Making Prototxt Nets with Python
Krassimir Valev edited this page Mar 1, 2017
·
4 revisions
Pages 35
- Home
- AWS EC2 GPU enabled Caffe AMI
- Borrowing Weights from a Pretrained Network
- Caffe installing script for ubuntu 16.04 support Cuda 8
- Caffe on EC2 Ubuntu 14.04 Cuda 7
- Caffe Output: .caffemodel .solverstate
- Contributing
- Development
- Excluding Layers: Train and Test Phase
- Faster Caffe Training
- Fine Tuning or Training Certain Layers Exclusively
- GeForce GTX 1080, CUDA 8.0, Ubuntu 16.04, Caffe
- IDE Nvidia’s Eclipse Nsight
- Image Format: BGR not RGB
- Install Caffe on EC2 from scratch (Ubuntu, CUDA 7, cuDNN 3)
- Installation
- Installation (OSX)
- Making Prototxt Nets with Python
- Model Zo
- Model Zoo
- Models accuracy on ImageNet 2012 val
- OpenCV 3.2 Installation Guide on Ubuntu 16.04
- Python Layer Unit Tests
- Related Projects
- Reporting Bugs and Other Issues
- Simple Example: Sin Layer
- Solver Prototxt
- The Data Layer
- The Datum Object
- Training and Resuming
- Ubuntu 14.04 ec2 instance
- Ubuntu 14.04 VirtualBox VM
- Ubuntu 16.04 or 15.10 Installation Guide
- Using a Trained Network: Deploy
- Working with Blobs
- Show 20 more pages…
Clone this wiki locally
#NetSpec
This article covers how to make Prototxt nets without having to look at a single protobuf message. The approach can use any of the existing and registered layers.
Diving In
The following is a quick example that creates a prototxt (string; it still needs to be saved).
We first create a DummyData layer, which outputs n.loss and n.label ("loss" and "label" in the proto).
We then pass the outputs to the input of our Python layer, which itself outputs n.accuracy ("accuracy" in the proto).
import caffe
from caffe import layers as L
from caffe import params as P
def example_network(batch_size):
n = caffe.NetSpec()
n.loss, n.label = L.DummyData(shape=[dict(dim=[1]),
dict(dim=[1])],
transform_param=dict(scale=1.0/255.0),
ntop=2)
n.accuracy = L.Python(n.loss, n.label,
python_param=dict(
module='python_accuracy',
layer='PythonAccuracy',
param_str='{ "param_name": param_value }'),
ntop=1,)
return n.to_proto()
Executing the above code will produce the following:
layer {
name: "loss"
type: "DummyData"
top: "loss"
top: "label"
dummy_data_param {
shape {
dim: 1
}
shape {
dim: 1
}
}
}
layer {
name: "accuracy"
type: "Python"
bottom: "loss"
bottom: "label"
top: "accuracy"
python_param {
module: "python_loss_graph"
layer: "PythonLossGraph"
}
}