简介
我正在使用 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 携带,我想知道:
我的输入数据的类型/形状?
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/