jeffheaton/t81_558_deep_learning

shape missmatch

Closed this issue · 4 comments

Hi, i am trying to follow along your tutorial on youtube and i am getting an error, I am not an expert at this can you please help, Thank you

Epoch 1/5


ValueError Traceback (most recent call last)
in
4 model.fit_generator(generator=train_generator,
5 steps_per_epoch=step_size_train,
----> 6 epochs=5)

E:\Anaconda\lib\site-packages\tensorflow_core\python\keras\engine\training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
1295 shuffle=shuffle,
1296 initial_epoch=initial_epoch,
-> 1297 steps_name='steps_per_epoch')
1298
1299 def evaluate_generator(self,

E:\Anaconda\lib\site-packages\tensorflow_core\python\keras\engine\training_generator.py in model_iteration(model, data, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch, mode, batch_size, steps_name, **kwargs)
263
264 is_deferred = not model._is_compiled
--> 265 batch_outs = batch_function(*batch_data)
266 if not isinstance(batch_outs, list):
267 batch_outs = [batch_outs]

E:\Anaconda\lib\site-packages\tensorflow_core\python\keras\engine\training.py in train_on_batch(self, x, y, sample_weight, class_weight, reset_metrics)
971 outputs = training_v2_utils.train_on_batch(
972 self, x, y=y, sample_weight=sample_weight,
--> 973 class_weight=class_weight, reset_metrics=reset_metrics)
974 outputs = (outputs['total_loss'] + outputs['output_losses'] +
975 outputs['metrics'])

E:\Anaconda\lib\site-packages\tensorflow_core\python\keras\engine\training_v2_utils.py in train_on_batch(model, x, y, sample_weight, class_weight, reset_metrics)
251 x, y, sample_weights = model._standardize_user_data(
252 x, y, sample_weight=sample_weight, class_weight=class_weight,
--> 253 extract_tensors_from_dataset=True)
254 batch_size = array_ops.shape(nest.flatten(x, expand_composites=True)[0])[0]
255 # If model._distribution_strategy is True, then we are in a replica context

E:\Anaconda\lib\site-packages\tensorflow_core\python\keras\engine\training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, batch_size, check_steps, steps_name, steps, validation_split, shuffle, extract_tensors_from_dataset)
2536 # Additional checks to avoid users mistakenly using improper loss fns.
2537 training_utils.check_loss_and_target_compatibility(
-> 2538 y, self._feed_loss_fns, feed_output_shapes)
2539
2540 # If sample weight mode has not been set and weights are None for all the

E:\Anaconda\lib\site-packages\tensorflow_core\python\keras\engine\training_utils.py in check_loss_and_target_compatibility(targets, loss_fns, output_shapes)
741 raise ValueError('A target array with shape ' + str(y.shape) +
742 ' was passed for an output of shape ' + str(shape) +
--> 743 ' while using as loss ' + loss_name + '. '
744 'This loss expects targets to have the same shape '
745 'as the output.')

ValueError: A target array with shape (1, 4) was passed for an output of shape (None, 3) while using as loss categorical_crossentropy. This loss expects targets to have the same shape as the output.

Could you let me know what file or Jupyter notebook you are running when you get this error? I cannot tell from above.

I've followed this video, Transfer Learning for Computer Vision and Keras (9.3)
I am using this jupyter notebook.. t81_558_class_09_3_transfer_cv.ipynb

only thing I've changed are the folder names for my own categories to classify

hello sir, it was my bad
preds=Dense(4,activation='softmax')(x)
on this line you had 3 because you had three different types of dogs i just had to simply change it to 4 because i have 4 classes.

your tutorials are very informative, thank you