环境:ubuntu 16.04 + TensorFlow 1.6.1 + cuda 9.0 + cudnn 7.0 +python2.7
# From tensorflow/models/research/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
Quick test by running model_test.py:
# From tensorflow/models/research/
python deeplab/model_test.py
Quick running the whole code on the PASCAL VOC 2012 dataset:
# From tensorflow/models/research/deeplab
sh local_test.sh
python build_voc2012_data.py \
--image_folder="保存images的路径" \
--semantic_segmentation_folder="保存labels的路径" \
--list_folder="保存train.txt文件的路径" \
--image_format="jpeg(image格式)" \
--output_dir="生成tfrecord格式的数据所要保存的位置"
PASCAL_VOC_SEG_INFORMATION = DatasetDescriptor(
splits_to_sizes={
'train': 1464,
'trainval': 2913,
'val': 1449,
},
num_classes=21,
ignore_label=255,
)
# Set to False if one does not want to re-use the trained classifier weights.
flags.DEFINE_boolean('initialize_last_layer', True,
'Initialize the last layer.')
python train.py \
--logtostderr \
--train_split="trainval" \ 可以选择train/val/trainval 不同的数据集
--model_variant="xception_65" \
--atrous_rates=6 \
--atrous_rates=12 \
--atrous_rates=18 \
--output_stride=16 \
--decoder_output_stride=4 \
--train_crop_size=512 \
--train_crop_size=512 \
--train_batch_size=12 \
--training_number_of_steps=30000 \
--fine_tune_batch_norm=True \
--tf_initial_checkpoint="加载与训练模型/model.ckpt" \
--train_logdir="保存训练的中间结果" \
--dataset_dir="生成的tfrecord的路径"
# When fine_tune_batch_norm=True, use at least batch size larger than 12
# (batch size more than 16 is better). Otherwise, one could use smaller batch
# size and set fine_tune_batch_norm=False.
2.
# For `xception_65`, use atrous_rates = [12, 24, 36] if output_stride = 8, or
# rates = [6, 12, 18] if output_stride = 16. Note one could use different
# atrous_rates/output_stride during training/evaluation.
python "${WORK_DIR}"/eval.py \
--logtostderr \
--eval_split="val" \
--model_variant="xception_65" \
--atrous_rates=6 \
--atrous_rates=12 \
--atrous_rates=18 \
--output_stride=16 \
--decoder_output_stride=4 \
--eval_crop_size=512 \
--eval_crop_size=512 \
--checkpoint_dir="${TRAIN_LOGDIR}" \
--eval_logdir="${EVAL_LOGDIR}" \
--dataset_dir="${DATASET}"
python vis.py \
--logtostderr \
--vis_split="val" \
--model_variant="xception_65" \
--atrous_rates=6 \
--atrous_rates=12 \
--atrous_rates=18 \
--output_stride=16 \
--decoder_output_stride=4 \
--vis_crop_size=513 \
--vis_crop_size=513 \
--checkpoint_dir="${TRAIN_LOGDIR}" \
--vis_logdir="${VIS_LOGDIR}" \
--dataset_dir="${DATASET}"
输出图片的预测结果到
vis_logdir中