Python 如何将历元号填充到回调函数的检查点路径中?
白色的工作,我注意到这一行Python 如何将历元号填充到回调函数的检查点路径中?,python,tensorflow,Python,Tensorflow,白色的工作,我注意到这一行 checkpoint_path = "training_2/cp-{epoch:04d}.ckpt" # <<-- this {epoch:04} thing cp_callback = tf.keras.callbacks.ModelCheckpoint( filepath=checkpoint_path, verbose=1, save_weights_only=True, period=5)
checkpoint_path = "training_2/cp-{epoch:04d}.ckpt" # <<-- this {epoch:04} thing
cp_callback = tf.keras.callbacks.ModelCheckpoint(
filepath=checkpoint_path,
verbose=1,
save_weights_only=True,
period=5)
model.fit(train_images,
train_labels,
epochs=50,
callbacks=[cp_callback],
validation_data=(test_images,test_labels),
verbose=0)
但我不明白,如何使用{epoch:04d}将epoch编号填充到检查点路径中
要格式化为字符串,应该有一个f前缀,比如f'{epoch}',或者使用'{}'。格式化(epoch)
training_2/cp-0001.ckpt
training_2/cp-0002.ckpt
...