Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fully connected multi layer perceptron using PyCaffe

I'm new to Caffe, and its workflow is very different from what I've previously encountered. I've used keras, sklearn, fann (C++) for neural networks before, and I want to use Caffe because of some additional things it offers. But the workflow seems hard to adjust to.

I want to start with a simple, fully connected MLP using PyCaffe. I want to feed it an N-dimensional input vectors and do multi label classification on those. I have the training data. All the Caffe examples seems to be written for images (square matrix inputs).
I also prefer to configure the network programmatically, as opposed to using a lot of configuration files. For example, Keras had a method to sequentially stack layers using add() .

Is it possible to construct a simple network in Caffe using only Python?

like image 281
sanjeev mk Avatar asked May 24 '26 11:05

sanjeev mk


1 Answers

You should look into caffe.NetSpec() interface: this allows you to construct a net programatically. For example:

from caffe import layers as L, params as P, to_proto
import caffe

ns = cafe.NetSpec()

ns.fc1 = L.InnerProduct(name='fc1', inner_product_param={'num_output':100,
                                                         'weight_filler':{'type':'xavier','std':0.1},
                                                         'bias_filler':{'type':'constant','value':0}},
                                    param=[{'lr_mult':1,'decay_mult':2},
                                           {'lr_mult':2,'decay_mult':0}])
ns.relu1 = L.ReLU(ns.fc1, inplace=True)
like image 162
Shai Avatar answered May 27 '26 03:05

Shai