Code Monkey home page Code Monkey logo

mxnet2caffe-tensor-rt-senet's Introduction

MXNet2Caffe: Convert MXNet model to Caffe model,And use Tensor-RT Plugin_Class to improve performance (SEnet)

  • caffe_plugin_layer

  • mxnet2caffe

  • caffe2TensorRT

  • TensorRT_plugin_layer

    Provide mxnet to caffe conversion tool,currently supports Conv、BN、Elemwise、Concat、Pooling、Flatten、 Cast、Fully、Slice、L2、Reshape、Broadcast etc. And then use the TensorRT(4.0) engine to parse the caffe model to improve performance.The project was successfully tested on SEnet.

Code

  • json2prototxt.py prototxt_basic.py Read mxnet_json file and converte to prototxt
  • mxnet2caffe.py Read mxnet_model params_dict and converte to .caffemodel
  • mxnet_test.py Debug mxnet output and you can compare the result with the converted caffemodel
  • load_param.py Print mxnet or caffe model param_dict
  • caffe_plugin_layer Add caffe plugin_layer, but forward computing implementation in Tensorrt_RT Plugin layer
  • Tensor_RT/Tensor_RT_Plugin.cpp Add Brocast_layer、Pooling and debug_layer in Tensor_RT by using IPluginExt API

caffe_plugin_layer

The caffe framework does't support many Layers_op. If you need to convert a special layer, you need to add a layer plugin in the caffe framework and register the Layer_param. Otherwise, you will get an error when building the network structure using this tool.

  • Add layer implementations in the caffe/src/caffe/layers/ directory, such as broadcast_mul.cpp broadcast_mul.cu,You need to provide forward and reverse operations.
  • Add a layer declaration in the caffe/include/caffe/layers/ directory, such as broadcast_mul.hpp
  • Register Layer_param in caffe/src/caffe/proto/caffe.proto (read the parameters required for the Layer from prototxt)
message LayerParameter {
  optional string name = 1; // the layer name
  optional string type = 2; // the layer type
  repeated string bottom = 3; // the name of each bottom blob
  repeated string top = 4; // the name of each top blob
  ......
  
  optional BroadcastmulParameter broadcastmul_param = 230;
}

message BroadcastmulParameter {  
   
} 
  • Re-make build libcaffe.so
  • sudo make pycaffe recompile python interface ***

mxnet2caffe

  • First,you should run json2prototxt.py to convert the structure(json) of the mxnet model to prototxt format.
  • Then, run mxnet2caffe.py to read the prototxt network structure build using the API provided by pycaffe.
  • Using mxnet_Api Read the param parameter saved by mxnet, and copy the parameter key value pair into the caffemodel file;

caffe2TensorRT and TensorRT_plugin_layer

The tensorrt engine can directly parse the caffe model. For unsupported ops, you can manually add them using the interface. This project adds a broadcast operation. In addition, it also tests the Pooling_layer,It also adds a test layer, which can separately print the parameters in the structure and assist the Debug.

  • Firsy,Inherit the IPluginExt interface to create a custom layer class

  • Create a PluginFactory function that will be used to add custom layer classes to the network.


  virtual int getNbOutputs() const = 0;

  virtual Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) = 0;

  virtual void configure(const Dims* inputDims, int nbInputs, const Dims* outputDims, int nbOutputs, int maxBatchSize) = 0;

  virtual int initialize() = 0;

  virtual void terminate() = 0;

  virtual size_t getWorkspaceSize(int maxBatchSize) const = 0;

  virtual int enqueue(int batchSize, const void*const * inputs, void** outputs, void* workspace, cudaStream_t stream) = 0;

  virtual size_t getSerializationSize() = 0;

  virtual void serialize(void* buffer) = 0;

This project provide Pooling, broadcast, and test_layer,you can see the implementation in the code.

TODO:

  • Tensor RT supported Se_Resnet

mxnet2caffe-tensor-rt-senet's People

Contributors

junqiangwu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mxnet2caffe-tensor-rt-senet's Issues

reshape是不是写错了

txt_file.write(' dim: %s\n' % info['attrs']['shape'].split(')')[0].split(',')[3])是不是写错了,总共就三维

can caffe Tile Layer use the your TensorRT plugin?

hi, it's awesome to see this project and i am wondering if i can use this in my own code. What i encountered is when i element wise mutiply two matrix whose shape is (2048, 128, 24, 24) and (2018, 128, 1, 1), it add a Tile Layer in prototxt, and it seems like this layer is not supported by the tensorrt 5.0. So i would like to know if i can use your Brodcast code and if i want to use what should i change? thanks.

About brocastmul layer

hello,I want to ask about how u transform brocastmul layer,there is a problem which shows Unknown layer type: Broadcastmul.look forward to your reply!

{4977E824-C6C9-4EA6-B121-B8A3F19064F7}

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.