Hey guys,
I’m still on Redux, and I seem to be getting the following error when I train:
Found 25000 images belonging to 2 classes.
Found 1998 images belonging to 3 classes.
Epoch 1/1
24960/25000 [============================>.] - ETA: 0s - loss: 2.6017 - acc: 0.8367
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-13-85f922dc948c> in <module>()
8 val_batches = vgg.get_batches(path+'valid', batch_size=batch_size*2)
9 vgg.finetune(batches)
---> 10 vgg.fit(batches, val_batches, nb_epoch=1)
/home/ubuntu/nbs/vgg16.pyc in fit(self, batches, val_batches, nb_epoch)
97 def fit(self, batches, val_batches, nb_epoch=1):
98 self.model.fit_generator(batches, samples_per_epoch=batches.nb_sample, nb_epoch=nb_epoch,
---> 99 validation_data=val_batches, nb_val_samples=val_batches.nb_sample)
100
/home/ubuntu/anaconda2/lib/python2.7/site-packages/keras/models.pyc in fit_generator(self, generator, samples_per_epoch, nb_epoch, verbose, callbacks, validation_data, nb_val_samples, class_weight, max_q_size, nb_worker, pickle_safe, **kwargs)
872 max_q_size=max_q_size,
873 nb_worker=nb_worker,
--> 874 pickle_safe=pickle_safe)
875
876 def evaluate_generator(self, generator, val_samples, max_q_size=10, nb_worker=1, pickle_safe=False, **kwargs):
/home/ubuntu/anaconda2/lib/python2.7/site-packages/keras/engine/training.pyc in fit_generator(self, generator, samples_per_epoch, nb_epoch, verbose, callbacks, validation_data, nb_val_samples, class_weight, max_q_size, nb_worker, pickle_safe)
1469 val_outs = self.evaluate_generator(validation_data,
1470 nb_val_samples,
-> 1471 max_q_size=max_q_size)
1472 else:
1473 # no need for try/except because
/home/ubuntu/anaconda2/lib/python2.7/site-packages/keras/engine/training.pyc in evaluate_generator(self, generator, val_samples, max_q_size, nb_worker, pickle_safe)
1552 'or (x, y). Found: ' + str(generator_output))
1553 try:
-> 1554 outs = self.test_on_batch(x, y, sample_weight=sample_weight)
1555 except:
1556 _stop.set()
/home/ubuntu/anaconda2/lib/python2.7/site-packages/keras/engine/training.pyc in test_on_batch(self, x, y, sample_weight)
1251 x, y, sample_weights = self._standardize_user_data(x, y,
1252 sample_weight=sample_weight,
-> 1253 check_batch_dim=True)
1254 if self.uses_learning_phase and type(K.learning_phase()) is not int:
1255 ins = x + y + sample_weights + [0.]
/home/ubuntu/anaconda2/lib/python2.7/site-packages/keras/engine/training.pyc in _standardize_user_data(self, x, y, sample_weight, class_weight, check_batch_dim, batch_size)
963 output_shapes,
964 check_batch_dim=False,
--> 965 exception_prefix='model target')
966 sample_weights = standardize_sample_weights(sample_weight,
967 self.output_names)
/home/ubuntu/anaconda2/lib/python2.7/site-packages/keras/engine/training.pyc in standardize_input_data(data, names, shapes, check_batch_dim, exception_prefix)
106 ' to have shape ' + str(shapes[i]) +
107 ' but got array with shape ' +
--> 108 str(array.shape))
109 return arrays
110
Exception: Error when checking model target: expected dense_20 to have shape (None, 2) but got array with shape (128, 3)
The lines that make this error are as follows:
batch_size=64
from vgg16 import Vgg16
vgg = Vgg16()
batches = vgg.get_batches(path+'train', batch_size=batch_size)
val_batches = vgg.get_batches(path+'valid', batch_size=batch_size*2)
vgg.finetune(batches)
vgg.fit(batches, val_batches, nb_epoch=1)
Personally, I have no idea what’s wrong, so I haven’t done anything to fix it. My data looks good. Under the “data/redux/” path, I have my valid folder with separate cats/dogs folders, each having 1000 images of the corresponding animal. Under my “Sample” folder, I have valid and train folders, each having a separate folder for cats/dogs. Animal folders under train have 51 photos of each, and animal folders under valid have 200 photos of each. Hopefully you can visualize that 
I am on Mac. I have a p2 instance.
I made my own python notebook and wrote some code with the info from Lesson 1’s notebook. I compared it with Jeremy’s and it looked pretty good. NOTE: I never did the “Create validation set and sample” and “Move to separate dirs for each set”. Instead, I did it all through terminal, which was quite a pain.
I have copied the code from “Run a few more epochs” (Jeremy’s code) and put it under my own Finetune and train, which seems to be the same as his.
Another thing to note is that it says “Found 25000 images belonging to 2 classes.
Found 1998 images belonging to 3 classes.” I have no idea why there are 3 classes. In my “data/redux/valid/” folder, there are 2 folders: cats and dogs, each with 1000 photos of the corresponding animal.
I have not yet implemented any code that deals with submitting.
Also, I can copy-and-paste my full code in if needed. But really, the stuff above is the main bulk of it.
Thanks!
Ethan