【问题标题】:Tensorflow DeepLab: Shape mismatch in tuple component 1. Expected [x,x,3], got [y,y,3]Tensorflow DeepLab:元组组件1中的形状不匹配。预期[x,x,3],得到[y,y,3]
【发布时间】:2018-09-15 10:09:54
【问题描述】:

我正在尝试使用 deeplab3+ tensorflow 实现来微调新数据集(具有不同数量的类)。我将数据集转换为 tfrecords 并开始 train 模型没有问题。现在我想评估新的检查点,运行evaluation 脚本,我得到一个形状不匹配错误。

tensorflow.python.framework.errors_impl.InvalidArgumentError:形状不匹配

模型实现使用tensorflow.slim,我认为我的问题与功能有关

slim.evaluation.evaluation_loop(
    master=FLAGS.master,
    checkpoint_dir=FLAGS.checkpoint_dir,
    logdir=FLAGS.eval_logdir,
    num_evals=num_batches,
    eval_op=list(metrics_to_updates.values()),
    max_number_of_evaluations=num_eval_iters,
    eval_interval_secs=FLAGS.eval_interval_secs,
    hooks=[tf_debug.LocalCLIDebugHook()]))

我的错误日志

`tensorflow.python.framework.errors_impl.InvalidArgumentError: Shape mismatch in tuple component 1. Expected [513,513,3], got [2448,2448,3]
 [[Node: batch/padding_fifo_queue_enqueue = QueueEnqueueV2[Tcomponents=[DT_INT64, DT_FLOAT, DT_STRING, DT_INT32, DT_UINT8, DT_INT64], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/device:CPU:0"](batch/padding_fifo_queue, Reshape_3/_4659, add_2/_4661, Reshape_1, add_3/_4663, case/cond/Merge/_4665, Reshape_6/_4667)]]`

我不明白这个错误,因为该实现在训练和验证期间使用了相同的 preprocessing 例程。我也尝试使用 tf_debug.LocalCLIDebugHook() 进行调试,但没有成功。

【问题讨论】:

    标签: python tensorflow deep-learning


    【解决方案1】:

    它作为问题发布在 github 上,解决方案在此评论中:https://github.com/tensorflow/models/issues/3886#issuecomment-378996570

    从那里复制粘贴:

    为您的数据集设置 eval_crop_size = output_stride * k + 1。 默认值 513 是为最大图像尺寸为 512 的 PASCAL 图像设置的。 我们选择 k = 32,得到 eval_crop_size = 16 * 32 + 1 = 513 > 512,因为我们将进行整个图像推断。 与我们对 Cityscapes 图像所做的类似情况,我们设置 eval_crop_size = 1025x2049。

    【讨论】:

      【解决方案2】:

      两种解决方案:

      • 只需将eval_crop_size/vis_crop_size 更改为评估集中的最大图像大小。

      • 使用tf.image.resize_image_with_pad(不会改变纵横比)或tf.image.resize_images(会改变纵横比但没有内边距)调整您的评估大小,使其最大图像尺寸长度

      背后的主要原因是input_preprocess.py。下面的代码显示了如何对输入进行预处理以确保尺寸兼容性:图像被填充(如果它们小于crop_size),然后被裁剪(仅用于训练)

      # Pad image and label to have dimensions >= [crop_height, crop_width]
        image_shape = tf.shape(processed_image)
        image_height = image_shape[0]
        image_width = image_shape[1]
      
        target_height = image_height + tf.maximum(crop_height - image_height, 0)
        target_width = image_width + tf.maximum(crop_width - image_width, 0)
      
      # Randomly crop the image and label
        if is_training and label is not None:
          processed_image, label = preprocess_utils.random_crop(
              [processed_image, label], crop_height, crop_width)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-06-18
        • 2019-02-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-04-20
        • 2017-12-30
        • 2021-01-18
        相关资源
        最近更新 更多