Pytorch 0.3加载0.4模型
Posted ranjiewen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Pytorch 0.3加载0.4模型相关的知识,希望对你有一定的参考价值。
- pytorch0.4有一些接口已经改变,且模型向下版本兼容,不向上兼容。
- In PyTorch 0.4, is it recommended to use `reshape` than `view` when it is possible?
- Question about ‘rebuild_tensor_v2‘?
使用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
- 拷贝一些权重到新的模型方法,感觉不能直接抽取sequential里面的某一层,除非重新构建模型,forward得到该层的内容,或者使用hook操作;
- pytorch在fintune时将sequential中的层输出,以vgg为例
以上是关于Pytorch 0.3加载0.4模型的主要内容,如果未能解决你的问题,请参考以下文章