inceptionv3 /v4迁移学习图像分类

研究一个图像分类的任务,现在的问题是对6类图像数据做分类任务,数据的特征是每一类都只有非常少的数据,并且存在类别不平均,在这种情况下我们的实验结果存在准确率的问题,对于少量数据,采用端到端从头开始训练的方法,模型学习到的特征很少,泛化能力不够,采用从ImageNet数据集训练得到的结果,我们可以采用预训练权重初始化特定的深度网络,如这里的Inception网路,采用slim轻量库构建模型,模型在三个公开数据集上的实例已经在github中可见,参照实例可用训练自定义的网络模型。

需要自己下载inceptionv3/v4的预训练权重,以及自定义的数据集。

构建数据训练代码,v3的训练和测试过程如下

python download_and_convert_data.py \
  --dataset_name=flowers \
  --dataset_dir=${DATASET_DIR}

# Fine-tune only the new layers for 1000 steps.
python train_image_classifier.py \
  --train_dir=${TRAIN_DIR} \
  --dataset_name=flowers \
  --dataset_split_name=train \
  --dataset_dir=${DATASET_DIR} \
  --model_name=inception_v3 \
  --checkpoint_path=${PRETRAINED_CHECKPOINT_DIR}/inception_v3.ckpt \
  --checkpoint_exclude_scopes=InceptionV3/Logits,InceptionV3/AuxLogits \
  --trainable_scopes=InceptionV3/Logits,InceptionV3/AuxLogits \
  --max_number_of_steps=1000 \
  --batch_size=32 \
  --learning_rate=0.01 \
  --learning_rate_decay_type=fixed \
  --save_interval_secs=60 \
  --save_summaries_secs=60 \
  --log_every_n_steps=100 \
  --optimizer=rmsprop \
  --weight_decay=0.00004

# Run evaluation.
python eval_image_classifier.py \
  --checkpoint_path=${TRAIN_DIR} \
  --eval_dir=${TRAIN_DIR} \
  --dataset_name=flowers \
  --dataset_split_name=validation \
  --dataset_dir=${DATASET_DIR} \
  --model_name=inception_v3

# Fine-tune all the new layers for 500 steps.
python train_image_classifier.py \
  --train_dir=${TRAIN_DIR}/all \
  --dataset_name=flowers \
  --dataset_split_name=train \
  --dataset_dir=${DATASET_DIR} \
  --model_name=inception_v3 \
  --checkpoint_path=${TRAIN_DIR} \
  --max_number_of_steps=500 \
  --batch_size=32 \
  --learning_rate=0.0001 \
  --learning_rate_decay_type=fixed \
  --save_interval_secs=60 \
  --save_summaries_secs=60 \
  --log_every_n_steps=10 \
  --optimizer=rmsprop \
  --weight_decay=0.00004

# Run evaluation.
python eval_image_classifier.py \
  --checkpoint_path=${TRAIN_DIR}/all \
  --eval_dir=${TRAIN_DIR}/all \
  --dataset_name=flowers \
  --dataset_split_name=validation \
  --dataset_dir=${DATASET_DIR} \
--model_name=inception_v3

v4

train:
python train_fracture_classifier.py --train_dir=/home/root1/models/research/slim/fracture_traindir --dataset_name=fracture --dataset_split_name=train --dataset_dir=/home/root1/data/fracture_data --model_name=inception_v4 --checkpoint_path=/home/root1/models/research/slim/pre_trained/inception_v4.ckpt --checkpoint_exclude_scopes=InceptionV4/Logits,InceptionV4/AuxLogits/Aux_logits --trainable_scopes=InceptionV4/Logits,InceptionV4/AuxLogits/Aux_logits --max_number_of_steps=10000 --batch_size=32 --learning_rate=0.001 --learning_rate_decay_type=fixed --save_interval_secs=60 --save_summaries_secs=60 --log_every_n_steps=100 --optimizer=rmsprop --weight_decay=0.00004

--learning_rate_decay_factor=0.5 --num_epochs_per_decay=50 --moving_average_decay=0.9999 --optimizer=adam --ignore_missing_vars=True

python train_fracture_classifier.py \
  --train_dir=/home/root1/models/research/slim/fracture_traindir1 \
  --dataset_name=fracture \
  --dataset_split_name=train \
  --dataset_dir=/home/root1/data/fracture_data \
  --model_name=inception_v4 \
  --checkpoint_path=/home/root1/models/research/slim/pre_trained/inception_v4.ckpt \
  --checkpoint_exclude_scopes=InceptionV4/Logits,InceptionV4/AuxLogits/Aux_logits \
  --trainable_scopes=InceptionV4/Logits,InceptionV4/AuxLogits/Aux_logits \
  --max_number_of_steps=10000 \
  --batch_size=32 \
  --learning_rate=0.01 \
  --learning_rate_decay_type=fixed \
  --save_interval_secs=60 \
  --save_summaries_secs=60 \
  --log_every_n_steps=100 \
  --optimizer=rmsprop \
--weight_decay=0.00004

eval:
python eval_fracture_classifier.py --checkpoint_path=/home/root1/models/research/slim/fracture_traindir --eval_dir=/home/root1/models/research/slim/fracture_traindir --dataset_name=fracture --dataset_split_name=validation --dataset_dir=/home/root1/data/fracture --model_name=inception_v4

猜你喜欢

转载自blog.csdn.net/Synioe/article/details/84198663