BVLC/caffe — pull request #501 by sguada (2014-06-14 02:49:23+00:00)
Title: Matcaffe2

A new and completely renovated CaffeNet interface (although backward compatible).

Now there is class CaffeNet that handle all the interactions with caffe.

New Features:
- `net = CaffeNet.instance` gets a instance of caffe network using default imagenet_deploy and caffe_reference_model
- `net = CaffeNet.instance(model_def_file, model_file)` gets an instance of caffe network using the parameters specified.
```
net =
CaffeNet with properties:

model_def_file: '../../examples/imagenet/imagenet_deploy.prototxt'
model_file: '../../examples/imagenet/caffe_reference_imagenet_model'
layers_info: [23x1 struct]
blobs_info: [15x1 struct]
mode: 'CPU'
phase: 'TRAIN'
device_id: 0
input_blobs: []
output_blobs: []
weights: [8x1 struct]
```
- Now one can set mode, phase or device_id, just by assigning the properties or using the corresponding methods.
``` net.phase = 'TEST'; net.set_phase_test; net.set_phase('TEST');```
```net.mode = 'GPU'; net.set_mode_gpu; net_set_mode('GPU');```
```net.device_id = 1;net.set_device(1); ```

- One can access the weights of the network just by
```
net.weights
8x1 struct array with fields:

layer_name
weights
```
- More amazingly can change the weights of the network by just assigning a new set of weights, for example changing the bias of the first layer `conv1`.
```
new_weights = net.weights;
new_weights(1)
layer_name: 'conv1'
weights: {2x1 cell}
new_weights(1).weights{2}(:) = 0;
net.weights = new_weights;
```
- Then one can save the new network in a different model_file
```
net.save_net('path_to/new_model')
```

- And load it later
```
net.load_net('path_to/new_model')
```

More examples about new features to follow.