基于TF-Slim使用MobilenetV2进行图像分类

 

元学习论文总结||小样本学习论文总结

2017-2019年计算机视觉顶会文章收录 AAAI2017-2019 CVPR2017-2019 ECCV2018 ICCV2017-2019 ICLR2017-2019 NIPS2017-2019

 


Environment

  • ubuntu16.04
  • python2.7
  • tensorflow

Github

Preparing the datasets

  • Prepare your own data and divide it into train(90%) and validation(10%) sets
  • Put in "data_prepare/pic/train" and "data_prepare/pic/validation" 
pic
--train
  --class 0
  --class 1
  ...
--validation
  --class 0
  --class 1
  ...

Converting to TFRecord format

  • Execute the "convert.sh" file 
python data_convert.py -t pic/ \
  --train-shards 2 \
  --validation-shards 2 \
  --num-threads 2 \
  --dataset-name satellite
  • Will get 4 tf-record files and 1 label file
  • Move these 5 files to "slim\satellite\data"

Modify the "slim\datasets\satellite.py" file

  • FILE_PATTERN = ‘satellite%s_*.tfrecord’ ( not recommend to modify)
  • SPLITS_TO_SIZES = {‘train’: 16, ‘validation’: 4} (Total number of train and validation set )(The sum of all categories)
  • _NUM_CLASSES = 2 (Number of categories)
  • ‘image/format’: tf.FixedLenFeature((), tf.string, default_value=’jpg’) (Image format, here is jpg)

Download the pre-training model Mobilenet V2

Execute "model_train.sh" in the "slim/" folder to train:

python train_image_classifier.py \
  --train_dir=satellite/train_log \
  --dataset_name=satellite \
  --train_image_size=500 \
  --dataset_split_name=train \
  --dataset_dir=satellite/data \
  --model_name="mobilenet_v2_140" \
  --checkpoint_path=satellite/pretrained/mobilenet_v2_1.4_224.ckpt \
  --checkpoint_exclude_scopes=MobilenetV2/Logits,MobilenetV2/AuxLogits \
  --trainable_scopes=MobilenetV2/Logits,MobilenetV2/AuxLogits \
  --max_number_of_steps=1000 \
  --batch_size=16 \
  --learning_rate=0.001 \
  --learning_rate_decay_type=fixed \
  --log_every_n_steps=10 \
  --optimizer=rmsprop \
  --weight_decay=0.00004 \
  --label_smoothing=0.1 \
  --num_clones=1 \
  --num_epochs_per_decay=2.5 \
  --moving_average_decay=0.9999 \
  --learning_rate_decay_factor=0.98 \
  --preprocessing_name="inception_v2" 

Execute "model_test.sh" in the "slim/" folder to evaluate the model:

python eval_image_classifier.py \
  --checkpoint_path=satellite/train_log \
  --eval_dir=satellite/eval_log \
  --dataset_name=satellite \
  --dataset_split_name=validation \
  --dataset_dir=satellite/data \
  --model_name="mobilenet_v2_140" \
  --batch_size=32 \
  --num_preprocessing_threads=2 \
  --eval_image_size=500
  • Or execute "start_train_test.sh" at the project root directory to train and evaluate the model.

Export trained models

  • Execute "export_inference_graph.py" in the "slim/" folder to exporting the Inference Graph
python export_inference_graph.py \
  --alsologtostderr \
  --model_name="mobilenet_v2_140" \
  --image_size=500 \
  --output_file=slim/satellite/export/mobilenet_v2_140_inf_graph.pb \
  --dataset_name satellite
  • Execute "freeze_graph.py" at the project root directory to freezing the exported Graph
  • Remember to modify the train steps "-****" in "--input_checkpoint"
python freeze_graph.py \
  --input_graph slim/satellite/export/mobilenet_v2_140_inf_graph.pb \
  --input_checkpoint slim/satellite/train_log/model.ckpt-****(8000) \
  --input_binary true \
  --output_node_names MobilenetV2/Predictions/Reshape_1 \
  --output_graph slim/satellite/freeze/mobilenet_v2_140.pb

  • Or execute "export_freeze.sh" at the project root directory to export and freeze Graph.

 

Reference:

# 打赏鼓励请扫支付宝微信二维码O(∩_∩)O金额不限噢噢!如果有修改建议或者疑问请留言!

支付宝
微信支付
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值