Open source project: Convert caffe's models (prototxt and caffemodel) to tensorflow (py and npy)
https://github.com/ethereon/caffe-tensorflow
Unzip caffe-tensorflow to a directory and enter.
Convert command:
python convert.py googlenet.prototxt --caffemodel googlenet.caffemodel --code-output-path=googlenet.py --data-output-path=googlenet.npy
The conversion is completed as shown below
Problems encountered:
1. TypeError: Descriptors should not be created directly, but only retrieved from their parent.
Attempted solution: Rename kaffe
/caffe/caffepb.py to caffe_pb2.py
17 18 lines of content
from . import caffepb
self.caffepb = caffepb
change to
from . import caffe_pb2
self.caffepb = caffe_pb2
2.Error encountered: Unknown layer type encountered
due to different caffe versions, solution: use the installed caffe version to update prototxt and caffemodel
Update prototxt:
/root/caffe/build/tools/upgrade_net_proto_text old.prototxt new.prototxt
Update caffemodel:
/root/caffe/build/tools/upgrade_net_proto_binary old.caffemodel new.caffemodel
3.Error encountered: Multiple top nodes are not supported
Layers in the network are not allowed to have two outputs top
Workaround: Change the two outputs in the layer to one output
4.Error encountered: Cannot determine dimensions of data layer.
See comments in function shape_data for more infoData
layer input format must be (dim:batchsize dim:channels dim:weight dim:heigh)
layer {
name: "data"
type: "Input"
top: "data"
input_param { shape: { dim: 64 dim: 1 dim: 28 dim: 28 } }
}