我需要将小图像分类到四个不同的类别中,再加上一个“背景”类用于错误检测。
在训练过程中,损失值迅速下降到0.7,但即使在800,000步之后仍然停留在那里。最终,冻结的图似乎将大多数图像分类为背景标签。
我可能遗漏了一些东西,我会在下面详细说明我使用的步骤,欢迎任何反馈。我是tf-slim的新手,所以可能犯了一些明显的错误,可能是样本太少?我不是在追求最高的准确性,只希望有一个可以用于原型设计的方案。
源材料可以在以下链接找到:https://www.dropbox.com/s/k55xoygdzb2efag/TilesDataset.zip?dl=0
我在Windows 10上使用了tensorflow-gpu 1.15.3版本。
-
我使用以下命令创建数据集:
python ./createTfRecords.py --tfrecord_filename=tilesV2_40 --dataset_dir=.\tilesV2\Tiles_40
-
我在models-master\research\slim\datasets中添加了一个基于flowers提供者的数据集提供者。
-
我修改了models-master\research\slim\nets\mobilenet中的mobilnet_v2.py,变更了num_classes=5和mobilenet.default_image_size = 40
-
我使用以下命令训练网络:
python ./models-master/research/slim/train_image_classifier.py --model_name "mobilenet_v2" --learning_rate 0.045 --preprocessing_name "inception_v2" --label_smoothing 0.1 --moving_average_decay 0.9999 --batch_size 96 --learning_rate_decay_factor 0.98 --num_epochs_per_decay 2.5 --train_dir ./weight --dataset_name Tiles_40 --dataset_dir .\tilesV2\Tiles_40
-
当我尝试
python .\models-master\research\slim\eval_image_classifier.py --alsologtostderr --checkpoint_path ./weight/model.ckpt-XXX --dataset_dir ./tilesV2/Tiles_40 --dataset_name Tiles_40 --dataset_split_name validation --model_name mobilenet_v2
时,我得到eval/Recall_5[1]eval/Accuracy[1]
-
然后我使用以下命令导出图:
python .\models-master\research\slim\export_inference_graph.py --alsologtostderr --model_name mobilenet_v2 --image_size 40 --output_file .\export\output.pb --dataset_name Tiles_40
-
并使用以下命令冻结它:
freeze_graph --input_graph .\export\output.pb --input_checkpoint .\weight\model.ckpt-XXX --input_binary true --output_graph .\export\frozen.pb --output_node_names MobilenetV2/Predictions/Reshape_1
-
然后我使用数据集中的图像尝试网络:
python .\label_image.py --graph .\export\frozen.pb --labels .\tilesV2\Tiles_40\labels.txt --image .\tilesV2\Tiles_40\photos\lac\1_1.png --input_layer input --output_layer MobilenetV2/Predictions/Reshape_1
。这是我得到错误分类的位置,例如对于数据集中的“lac”图像,得到的结果是0:background 0.92839915 2:lac 0.020171663 1:house 0.019106707 3:road 0.01677236 4:start 0.0155500565
我尝试更改了depth_multiplier、学习率,在CPU上进行学习,删除了学习命令中的--preprocessing_name "inception_v2"
。我已经没有其他想法了…
回答:
更改你的学习率,可能从通常选择的3e-5开始。