我真希望我剛開始看代碼的時候有這一些列的博客。我記得我當時上網各種找,只找到一篇可憐巴巴的解析,如獲至寶,開啓了看代碼的流程。畢竟我當時完全不會tf,一直用的keras。
bash代碼舉例:
python "${WORK_DIR}"/vis.py \
--logtostderr \
--vis_split="val" \
--model_variant="xception_65" \
--atrous_rates=12 \
--atrous_rates=24 \
--atrous_rates=36 \
--output_stride=8 \
--decoder_output_stride=1 \
--vis_crop_size="513,513" \
--checkpoint_dir="${TRAIN_LOGDIR}" \
--vis_logdir="${VIS_LOGDIR}" \
--dataset_dir="${PASCAL_DATASET}" \
--max_number_of_iterations=1 \
--eval_scales=[0.25,1,1.75] \
--add_flipped_images=True \
這裏需要說明的是eval_scale這個參數能不能接受這個list我還真不知道,我一般都是在vis.py裏面改,因爲我記得我試驗過,不接受。
vis.py一共三個函數
其中需要注意的是_process_batch
因爲她第一句代碼就把圖片跑完了:
(original_images,
semantic_predictions,
image_names,
image_heights,
image_widths) = sess.run([original_images, semantic_predictions,
image_names, image_heights, image_widths])
看,semantic_prediction已經預測完畢了:
然後就是一些修繕工作。
其中170幾行的代碼是將圖片保存:
save_annotation.save_annotation(
original_image, save_dir, _IMAGE_FORMAT % (image_id_offset + i),
add_colormap=False)
# Save prediction.
save_annotation.save_annotation(
crop_semantic_prediction, save_dir,
_PREDICTION_FORMAT % (image_id_offset + i), add_colormap=True,
colormap_type=FLAGS.colormap_type)
另外,在cityscape這個數據集上,
tf.logging.info('Cityscapes requires converting train_id to eval_id.')
其他數據即如voc不用管
我還沒了解過cityscape,所以。。。。
迴歸代碼,如果想要同名於數據集的可視化需要改代碼:
for i in range(num_image):
image_height = np.squeeze(image_heights[i])
image_width = np.squeeze(image_widths[i])
original_image = np.squeeze(original_images[i])
semantic_prediction = np.squeeze(semantic_predictions[i])
crop_semantic_prediction = semantic_prediction[:image_height, :image_width]
image_filename = os.path.basename(image_names[i])
image_filename = str(image_filename)
image_filename = image_filename[2:13]
if FLAGS.also_save_raw_predictions:
if train_id_to_eval_id is not None:
crop_semantic_prediction = _convert_train_id_to_eval_id(
crop_semantic_prediction,
train_id_to_eval_id)
save_annotation.save_annotation(
crop_semantic_prediction, raw_save_dir, image_filename,
add_colormap=False)
save_annotation.save_annotation(
original_image, save_dir, image_filename,
add_colormap=False)
這裏的image_filename是byte,所以轉化成str,再操作。
然後函數調用save_annotation的時候直接用即可。