ImageDataGenerator .next() can this be equivalent to mnist.train.next_batch?

Viewed 149

hello guys i'm new to tensorflow nd i'm workin on capsule network this how my dataset looks like :

 -train
     |-class1
     |-class2
     |-class3

I'm using ImageDataGenerator flow_from_directory to generate labels from directories names :

 train = ImageDataGenerator(rescale= 1/255)
trainData = train.flow_from_directory(dir_path , class_mode='categorical' , target_size=(80, 80), batch_size=batch_size )

this is the placeholder for labels :

 y = tf.placeholder(shape=[None], dtype=tf.int64, name="y")

the tutorial that i'm following is workin on mnist dataset so he did this to feed training data to the model :

X_batch, y_batch = mnist.train.next_batch(batch_size)
        

i did this instead :

 X_batch, y_batch = trainData.next()

it works well with images but not with labesl because i got this error :

Cannot feed value of shape (10, 3) for Tensor 'y:0', which has shape '(?,)'

y_batch.shape --> (10, 3) 10 is the batch_size and i guess 3 is the number of classes , i'am confused about this

Can anyone help please ?

2 Answers

you don't need a placeholder for the labels, just use

images, labels=next(trainData)

this will return a batch_size number of images and a batch_size number of labels. The labels shape will be (batch_size, number_of_classes) The images shape will be (batch_size, 80, 80,3)

placeholders are create the empty and then load with data. for labels no need of creating placeholders

Related