码迷,mamicode.com
首页 > 其他好文 > 详细

Pytorch 0.3加载0.4模型

时间:2018-08-16 01:06:35      阅读:351      评论:0      收藏:0      [点我收藏+]

标签:with   tee   class   ror   tps   内容   error:   storage   when   

- pytorch0.4有一些接口已经改变,且模型向下版本兼容,不向上兼容。

使用pytorch0.3导入pytorch0.4保存的模型时候:

 Monkey-patch because I trained with a newer version.
# This can be removed once PyTorch 0.4.x is out.
# See https://discuss.pytorch.org/t/question-about-rebuild-tensor-v2/14560
import torch._utils
try:
    torch._utils._rebuild_tensor_v2
except AttributeError:
    def _rebuild_tensor_v2(storage, storage_offset, size, stride, requires_grad, backward_hooks):
        tensor = torch._utils._rebuild_tensor(storage, storage_offset, size, stride)
        tensor.requires_grad = requires_grad
        tensor._backward_hooks = backward_hooks
        return tensor
    torch._utils._rebuild_tensor_v2 = _rebuild_tensor_v2

Pytorch 0.3加载0.4模型

标签:with   tee   class   ror   tps   内容   error:   storage   when   

原文地址:https://www.cnblogs.com/ranjiewen/p/9484323.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!