GithubHelp home page GithubHelp logo

caffe2pytorch's Introduction

Caffe2Pytorch

Introduction

This is a tool for changing Caffe model to Pytorch model. I borrow the main framework from xiaohang's CaffeNet. I modify the structure and add more supports to them.

Given a .prototxt and a .caffemodel, the conversion code generates a .pth. You can use the Pytorch model by the .prototxt and the .pth.

There will be lots of layers in Caffe, it is impossible to know how all layers are constructed. Now the code supports these layers:

'Data', 'AnnotatedData', 'Pooling', 'Eltwise', 'ReLU', 'PReLU', 'Permute', 'Flatten', 'Slice', 'Concat', 'Softmax', 'SoftmaxWithLoss', 'LRN', 'Dropout', 'Reshape', 'PriorBox', 'DetectionOutput'

Dependency

General requirement:

python2 or python3 are both OK, depend on your pycaffe API.

pytorch >= 0.4

Special requirement:

Only the conversion code requires pycaffe.

Usage

Conversion

python caffe2pth_convertor.py \
 --prototxt=YOUT_PROTOTXT_PATH \
 --caffemodel=YOUT_CAFFEMODEL_PATH \
 --pthmodel=OUTPUT_PTHMODEL_PATH

Use the model in Pytorch

from caffe2pth.caffenet import *

net = CaffeNet(YOUT_PROTOTXT_PATH)
net.load_state_dict(torch.load(OUTPUT_PTHMODEL_PATH))

caffe2pytorch's People

Contributors

wei1tang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.