4

I am currently training a convolutional neural network to classify between a rotten apple and a normal apple based on external appearance. I have all the necessary data, however I have a question about the following line of code.

epoch_x, epoch_y = tf.train.batch([resized_image, "Normal"], batch_size=batch_size)

This feeds the neural network with the images and labels. My question is, should I train the network with all the batches of normal oranges and then train the neural network with the rotten oranges? Should I alternate training the batches of rotten and normal oranges? Is there a particular order these images should be trained in?

Rehaan Ahmad
  • 794
  • 8
  • 23
  • Is this a similar [question](http://stackoverflow.com/questions/8101925/effects-of-randomizing-the-order-of-inputs-to-a-neural-network) ? – vendaTrout Feb 05 '17 at 04:52

1 Answers1

6

You should not train it in any particular order, each batch should contain positive and negative examples, in a random order. If your classes are balanced, then each batch will have approximately the same number of positive/negative samples.

The easiest way to do this is to randomly shuffle your data (in the first dimension) and then produce batches sequentially. A good practice is also to reshuffle your data after each epoch, so the neural network does not see any pattern in the order that the samples are presented.

This techniques prevent any kind of bias in neural network training.

Dr. Snoopy
  • 55,122
  • 7
  • 121
  • 140
  • Oh I didn't know that. Each batch should contain positive and negative examples? How does the neural network know which image is positive and which image is negative? Where do I specify this? – Rehaan Ahmad Feb 05 '17 at 19:54
  • @RehaanAhmad The labels (y) tell the NN what class each sample belongs. – Dr. Snoopy Feb 05 '17 at 21:01