1. as a data layer
usage:
layer {
name: "data"
type: "Python"
top: "data"
top: "label"
top: "cont"
python_param {
module: "pythondatalayer"
layer: "gene_data"
param_str: " {'batch_size':10, 'shuffle': True} "
}
}
implement:
import caffe
import numpy as np
class gene_data(caffe.Layer):
def setup(self, bottom, top):
self.top_names = ['data', 'label', 'cont']
param = eval(self.param_str)
self.batch_size = param['batch_size']
self.shuffle = param['shuffle']
top[0].reshape(self.batch_size, 3, 10,10)
top[1].reshape(self.batch_size, 1)
top[2].reshape(self.batch_size, 1)
def forward(self, bottom, top):
top[0].data[...] = np.random.randn(self.batch_size, 3, 10,10)
top[1].data[...] = np.random.randn(self.batch_size, 1)
top[2].data[...] = np.random.randn(self.batch_size, 1)
def backward(self, top, propagate_down, bottom):
pass
def reshape(self, bottom, top):
pass
2. as a layer that has learnable parameters
self.diff[...]
top[i].data[...]
bottom[i].data[...]
bottom[i].diff[...]
propagate_down[i]
raise Exception(" xxx ")