【问题标题】:Tensorflow error using tf.image.random : 'numpy.ndarray' object has no attribute 'get_shape'使用 tf.image.random 的 TensorFlow 错误:“numpy.ndarray”对象没有属性“get_shape”
【发布时间】:2016-03-06 08:39:05
【问题描述】:

简介

我正在将 Tensorflow 教程“Deep MNIST for Experts”的修改版本与 Python API 一起用于使用卷积网络的医学图像分类项目。

我想通过对训练集的图像进行随机修改来人为地增加训练集的大小。

问题

当我跑线时:

flipped_images = tf.image.random_flip_left_right(images)

我得到以下错误:

AttributeError: 'numpy.ndarray' 对象没有属性 'get_shape'

我的张量“图像”是“批量”ndarrays (shape=[im_size, im_size, channels]) 的 ndarray (shape=[batch, im_size, im_size, channels])

只是为了检查我的输入数据是否以正确的形状和类型打包,我尝试在(未修改的)教程“Tensorflow Mechanics 101”中应用这个简单的函数,但我得到了同样的错误。

最后,我在尝试使用以下函数时仍然遇到同样的错误:

  • tf.image.random_flip_up_down()
  • tf.image.random_brightness()
  • tf.image.random_contrast()

问题

由于输入数据通常在 Tensorflow 中作为 ndarrays 携带,我想知道:

  1. 这是 Tensorflow Python API 的错误还是我的“错误”,因为 我的输入数据的类型/形状?
  2. 我怎样才能让它工作并能够将tf.image.random_flip_left_right 应用于我的训练集?

【问题讨论】:

    标签: python-2.7 tensorflow


    【解决方案1】:

    这似乎是 TensorFlow API 中的一个不一致之处,因为几乎所有其他操作函数都接受 NumPy 数组,只要需要 tf.Tensor。我已提交 an issue 以跟踪修复。

    幸运的是,有一个简单的解决方法,使用tf.convert_to_tensor()。将您的代码替换为以下内容:

    flipped_images = tf.image.random_flip_left_right(tf.convert_to_tensor(images))
    

    【讨论】:

      猜你喜欢
      • 2020-08-02
      • 2018-01-29
      • 2021-12-10
      • 1970-01-01
      • 1970-01-01
      • 2021-06-24
      • 2020-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多