parent
d0875b1c4c
commit
f8119ea058
11 changed files with 270 additions and 51 deletions
@ -0,0 +1,39 @@ |
||||
name: "test_Convolution" |
||||
input: "input" |
||||
|
||||
input_dim: 2 |
||||
input_dim: 6 |
||||
input_dim: 75 |
||||
input_dim: 113 |
||||
|
||||
layer { |
||||
type: "Convolution" |
||||
|
||||
convolution_param |
||||
{ |
||||
group: 3 |
||||
num_output: 12 |
||||
|
||||
pad_h: 0 |
||||
pad_w: 1 |
||||
kernel_h: 4 |
||||
kernel_w: 5 |
||||
stride_h: 2 |
||||
stride_w: 3 |
||||
|
||||
weight_filler{ |
||||
type: 'uniform' |
||||
min: -1 |
||||
max: 1 |
||||
} |
||||
bias_filler { |
||||
type: 'uniform' |
||||
min: -1 |
||||
max: 1 |
||||
} |
||||
} |
||||
|
||||
name: "output" |
||||
bottom: "input" |
||||
top: "output" |
||||
} |
@ -0,0 +1,39 @@ |
||||
name: "test_Convolution" |
||||
input: "input" |
||||
|
||||
input_dim: 2 |
||||
input_dim: 6 |
||||
input_dim: 75 |
||||
input_dim: 113 |
||||
|
||||
layer { |
||||
type: "Deconvolution" |
||||
|
||||
convolution_param |
||||
{ |
||||
group: 3 |
||||
num_output: 12 |
||||
|
||||
pad_h: 0 |
||||
pad_w: 1 |
||||
kernel_h: 4 |
||||
kernel_w: 5 |
||||
stride_h: 2 |
||||
stride_w: 3 |
||||
|
||||
weight_filler{ |
||||
type: 'uniform' |
||||
min: -1 |
||||
max: 1 |
||||
} |
||||
bias_filler { |
||||
type: 'uniform' |
||||
min: -1 |
||||
max: 1 |
||||
} |
||||
} |
||||
|
||||
name: "output" |
||||
bottom: "input" |
||||
top: "output" |
||||
} |
@ -0,0 +1,32 @@ |
||||
name: "test_InnerProduct" |
||||
input: "input" |
||||
|
||||
input_dim: 2 |
||||
input_dim: 6 |
||||
input_dim: 75 |
||||
input_dim: 113 |
||||
|
||||
layer { |
||||
type: "InnerProduct" |
||||
|
||||
inner_product_param |
||||
{ |
||||
axis: 3 |
||||
num_output: 2 |
||||
|
||||
weight_filler{ |
||||
type: 'uniform' |
||||
min: -1 |
||||
max: 1 |
||||
} |
||||
bias_filler { |
||||
type: 'uniform' |
||||
min: -1 |
||||
max: 1 |
||||
} |
||||
} |
||||
|
||||
name: "output" |
||||
bottom: "input" |
||||
top: "output" |
||||
} |
@ -0,0 +1,26 @@ |
||||
name: "test_Pooling_max" |
||||
input: "input" |
||||
|
||||
input_dim: 2 |
||||
input_dim: 6 |
||||
input_dim: 75 |
||||
input_dim: 113 |
||||
|
||||
layer { |
||||
type: "Pooling" |
||||
|
||||
pooling_param |
||||
{ |
||||
pool: AVE |
||||
pad_h: 2 |
||||
pad_w: 1 |
||||
kernel_h: 3 |
||||
kernel_w: 5 |
||||
stride_h: 2 |
||||
stride_w: 1 |
||||
} |
||||
|
||||
name: "output" |
||||
bottom: "input" |
||||
top: "output" |
||||
} |
@ -0,0 +1,26 @@ |
||||
name: "test_Pooling_max" |
||||
input: "input" |
||||
|
||||
input_dim: 2 |
||||
input_dim: 6 |
||||
input_dim: 75 |
||||
input_dim: 113 |
||||
|
||||
layer { |
||||
type: "Pooling" |
||||
|
||||
pooling_param |
||||
{ |
||||
pool: MAX |
||||
pad_h: 2 |
||||
pad_w: 1 |
||||
kernel_h: 3 |
||||
kernel_w: 5 |
||||
stride_h: 2 |
||||
stride_w: 1 |
||||
} |
||||
|
||||
name: "output" |
||||
bottom: "input" |
||||
top: "output" |
||||
} |
@ -0,0 +1,48 @@ |
||||
# coding: utf-8 |
||||
|
||||
import sys, os, glob |
||||
|
||||
CAFFE_ROOT = "/home/vitaliy/opencv/caffe/" |
||||
sys.path.insert(0, CAFFE_ROOT + 'python') |
||||
|
||||
CV2_DIR = "/home/vitaliy/opencv/build-opencv-qt/lib" |
||||
sys.path.insert(0, CV2_DIR) |
||||
|
||||
|
||||
import numpy as np |
||||
import caffe |
||||
import cv2 |
||||
|
||||
def get_cafe_output(inp_blob, proto_name, caffemodel_name): |
||||
caffe.set_mode_cpu() |
||||
net = caffe.Net(proto_name, caffe.TEST) |
||||
|
||||
net.blobs['input'].reshape(*inp_blob.shape) |
||||
net.blobs['input'].data[...] = inp_blob |
||||
|
||||
net.forward() |
||||
out_blob = net.blobs['output'].data[...]; |
||||
|
||||
if net.params.get('output'): |
||||
print "Params count:", len(net.params['output']) |
||||
net.save(caffemodel_name) |
||||
|
||||
return out_blob |
||||
|
||||
if __name__ == '__main__': |
||||
proto_filenames = glob.glob("*.prototxt") |
||||
|
||||
inp_blob = np.load('blob.npy') |
||||
print inp_blob.shape |
||||
|
||||
for proto_filename in proto_filenames: |
||||
proto_filename = os.path.basename(proto_filename) |
||||
proto_basename = os.path.splitext(proto_filename)[0] |
||||
cfmod_basename = proto_basename + ".caffemodel" |
||||
npy_filename = proto_basename + ".npy" |
||||
|
||||
print cfmod_basename |
||||
|
||||
out_blob = get_cafe_output(inp_blob, proto_filename, cfmod_basename) |
||||
print out_blob.shape |
||||
np.save(npy_filename, out_blob) |
Loading…
Reference in new issue