【问题标题】:TF Slim: Fine Tune mobilenet v2 on custom datasetTF Slim:在自定义数据集上微调 mobilenet v2
【发布时间】:2018-09-15 18:04:12
【问题描述】:

我正在尝试在我的自定义数据集上为图像分类任务微调 Mobilenet_v2_1.4_224 模型。 我正在关注本教程TensorFlow-Slim image classification library。 我已经创建了 .tfrecord 训练和验证文件。当我尝试从现有检查点进行微调时,出现以下错误:

InvalidArgumentError(参见上面的回溯):分配需要两个张量的形状匹配。 lhs 形状= [1,1,24,144] rhs 形状= [1,1,32,192] [[节点:save/Assign_149 = Assign[T=DT_FLOAT, _class=["loc:@MobilenetV2/expanded_conv_2/expand/weights"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0 /task:0/device:CPU:0"](MobilenetV2/expanded_conv_2/expand/weights, save/RestoreV2:149)]]

我用过的微调脚本是:

DATASET_DIR=G:\数据集

TRAIN_DIR=G:\Dataset\emotion-models\mobilenet_v2

CHECKPOINT_PATH=C:\Users\lenovo\Desktop\mobilenet_v2\mobilenet_v2_1.4_224.ckpt

python train_image_classifier.py \
--train_dir=${TRAIN_DIR} \
--dataset_dir=${DATASET_DIR} \
--dataset_name=emotion \
--dataset_split_name=train \
--model_name=mobilenet_v2 \
--train_image_size=224 \
--clone_on_cpu=True \
--checkpoint_path=${CHECKPOINT_PATH} \
--checkpoint_exclude_scopes=MobilenetV2/Logits \
--trainable_scopes=MobilenetV2/Logits

我怀疑错误是由于最后两个参数“checkpoint_exclude_scopes”或“trainable_scopes”造成的。

我知道这两个参数被用于迁移学习,方法是移除最后 2 层并创建我们自己的 softmax 层用于自定义数据集分类。但我不确定我是否为它们传递了正确的值。

【问题讨论】:

    标签: python tensorflow tensorflow-slim


    【解决方案1】:

    要重新训练模型,您必须针对自定义的类数进行微调

    MobilenetV2/Predictions 和 MobilenetV2/predics

    --checkpoint_exclude_scopes=MobilenetV2/Logits,MobilenetV2/Predictions,MobilenetV2/predics \
    --trainable_scopes=MobilenetV2/Logits,MobilenetV2/Predictions,MobilenetV2/predics \
    

    在 mobilenet_v2.py 中,对于 mobilenet 和 mobilenet_base,depth_multiplier=1,您应该将其更改为 1.4

    @slim.add_arg_scope 
    def mobilenet_base(input_tensor, depth_multiplier=1.4, **kwargs): 
    """Creates base of the mobilenet (no pooling and no logits) .""" 
    return mobilenet(input_tensor,
                     depth_multiplier=depth_multiplier,
                     base_only=True, **kwargs)
    
    @slim.add_arg_scope 
    def mobilenet(input_tensor,
                      num_classes=1001,
                      depth_multiplier=1.4,
                      scope='MobilenetV2',
                      conv_defs=None,
                      finegrain_classification_mode=False,
                      min_depth=None,
                      divisible_by=None,
                      **kwargs):
    

    【讨论】:

      猜你喜欢
      • 2022-01-16
      • 2017-11-30
      • 2018-03-09
      • 2019-09-22
      • 2017-09-18
      • 2021-09-03
      • 1970-01-01
      • 2017-10-28
      • 2017-11-01
      相关资源
      最近更新 更多