PyTorch2Caffe 是一个可以将 Pytorch 模型转换为 Caffe 模型的工具,支持多种网络结构(好像对upsampling支持还不太友好)。具体方法可以见下方代码实例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | # We can obtain almost the same output from caffe except Upsampling # for inception_v3: # diff between pytorch and caffe: min: 0.0, max: 1.76429748535e-05, mean: 2.14079022953e-06 # see more in demo.py import torch from torch.autograd import Variable import torchvision import os from pytorch2caffe import pytorch2caffe, plot_graph m = torchvision.models.inception_v3(pretrained=True, transform_input=False) m.eval() print(m) input_var = Variable(torch.rand(1, 3, 299, 299)) output_var = m(input_var) output_dir = 'demo' # plot graph to png plot_graph(output_var, os.path.join(output_dir, 'inception_v3.dot')) pytorch2caffe(input_var, output_var, os.path.join(output_dir, 'inception_v3-pytorch2caffe.prototxt'), os.path.join(output_dir, 'inception_v3-pytorch2caffe.caffemodel')) |
工具地址:Github
本站微信群、QQ群(三群号 726282629):