How to resume a pytorch training of a deep learning model while training stopped due to power issues or some other interrpts

huangapple go评论56阅读模式
英文:

How to resume a pytorch training of a deep learning model while training stopped due to power issues or some other interrpts

问题

我正在训练一个深度学习模型,想要保存模型的检查点,但当电源中断时,训练会停止,然后我需要从被中断的那一点重新开始,比如已完成了10个epochs,我想要从第11个epoch重新开始,使用之前的参数。

英文:

Actually i am training a deep learning model and want to save checkpoint of the model but its stopped when power is off then i have to start from that point from which its interrupted like 10 epoches completed and want to resume/start again from epoch 11 with that parameters

答案1

得分: 1

在PyTorch中,您可以使用checkpoint字典中的epoch键来从特定点恢复,如下所示:

# 载入模型检查点
checkpoint = torch.load("checkpoint.pth")
model.load_state_dict(checkpoint['model'])
epoch = checkpoint['epoch']

# 从特定的纪元恢复训练
for epoch in range(epoch + 1, num_epochs):
    ...

注意:代码部分不会进行翻译。

英文:

In PyTorch, you can resume from a specific point by using epoch key from the checkpoint dictionary as follows:

# Load model checkpoint
checkpoint = torch.load("checkpoint.pth")
model.load_state_dict(checkpoint['model'])
epoch = checkpoint['epoch']

# Resume training from a specific epoch
for epoch in range(epoch + 1, num_epochs):
    ...

huangapple
  • 本文由 发表于 2023年2月6日 13:33:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75357653.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定