Dear Supervisior,
I’ve tried run the following code provided on both my local machine and our Coursera platform.
# Run this on your local machine only
# May cause the kernel to die if running in the Coursera platform
base_dir = HOME_DIR + "processed/"
with open(base_dir + "config.json") as json_file:
config = json.load(json_file)
# Get generators for training and validation sets
train_generator = util.VolumeDataGenerator(config["train"], base_dir + "train/", batch_size=3, dim=(160, 160, 16), verbose=0)
valid_generator = util.VolumeDataGenerator(config["valid"], base_dir + "valid/", batch_size=3, dim=(160, 160, 16), verbose=0)
steps_per_epoch = 20
n_epochs=10
validation_steps = 20
model.fit_generator(generator=train_generator,
steps_per_epoch=steps_per_epoch,
epochs=n_epochs,
use_multiprocessing=True,
validation_data=valid_generator,
validation_steps=validation_steps)
# run this cell if you to save the weights of your trained model in cell section 4.1
#model.save_weights(base_dir + 'my_model_pretrained.hdf5')
However, the same error occurs as follows:
Epoch 1/10
InvalidArgumentError Traceback (most recent call last)
in ()
17 use_multiprocessing=True,
18 validation_data=valid_generator,
—> 19 validation_steps=validation_steps)
20
21 # run this cell if you to save the weights of your trained model in cell section 4.1
/opt/conda/lib/python3.6/site-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs)
89 warnings.warn('Update your ' + object_name + '
call to the ’ +
90 'Keras 2 API: ’ + signature, stacklevel=2)
—> 91 return func(*args, **kwargs)
92 wrapper._original_function = func
93 return wrapper
/opt/conda/lib/python3.6/site-packages/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)
1730 use_multiprocessing=use_multiprocessing,
1731 shuffle=shuffle,
→ 1732 initial_epoch=initial_epoch)
1733
1734 @interfaces.legacy_generator_methods_support
/opt/conda/lib/python3.6/site-packages/keras/engine/training_generator.py in fit_generator(model, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
218 sample_weight=sample_weight,
219 class_weight=class_weight,
→ 220 reset_metrics=False)
221
222 outs = to_list(outs)
/opt/conda/lib/python3.6/site-packages/keras/engine/training.py in train_on_batch(self, x, y, sample_weight, class_weight, reset_metrics)
1512 ins = x + y + sample_weights
1513 self._make_train_function()
→ 1514 outputs = self.train_function(ins)
1515
1516 if reset_metrics:
/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/keras/backend.py in call(self, inputs)
3474
3475 fetched = self._callable_fn(*array_vals,
→ 3476 run_metadata=self.run_metadata)
3477 self._call_fetch_callbacks(fetched[-len(self._fetches):])
3478 output_structure = nest.pack_sequence_as(
/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/client/session.py in call(self, *args, **kwargs)
1470 ret = tf_session.TF_SessionRunCallable(self._session._session,
1471 self._handle, args,
→ 1472 run_metadata_ptr)
1473 if run_metadata:
1474 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
InvalidArgumentError: Incompatible shapes: [3] vs. [16]
[[{{node training/Adam/gradients/loss/activation_15_loss/soft_dice_loss/weighted_loss/mul_grad/Mul_1}}]]
Could u plz help ? Many Thanks !
Best Regards
Zuobin