Bolt provide a tool to transform tensorflow model to caffe model and verify the correct of model translation. We define some commonly used caffe layers in tensorflow2caffe.py. You can use these layers to construct your model. We provide some examples in section 3. If you want to add your layers, you can refer section 4 step by step.
-
tensorflow python environment
-
caffe python environment, you need to compile the model_tools project to generate the caffe_pbs2.py in the Caffe directory.
Modify the following variables:
-
tensorflow_model_path: tensorflow bert model path
-
seq_length: input word sequence lenth
-
caffe_model_path_prefix: caffe result model save path prefix
-
check: set whether to check layer name duplicate
-
calc: set whether to use inner Numpy verify program.
you can directly use transform_bert.py and modify some parameters according to downloaded model.
you can directly use transform_albert.py and modify some parameters according to downloaded model.
you can directly use transform_tinybert_mrpc.py for MRPC task, and modify some parameters according to downloaded model.
you can directly use transform_tinybert_intent_slot.py for intention identification, and modify some parameters according to downloaded model.
you can use transform_transformer_lstm.py for transforming neural machine traslation model, and modify some parameters according to downloaded model.
you can use transform_asr.py for recognizing speech model RNT, and modify some parameters according to downloaded model.
you can use transform_convolution_transformer.py for recognizing speech model Convolution+Transformer, and modify some parameters according to downloaded model.
- add layer defination in caffe.proto
- generate caffe_pb2.py by using protobuf tool
- add layer parameter defination in Caffe/layer_parameter.py
- add Numpy operator implementation in operators.py
- add layer in tensorflow2caffe.py
we give an example to use bert tools do inference on mobile device in tinybert. You need to download the Google research bert modeling.py from github, and run the tinybert-infer.py.