Sunday, December 6, 2015

fatal error: 'cblas.h' file not found

I once again found myself installing caffe on my Mac, and ran into that error. The solution was to install openblas via "brew install openblas", and then edit the relevant lines in Makefile.config to look like this:

BLAS := open
BLAS_INCLUDE := /usr/local/Cellar/openblas/0.2.14_1/include
BLAS_LIB := /usr/local/Cellar/openblas/0.2.14_1/lib

Also, I was getting some weird permission errors about inability to do the linking (when using brew install). I tried "sudo brew link openblas" and then got a confusing error about sudo. The solution was to execute the following lines:

sudo chown -R `whoami`:admin /usr/local/bin

sudo chown -R `whoami`:admin /usr/local/share

After that I was able to brew link as needed.

Contents of my Makefile.config, largely for my own reference (I think the only other things I modified were the python paths for anaconda: http://pastebin.com/RscLA8j9)

Thursday, December 3, 2015

How to parse a caffe deploy.prototxt file or solver.prototxt file using python.


1) Install google's protobuf by downloading the source from https://developers.google.com/protocol-buffers/docs/downloads (I had protobuf-2.6.1.tar.gz), untarring (tar -zxvf [filename]), and following the instructions in the README

2) Get your caffe .proto file. It lives in [caffe folder]/src/caffe/proto/caffe.proto

3) Compile the caffe.proto file with protoc --python_out=. caffe.proto; it will produce caffe_pb2.py in the same directory.

4.1) For parsing a deploy.prototxt file, use:

import caffe_pb2 #you created this module with the protoc command
from google.protobuf.text_format import Merge
net = caffe_pb2.NetParameter()
Merge((open("deploy.prototxt",'r').read()), net)

4.2) For parsing a solver.prototxt file, use:

import caffe_pb2 #you created this module with the protoc command
from google.protobuf.text_format import Merge
solver = caffe_pb2.SolverParameter()
Merge((open("solver.prototxt",'r').read()), solver)

Remember, you can inspect the attributes of the object using dir(net) or dir(solver)