Posts

[Caffe] Try out Caffe with Python code

This document is just a testing record to try out on Caffe with Python code. I refer to this blog. For using Python, we can easily to access every data flow blob in layers, including diff blob, weight blob and bias blob. It is so convenient for us to understand the change of training phase's weights and what have done in each step.

importosimportnumpyasnpimportcaffecaffe_root='/home/liudanny/git/caffe'os.chdir(caffe_root)solver_prototxt='examples/mnist/lenet_solver.prototxt'solver=caffe.SGDSolver(solver_prototxt)net=solver.net# print out all the data flow blobs[(k,v.data.shape)fork,vinnet.blobs.items()][('data',(64,1,28,28)),('label',(64,)),('conv1',(64,20,24,24)),('pool1',(64,20,12,12)),('conv2',(64,50,8,8)),('pool2',(64,50,4,4)),('ip1',(64,500)),('ip2',(64,10)),('loss',())]# print out all the diff blobs[(k,v.diff.shape)fork,vinnet.blobs.items()]Out[20]:[('data',(64,1,28,28)),('labe…