Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tensorflow error using tf.image.random : 'numpy.ndarray' object has no attribute 'get_shape'

Intro

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.

Problem

When I run the line :

flipped_images = tf.image.random_flip_left_right(images)

I get de following error :

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

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

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()

Questions

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

  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?
like image 424
Julep Avatar asked Mar 06 '16 08:03

Julep


1 Answers

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.

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))
like image 74
mrry Avatar answered Nov 09 '22 23:11

mrry