BVLC/caffe — pull request #219 by jeffdonahue (2014-03-17 14:01:04+00:00)
Title: Refactor LayerParameter into per-layer Parameter messages

Addresses #208. This changes the way net protos are specified. Before:

```
layers {
layer {
name: "conv1"
type: "conv"
num_output: 96
kernelsize: 11
stride: 4
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0.
}
blobs_lr: 1.
blobs_lr: 2.
weight_decay: 1.
weight_decay: 0.
}
bottom: "data"
top: "conv1"
}
```

After:

```
layers {
name: "conv1"
type: CONVOLUTION
bottom: "data"
top: "conv1"
blobs_lr: 1
blobs_lr: 2
weight_decay: 1
weight_decay: 0
convolution_param {
num_output: 96
kernel_size: 11
stride: 4
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0
}
}
}
```

The most notable change is that we have a message, e.g., `convolution_param`. for each layer type that has its own parameters. I also turned the layer types from a string into an enum to catch spelling errors etc. at compile time.

This should be fully backward compatible with old model protos - the `Net::Net(const string& param_file)` constructor will attempt to load the param_file using the new proto specification, but if that fails will instead try to load it with the old ("v0") proto specification and then convert it to the new format at runtime, printing a warning that you should convert your nets to the new format.

There is also a script `tools/upgrade_net_proto.cpp` which converts the a v0-formatted proto to the new format and saves the new format to a file.

Both the converter script and the Net constructor will first pass the v0 formatted proto through a function `UpgradeV0Padding` that turns padding layers into pad-aware conv layers (assuming they are passed into conv layers; errors if not), and then another function that upgrades to the new proto format.