Caffe Convert TensorFlow Tool caffe-tensorflow

Source: Internet
Author: User
Introduction and use of Caffe-tensorflow conversion

Caffe-tensorflow can convert Caffe network definition file and pre-training parameters into TensorFlow form, including TensorFlow network structure source code and NPY format weight file.
Download the source code from GitHub and enter the source directory to run convert.py.
Its invocation format is

Python convert.py def_path--caffemodel caffemodel_path--data-output-path dataoutput_path--code-output-path Codeoutput_path

Where Def_path is required, four parameters two caffe input, two TensorFlow end outputs. Only the first three parameters are required if you need only the weight parameter. The TensorFlow code for the output is the subclass of the network in its source, and the networking build process implements its Setup method, so it needs to be introduced in the code to be called. TensorFlow Directory network.py This file implements the network class, this class encapsulates a number of layers, including the conv layer with group, Caffe-tensorflow conversion is relatively safe, self-conversion will encounter many such as CAFFE,TENSORFL ow convolution kernel format, FC weight format, input and output data presentation format of the different problems, Caffe-tensorflow this project will be self-conversion. Caffe-tensorflow Implementation Details

The specific principle of caffe-tensorflow is to read the network definition file through Pycaffe and regenerate a graph, the node on the diagram holds the information of each layer, the Graphbuilder class is responsible for generating the graph structure, each node represents a layer, The author defines a number of transformer, each transformer to do some work on the diagram, there are data in the diagram to manipulate the layer in the diagram is also modified, Where the Datainjector class reads the Caffemodel data and distributes the data to each node of the diagram.

The

Datareshaper converts caffe to different formats in TensorFlow, including convolution kernel format, TensorFlow convolution kernel is [Filter_height, Filter_width, In_channels, Out_channels] and Caffe's convolution core is [Out_channels, In_channels, filter_height, filter_width],tensorflow FC layer parameters are also different from Caffe, TensorFlow is generally the opposite of [Input_dimension,output_dimension],caffe]. And tensorflow the first FC layer needs to pool5 reshape, and POOL5 layer and Caffe layer of POOL5 due to different formats (TensorFlow for NHWC, Caffe is NCHW) so Caffe's weight does not actually work with a simple NHWC format, so the weight of this layer needs to be transformed. In addition, the parameters of LRN also need to be adjusted, detailed in another blog LRN introduction.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.