https://github.com/longcw/pytorch2caffe
Convert PyTorch model to Caffemodel
https://github.com/longcw/pytorch2caffe
Last synced: 9 days ago
JSON representation
Convert PyTorch model to Caffemodel
- Host: GitHub
- URL: https://github.com/longcw/pytorch2caffe
- Owner: longcw
- Created: 2017-08-28T05:17:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-28T02:29:19.000Z (almost 6 years ago)
- Last Synced: 2025-03-29T14:11:21.761Z (16 days ago)
- Language: Python
- Size: 1.6 MB
- Stars: 541
- Watchers: 12
- Forks: 151
- Open Issues: 25
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- Awesome-pytorch-list-CNVersion - pytorch2caffe
- Awesome-pytorch-list - pytorch2caffe
README
## PyTorch2Caffe
**Require Pytorch < 0.4**
Ported from [pytorch-caffe-darknet-convert](https://github.com/marvis/pytorch-caffe-darknet-convert).
Add support for
+ Dilated Convolution Layer
+ Concat Layer
+ Upsampling (converted to Deconvolution with bilinear initialization)
+ Eltwise Product
+ Sigmoid Layer```python
# 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.pyimport torch
from torch.autograd import Variable
import torchvisionimport os
from pytorch2caffe import pytorch2caffe, plot_graphm = 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'))```