Lesson 1 - shape error in vgg.fit

I’m trying to run the exercises in lesson1.ipynb. I’m getting an error in vgg,fit. I’m trying to replicate the results for the basic dogscats data set. Everything seems to work fine when I use the sample data set, but I get the following error message when using the full set.

Thanks
Bill

vgg.fit(batches, val_batches, nb_epoch=1)

Epoch 1/1
22976/23000 [============================>.] - ETA: 0s - loss: 0.1238 - acc: 0.9664


Exception Traceback (most recent call last)
in ()
----> 1 vgg.fit(batches, val_batches, nb_epoch=1)

/home/ubuntu/nbs/vgg16.pyc in fit(self, batches, val_batches, nb_epoch)
211 “”"
212 self.model.fit_generator(batches, samples_per_epoch=batches.nb_sample, nb_epoch=nb_epoch,
–> 213 validation_data=val_batches, nb_val_samples=val_batches.nb_sample)
214
215

/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_4 to have shape (None, 2) but got array with shape (64, 6)

1 Like

I’m facing the exact issue, anyone managed to solve it ?