我正在尝试使用keras在模型训练中实现不同的检查点。当我使用单个检查点时,它运行良好,但是当我将多个检查点作为列表提供时,它给了我一条错误消息。
model_1_checkpoint = ModelCheckpoint('model/model1/model.{epoch:02d}-{val_loss:.2f}.hdf5', monitor='val_loss', \
save_best_only=True, verbose=1)
model_1_tensorboard = TensorBoard(log_dir=str('logs/scalars/'+datetime.datetime.now().strftime("%Y%m%d-%H%M%S")),\
histogram_freq=0, write_graph=True, write_images=True, embeddings_freq=0, \
embeddings_layer_names=None, embeddings_metadata=None),
keras_callbacks_1 = EarlyStopping(monitor='val_mean_absolute_error', patience=20, verbose=1, restore_best_weights=True)
callback = [model_1_checkpoint, model_1_tensorboard, keras_callbacks_1]
model_1.fit(x_train_array, y_train_array,
batch_size=batch_size,
epochs=epochs,
shuffle=True,
verbose=1, # Change it to 2, if wished to observe execution one line per epoch. o if not. 1 for progress bar
validation_data=(x_validation_array, y_validation_array),
callbacks=callback,
use_multiprocessing=True,
workers=30)
错误消息:
AttributeError Traceback (most recent call last)
<ipython-input-203-3b2d923f4ffd> in <module>
7 callbacks=callback,
8 use_multiprocessing=True,
----> 9 workers=30)
/app/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs)
778 validation_steps=validation_steps,
779 validation_freq=validation_freq,
--> 780 steps_name='steps_per_epoch')
781
782 def evaluate(self,
/app/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/training_arrays.py in model_iteration(model, inputs, targets, sample_weights, batch_size, epochs, verbose, callbacks, val_inputs, val_targets, val_sample_weights, shuffle, initial_epoch, steps_per_epoch, validation_steps, validation_freq, mode, validation_in_fit, prepared_feed_values_from_dataset, steps_name, **kwargs)
211 samples=num_samples_or_steps,
212 verbose=0, # Handle ProgBarLogger separately in this loop.
--> 213 mode=mode)
214 # TODO(omalleyt): Handle ProgBar as part of Callbacks once hooks are ready.
215 progbar = training_utils.get_progbar(model, count_mode)
/app/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/callbacks.py in configure_callbacks(callbacks, model, do_validation, batch_size, epochs, steps_per_epoch, samples, verbose, count_mode, mode)
103 # Set callback model
104 callback_model = model._get_callback_model() # pylint: disable=protected-access
--> 105 callback_list.set_model(callback_model)
106
107 set_callback_parameters(
/app/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/callbacks.py in set_model(self, model)
229 self.model = model
230 for callback in self.callbacks:
--> 231 callback.set_model(model)
232
233 def _call_batch_hook(self, mode, hook, batch, logs=None):
AttributeError: 'tuple' object has no attribute 'set_model'