【代码】deeplabv3+ vis.py 可视化代码解析

我真希望我刚开始看代码的时候有这一些列的博客。我记得我当时上网各种找,只找到一篇可怜巴巴的解析,如获至宝,开启了看代码的流程。毕竟我当时完全不会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的时候直接用即可。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章