使用TensorFlow Model Maker如何在训练过程中保存检查点

yiytaume  于 7个月前  发布在  其他
关注(0)|答案(2)|浏览(74)

我正在使用TensorflowLite model maker,我想知道如何在训练期间定期保存检查点,以便使用tensorboard检查损失图。如何做到这一点?
当我想训练时,我会调用这个函数,但似乎没有额外的设置,如写入检查点或为其指定目录。
第一个月

djp7away

djp7away1#

好了,我发现了它是如何工作的!参数grad_checkpoint=true必须在指定给object_detector.create()函数的spec对象中设置!在spec中,模型检查点目录也可以指定!这就是我如何让它工作的:

spec = object_detector.EfficientDetLite0Spec(
    model_name='efficientdet-lite0',
    model_dir='/home/alex/checkpoints_1/',
    hparams='grad_checkpoint=true,strategy=gpus',
    epochs=30, batch_size=8,
    steps_per_execution=1, moving_average_decay=0,
    var_freeze_expr='(efficientnet|fpn_cells|resample_p6)',
    tflite_max_detections=25
)

model = object_detector.create(train_data, model_spec=spec, batch_size=8, 
    train_whole_model=True, validation_data=validation_data)

字符串

tktrz96b

tktrz96b2#

TensorFlow Lite Model Maker不提供在训练期间保存检查点的直接方法,但您可以使用tensorboard。尝试以下操作:

import tensorflow as tf

checkpoint_callback = tf.keras.callbacks.ModelCheckpoint(
    filepath='path/to/checkpoints/model_checkpoint.h5',
    save_weights_only=True,
    save_best_only=True,
    monitor='val_loss',  # Choose a metric to monitor
    mode='min',  # 'min' or 'max' depending on the metric
)

tensorboard_callback = tf.keras.callbacks.TensorBoard(
    log_dir='path/to/tensorboard/logs',
    write_graph=True,
    write_images=True
)

# Train the model with callbacks
model.fit(
    train_data,
    validation_data=validation_data,
    epochs=10,  # Set the number of epochs
    callbacks=[checkpoint_callback, tensorboard_callback]
)

字符串
如果你需要更多关于tensorboard的信息,请告诉我。

相关问题