python-2.7 - 使用 tf.image.random : 'numpy.ndarray' object has no attribute 'get_shape' 的 Tensorflow 错误

标签 python-2.7 tensorflow

简介

我正在使用 Tensorflow 教程“专家深度 MNIST”的修改版本和 Python API,用于使用卷积网络的医学图像分类项目。

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

问题

当我运行该行时:

flipped_images = tf.image.random_flip_left_right(images)

我收到以下错误:

AttributeError: 'numpy.ndarray' object has no attribute 'get_shape'



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

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

最后,我在尝试使用以下函数时仍然遇到相同的错误:
  • tf.image.random_flip_up_down()
  • tf.image.random_brightness()
  • tf.image.random_contrast()

  • 问题

    由于输入数据通常在 Tensorflow 中作为 ndarrays 携带,我想知道:
  • 这是 Tensorflow Python API 的错误还是我的“错”,因为
    我的输入数据的类型/形状?
  • 我怎样才能让它工作并能够申请tf.image.random_flip_left_right到我的训练集?
  • 最佳答案

    这似乎与 TensorFlow API 不一致,因为几乎所有其他操作函数都接受 NumPy 数组,无论是 tf.Tensor是期待。我已提交 an issue跟踪修复。

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

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

    关于python-2.7 - 使用 tf.image.random : 'numpy.ndarray' object has no attribute 'get_shape' 的 Tensorflow 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35824798/

    相关文章:

    python - 设置 Scrapy 框架以在 Python 2.7 上运行

    python - 从兄弟目录导入的问题

    python - train_on_batch() 在 keras 模型中做了什么?

    Tensorflow物体检测: why is the location in image affecting detection accuracy when using ssd mobilnet v1?

    python - 如何初始化特定name_scope下的局部变量

    python - 如何在 Pandas 中组合和形成复杂的数据框

    python - 文件名及其路径作为字典不显示所有结果

    python - 在python 3中查找表中名称第一个字符的频率分布

    c++11 - 使用 CXX_FLAGS 构建 Eigen3

    python - 使用数组输入神经网络