Search code examples
pythonneural-networkdeep-learningcaffepycaffe

Extracting weights from .caffemodel without caffe installed in Python


Is there a relatively simple way to extract weights in Python from one of the many pretrained models in Caffe Zoo WITHOUT CAFFE (nor pyCaffe)? i.e. parsing .caffemodel to hdf5/numpy or whatever format that can be read by Python?

All the answers I found use C++ code with caffe classes or Pycaffe. I have looked at pycaffe's code it looks like you really need caffe to make sense of the binary is that the only solution?


Solution

  • As it so happens, ethereon made a wonderful library called caffe-tensorflow to convert caffe models to Tensorflow code, but that is not all! It also allows the user to convert .caffemodel files to .npy files without having to build pycaffe! It tests if caffe was built and if not it falls back to a pure google protobuf implementation.