此文基于新版本Pytorch中load_lua失效的解决办法及参数获取_lihengbit的博客-CSDN博客 上作扩展!
原文方法一比较简洁但需要在转换GitHub - sunshineatnoon/PytorchWCT: This is the Pytorch implementation of Universal Style Transfer via Feature Transforms.时报错。这里提供解决方法如下:
import torchfile
from torchfile import load, TorchObject
from models.vgg import encoder5, decoder5
import torch
from collections import namedtuple
vgg5_path = 'models/pretrain_models/vgg_normalised_conv5_1.t7'
vgg5 = load(vgg5_path)
def torch_object_parse(obj):
if isinstance(obj, list):
return [torch_object_parse(o) for o in obj]
if isinstance(obj, dict):