Tflearn: how to input image data in tflearn

Created on 13 Nov 2016  路  5Comments  路  Source: tflearn/tflearn

Hi @aymericdamien,
in the example of googlenet.py, the image input is like this
''
X, Y = oxflower17.load_data(one_hot=True, resize_pics=(227, 227))
''
my problem is two classification, and I have two kinds image files like following,
''
a -- img1.jpg
img2.jpg
img3.jpg
...
b -- img1.jpg
img2.jpg
img3.jpg
...
''
and 'a' and 'b' are directory name of two kinds images and labels of two kinds images, too.
in tensroflow, I can convert these image files into a TFRecords, and then use the following codes

def read_and_decode(filename):
      filename_queue = tf.train.string_input_producer([filename])

    reader = tf.TFRecordReader()
    _, serialized_example = reader.read(filename_queue) 
    features = tf.parse_single_example(serialized_example,
                                       features={
                                           'label': tf.FixedLenFeature([], tf.int64),
                                           'img_raw' : tf.FixedLenFeature([], tf.string),
                                       })

    img = tf.decode_raw(features['img_raw'], tf.uint8)
    img = tf.reshape(img, [224, 224, 3])
    img = tf.cast(img, tf.float32) * (1. / 255) - 0.5
    label = tf.cast(features['label'], tf.int32)

    return img, label

img, label = read_and_decode("train.tfrecords")

img_batch, label_batch = tf.train.shuffle_batch([img, label],
                                                batch_size=30, capacity=2000,
                                                min_after_dequeue=1000)

in tflearn, how to input the image data ?
and is there any shuffle function ?
thanks for your help!

Most helpful comment

@dp1: this seems to work:
X = np.reshape(X, (-1, 32, 32,1))
thanks https://stackoverflow.com/questions/43698016/cant-input-images-in-the-right-shape-for-tflearn

All 5 comments

TFLearn doesn't support TFRecords for now, you can check here how to load images:

@luoruisichuan did you find any success regarding this ? I am also trying to do the same thing using image preloader but getting error on input layer as " Cannot feed value of shape (64, 128, 128) for Tensor u'input/X:0', which has shape '(?, 128, 128, 1)' " I think its because i am not able to reshape data into [-1,128,128,1] format in image-preloader
Please help if you have done something.

@dp01 sorry, I have not get a good scheme of inputting image data.

@dp01 : same thing here. I imported images, but now face the same problem.
how to reshape those images to [-1, 32,32,1] ?

@dp1: this seems to work:
X = np.reshape(X, (-1, 32, 32,1))
thanks https://stackoverflow.com/questions/43698016/cant-input-images-in-the-right-shape-for-tflearn

Was this page helpful?
0 / 5 - 0 ratings