【问题标题】:how does tensorflow retraining last layer handle different image sizes?tensorflow再训练最后一层如何处理不同的图像尺寸?
【发布时间】:2017-05-23 17:44:33
【问题描述】:

我正在运行tensorflow retrain tutorial,但我不明白为什么重新训练的图像可能与最初训练模型的图像大小不同。我查看了将图像提供给模型的retrain.py 脚本但代码没有进行任何类型的图像调整,它直接是reading the image from disk,然后是feeds it to the model

有谁知道在进行最后一层训练时如何使用不同大小的图像?

【问题讨论】:

  • 它可能正在动态调整图像大小?
  • 什么意思?您是否建议该模型可以接受可变大小的图像?
  • 不是模型,但代码可能正在执行图像预处理以在发送到模型之前调整图像的大小或子集。这只是猜测
  • 来自 create_inception_graph() 的 jpeg_data_tensor、resized_input_tensor 有什么区别??
  • 另外,如果你要求任何失真,裁剪/调整大小在这里完成:github.com/tensorflow/tensorflow/blob/master/tensorflow/…

标签: python tensorflow deep-learning


【解决方案1】:

从技术上讲,Inception 模型可以直接应用于各种图像尺寸。这是可能的,因为密集层之前的最后一个平均池是 global 平均池(而不是 3x3 或 2x2):

来自https://github.com/tensorflow/models/blob/master/inception/inception/slim/inception_model.py#L320

      shape = net.get_shape()
      net = ops.avg_pool(net, shape[1:3], padding='VALID', scope='pool')

这将池化的窗口指定为整个图像。

换句话说,池化层对空间维度上的特征进行平均,因此H x W x 2048 变为1 x 1 x 2048,而不管HW


也就是说,根据我的经验,以与训练方式截然不同的规模应用 NN 可能会导致准确性下降(但网络应该可以工作)

【讨论】:

    【解决方案2】:

    @anthonybell 你是正确的代码没有做任何图像调整。但是如果你检查预训练的网络有一个图像调整层

    <tf.Tensor 'DecodeJpeg/contents:0' shape=() dtype=string>,
    <tf.Tensor 'DecodeJpeg:0' shape=(?, ?, 3) dtype=uint8>,
    <tf.Tensor 'Cast:0' shape=(?, ?, 3) dtype=float32>,
    <tf.Tensor 'ExpandDims/dim:0' shape=(1,) dtype=int32>,
    <tf.Tensor 'ExpandDims:0' shape=(1, ?, ?, 3) dtype=float32>,
    <tf.Tensor 'ResizeBilinear/size:0' shape=(2,) dtype=int32>,
    <tf.Tensor 'ResizeBilinear:0' shape=(1, 299, 299, 3) dtype=float32>,
    <tf.Tensor 'Sub/y:0' shape=() dtype=float32>,
    <tf.Tensor 'Sub:0' shape=(1, 299, 299, 3) dtype=float32>,
    <tf.Tensor 'Mul/y:0' shape=() dtype=float32>,
    <tf.Tensor 'Mul:0' shape=(1, 299, 299, 3) dtype=float32>,
    

    网络将接受任何分辨率的图像,并在内部将其大小调整为 299x299

    【讨论】:

    • 似乎他们必须进行某种调整大小,因为当您查看卷积时,每一层的图像会变得越来越小。如果我的图像是 8x8 开始,它会做什么当它达到 1x1..
    • 那是因为卷积层之间夹有池化层。如果您的输入尺寸为 8x8,resize layer 会将图像尺寸调整为 299x299。
    猜你喜欢
    • 2019-01-11
    • 1970-01-01
    • 2019-12-12
    • 2017-06-19
    • 2016-12-19
    • 2021-09-09
    • 1970-01-01
    • 2023-01-29
    • 2018-06-06
    相关资源
    最近更新 更多