TF Slim:在自定义数据集上微调 mobilenet v2

TF Slim: Fine Tune mobilenet v2 on custom dataset

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

InvalidArgumentError (see above for traceback): Assign requires shapes of both tensors to match. lhs shape= [1,1,24,144] rhs shape= [1,1,32,192] [[Node: 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 个参数用于迁移学习,删除最后 2 层并创建我们自己的 softmax 层用于自定义数据集分类。但我不确定我是否为它们传递了正确的值。

要重新训练模型,您必须微调您的自定义数量 类

MobilenetV2/Predictions and MobilenetV2/predics

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

在 mobilenet_v2.py 中,depth_multiplier=1 对于 mobilenet 和 mobilenet_base,您应该将其更改为 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):