import numpy as npimport h5pyimport sysimport caffe
file_labels = 'simple_labels.txt'outputH5_prefix = 'simple'
X = []y = []for i in range(100): for j in range(100): f = 3 * i + 5 * j X.append([i, j]) y.append([f])
outputH5 = outputH5_prefix + ".h5"
with h5py.File(outputH5,'w') as H: H.create_dataset( 'data', data=np.array(X).astype(np.float32) ) H.create_dataset( 'label', data=np.array(y).astype(np.float32) )
with open(outputH5_prefix + '_h5_list.txt','w') as L: L.write(outputH5)
net: "simple_net.prototxt"
type: "SGD"
test_iter: 10test_interval: 50
base_lr: 0.01weight_decay: 0.00005momentum: 0.9
lr_policy: "step"gamma: 0.1stepsize: 10
display: 10max_iter: 80000
snapshot: 1000snapshot_prefix: "snapshots/simple_net"
solver_mode: CPU
name: "simple_net"
layer { name: "input" type: "HDF5Data"
hdf5_data_param { source: "simple_h5_list.txt" batch_size: 32 }
top: "data" top: "label"}
layer { name: "relu1" type: "ReLU" bottom: "data" top: "conv1"}
layer { name: "ip1" type: "InnerProduct" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 10 weight_filler { type: "xavier" } bias_filler { type: "constant" } } bottom: "conv1" top: "ip1"}
layer { name: "relu3" type: "ReLU" bottom: "ip1" top: "ip1"}
layer { name: "ip2" type: "InnerProduct" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 1 weight_filler { type: "xavier" } bias_filler { type: "constant" } } bottom: "ip1" top: "ip2"}
layer { name: "relu4" type: "ReLU" bottom: "ip2" top: "ip2"}
layer { name: "loss" type: "EuclideanLoss" bottom: "ip2" bottom: "label" }
layer { name: "accuracy" type: "Accuracy" bottom: "ip2" bottom: "label" top: "accuracy"}
name: "letter_net"input: "data"input_dim: 10input_dim: 1input_dim: 1input_dim: 2
layer { name: "relu1" type: "ReLU" bottom: "data" top: "conv1"}
layer { name: "ip1" type: "InnerProduct" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 10 weight_filler { type: "xavier" } bias_filler { type: "constant" } } bottom: "conv1" top: "ip1"}
layer { name: "relu3" type: "ReLU" bottom: "ip1" top: "ip1"}
layer { name: "ip2" type: "InnerProduct" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 1 weight_filler { type: "xavier" } bias_filler { type: "constant" } } bottom: "ip1" top: "ip2"}
layer { name: "relu4" type: "ReLU" bottom: "ip2" top: "ip2"}
import numpy as npimport caffe
net = caffe.Net("simple_deploy.prototxt", "snapshots/simple_net_iter_80000.caffemodel", caffe.TEST)
net.blobs['data'].reshape(1, 1, 1, 2)net.blobs['data'].data[...] = [10, 20]
output = net.forward()print net.blobs['ip2'].data
name: "simple_net"
name: "letter_net"