【问题标题】:Is it possible to resume training from a checkpoint model in Tensorflow?是否可以从 Tensorflow 中的检查点模型恢复训练?
【发布时间】:2020-08-11 16:59:01
【问题描述】:

我正在做自动分割,周末我正在训练一个模型,然后电源就坏了。我已经训练了我的模型 50 多个小时,并使用以下行每 5 个 epoch 保存我的模型:

model_checkpoint = ModelCheckpoint('test_{epoch:04}.h5', monitor=observe_var, mode='auto', save_weights_only=False, save_best_only=False, period = 5)

我正在使用以下行加载保存的模型:

model = load_model('test_{epoch:04}.h5', custom_objects = {'dice_coef_loss': dice_coef_loss, 'dice_coef': dice_coef})

我已经包含了我的所有数据,这些数据将我的训练数据拆分为train_x 用于扫描和train_y 用于标签。当我运行这条线时:

loss, dice_coef = model.evaluate(train_x,  train_y, verbose=1)

我得到错误:

ResourceExhaustedError:  OOM when allocating tensor with shape[32,8,128,128,128] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
 [[node model/conv3d_1/Conv3D (defined at <ipython-input-1-4a66b6c9f26b>:275) ]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.
 [Op:__inference_distributed_function_3673]

Function call stack:
distributed_function

【问题讨论】:

    标签: python tensorflow machine-learning training-data resuming-training


    【解决方案1】:

    这基本上是您的内存不足。所以您需要以小批量方式进行评估。默认批量大小为 32 并尝试分配小批量大小。

    evaluate(train_x,  train_y, batch_size=<batch size>)
    

    来自keras documentation

    batch_size:整数或无。每次梯度更新的样本数。如果 未指定,batch_size 将默认为 32。

    【讨论】:

      猜你喜欢
      • 2017-07-12
      • 1970-01-01
      • 2018-02-16
      • 2016-09-29
      • 2018-08-05
      • 1970-01-01
      • 2017-09-08
      • 2020-07-24
      • 1970-01-01
      相关资源
      最近更新 更多