使用 tf.image.random 的 Tensorflow 错误:'numpy.ndarray' 对象没有属性 'get_shape' [英] Tensorflow error using tf.image.random : 'numpy.ndarray' object has no attribute 'get_shape'

查看:65
本文介绍了使用 tf.image.random 的 Tensorflow 错误:'numpy.ndarray' 对象没有属性 'get_shape'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简介

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

I am using a modified version of the Tensorflow tutorial "Deep MNIST for experts" with the Python API for a medical images classification project using convolutionnal networks.

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

I want to artificially increase the size of my training set by applying random modifications on the images of my training set.

问题

当我运行该行时:

flipped_images = tf.image.random_flip_left_right(images)

我收到以下错误:

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

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

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

My Tensor "images" is an ndarray (shape=[batch, im_size, im_size, channels]) of "batch" ndarrays (shape=[im_size, im_size, channels]).

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

Just to check if my input data was packed in the right shape and type, I have tried to apply this simple function in the (not modified) tutorial "Tensorflow Mechanics 101" and I get the same error.

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

Finally, I still get the same error trying to use the following functions :

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

问题

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

As input data is usually carried in Tensorflow as ndarrays, I would like to know :

  1. 这是 Tensorflow Python API 的错误还是我的错",因为输入数据的类型/形状?
  2. 我怎样才能让它工作并能够将 tf.image.random_flip_left_right 应用到我的训练集?
  1. Is it a bug of Tensorflow Python API or is it my "fault" because of the type/shape of my input data?
  2. How could I get it to work and be able to apply tf.image.random_flip_left_right to my training set?

推荐答案

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

This seems like an inconsistency in the TensorFlow API, since almost all other op functions accept NumPy arrays wherever a tf.Tensor is expected. I've filed an issue to track the fix.

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

Fortunately, there is a simple workaround, using tf.convert_to_tensor(). Replace your code with the following:

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

这篇关于使用 tf.image.random 的 Tensorflow 错误:'numpy.ndarray' 对象没有属性 'get_shape'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆