Add support for resnet_14l in tools/export.lua; Add resnet_14l.prototxt
This commit is contained in:
parent
3447c6c44c
commit
cf2493a1a4
524
appendix/caffe_prototxt/resnet_14l.prototxt
Normal file
524
appendix/caffe_prototxt/resnet_14l.prototxt
Normal file
|
@ -0,0 +1,524 @@
|
|||
name: "resnet_14l"
|
||||
layer {
|
||||
name: "input"
|
||||
type: "Input"
|
||||
top: "input"
|
||||
input_param { shape: { dim: 1 dim: 3 dim: 156 dim: 156 } }
|
||||
}
|
||||
layer {
|
||||
name: "Convolution1"
|
||||
type: "Convolution"
|
||||
bottom: "input"
|
||||
top: "Convolution1"
|
||||
convolution_param {
|
||||
num_output: 32
|
||||
bias_term: true
|
||||
pad: 0
|
||||
kernel_size: 3
|
||||
stride: 1
|
||||
weight_filler {
|
||||
type: "msra"
|
||||
}
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "ReLU1"
|
||||
type: "ReLU"
|
||||
bottom: "Convolution1"
|
||||
top: "Convolution1"
|
||||
relu_param {
|
||||
negative_slope: 0.1
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Convolution2"
|
||||
type: "Convolution"
|
||||
bottom: "Convolution1"
|
||||
top: "Convolution2"
|
||||
convolution_param {
|
||||
num_output: 64
|
||||
bias_term: true
|
||||
pad: 0
|
||||
kernel_size: 3
|
||||
stride: 1
|
||||
weight_filler {
|
||||
type: "msra"
|
||||
}
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "ReLU2"
|
||||
type: "ReLU"
|
||||
bottom: "Convolution2"
|
||||
top: "Convolution2"
|
||||
relu_param {
|
||||
negative_slope: 0.1
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Convolution3"
|
||||
type: "Convolution"
|
||||
bottom: "Convolution2"
|
||||
top: "Convolution3"
|
||||
convolution_param {
|
||||
num_output: 64
|
||||
bias_term: true
|
||||
pad: 0
|
||||
kernel_size: 3
|
||||
stride: 1
|
||||
weight_filler {
|
||||
type: "msra"
|
||||
}
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "ReLU3"
|
||||
type: "ReLU"
|
||||
bottom: "Convolution3"
|
||||
top: "Convolution3"
|
||||
relu_param {
|
||||
negative_slope: 0.1
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Convolution4"
|
||||
type: "Convolution"
|
||||
bottom: "Convolution1"
|
||||
top: "Convolution4"
|
||||
convolution_param {
|
||||
num_output: 64
|
||||
bias_term: true
|
||||
pad: 0
|
||||
kernel_size: 1
|
||||
stride: 1
|
||||
weight_filler {
|
||||
type: "msra"
|
||||
}
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Crop1"
|
||||
type: "Crop"
|
||||
bottom: "Convolution4"
|
||||
bottom: "Convolution3"
|
||||
top: "Crop1"
|
||||
crop_param {
|
||||
axis: 2
|
||||
offset: 2
|
||||
offset: 2
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Eltwise1"
|
||||
type: "Eltwise"
|
||||
bottom: "Convolution3"
|
||||
bottom: "Crop1"
|
||||
top: "Eltwise1"
|
||||
eltwise_param {
|
||||
operation: SUM
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Convolution5"
|
||||
type: "Convolution"
|
||||
bottom: "Eltwise1"
|
||||
top: "Convolution5"
|
||||
convolution_param {
|
||||
num_output: 64
|
||||
bias_term: true
|
||||
pad: 0
|
||||
kernel_size: 3
|
||||
stride: 1
|
||||
weight_filler {
|
||||
type: "msra"
|
||||
}
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "ReLU4"
|
||||
type: "ReLU"
|
||||
bottom: "Convolution5"
|
||||
top: "Convolution5"
|
||||
relu_param {
|
||||
negative_slope: 0.1
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Convolution6"
|
||||
type: "Convolution"
|
||||
bottom: "Convolution5"
|
||||
top: "Convolution6"
|
||||
convolution_param {
|
||||
num_output: 64
|
||||
bias_term: true
|
||||
pad: 0
|
||||
kernel_size: 3
|
||||
stride: 1
|
||||
weight_filler {
|
||||
type: "msra"
|
||||
}
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "ReLU5"
|
||||
type: "ReLU"
|
||||
bottom: "Convolution6"
|
||||
top: "Convolution6"
|
||||
relu_param {
|
||||
negative_slope: 0.1
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Crop2"
|
||||
type: "Crop"
|
||||
bottom: "Eltwise1"
|
||||
bottom: "Convolution6"
|
||||
top: "Crop2"
|
||||
crop_param {
|
||||
axis: 2
|
||||
offset: 2
|
||||
offset: 2
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Eltwise2"
|
||||
type: "Eltwise"
|
||||
bottom: "Convolution6"
|
||||
bottom: "Crop2"
|
||||
top: "Eltwise2"
|
||||
eltwise_param {
|
||||
operation: SUM
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Convolution7"
|
||||
type: "Convolution"
|
||||
bottom: "Eltwise2"
|
||||
top: "Convolution7"
|
||||
convolution_param {
|
||||
num_output: 128
|
||||
bias_term: true
|
||||
pad: 0
|
||||
kernel_size: 3
|
||||
stride: 1
|
||||
weight_filler {
|
||||
type: "msra"
|
||||
}
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "ReLU6"
|
||||
type: "ReLU"
|
||||
bottom: "Convolution7"
|
||||
top: "Convolution7"
|
||||
relu_param {
|
||||
negative_slope: 0.1
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Convolution8"
|
||||
type: "Convolution"
|
||||
bottom: "Convolution7"
|
||||
top: "Convolution8"
|
||||
convolution_param {
|
||||
num_output: 128
|
||||
bias_term: true
|
||||
pad: 0
|
||||
kernel_size: 3
|
||||
stride: 1
|
||||
weight_filler {
|
||||
type: "msra"
|
||||
}
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "ReLU7"
|
||||
type: "ReLU"
|
||||
bottom: "Convolution8"
|
||||
top: "Convolution8"
|
||||
relu_param {
|
||||
negative_slope: 0.1
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Convolution9"
|
||||
type: "Convolution"
|
||||
bottom: "Eltwise2"
|
||||
top: "Convolution9"
|
||||
convolution_param {
|
||||
num_output: 128
|
||||
bias_term: true
|
||||
pad: 0
|
||||
kernel_size: 1
|
||||
stride: 1
|
||||
weight_filler {
|
||||
type: "msra"
|
||||
}
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Crop3"
|
||||
type: "Crop"
|
||||
bottom: "Convolution9"
|
||||
bottom: "Convolution8"
|
||||
top: "Crop3"
|
||||
crop_param {
|
||||
axis: 2
|
||||
offset: 2
|
||||
offset: 2
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Eltwise3"
|
||||
type: "Eltwise"
|
||||
bottom: "Convolution8"
|
||||
bottom: "Crop3"
|
||||
top: "Eltwise3"
|
||||
eltwise_param {
|
||||
operation: SUM
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Convolution10"
|
||||
type: "Convolution"
|
||||
bottom: "Eltwise3"
|
||||
top: "Convolution10"
|
||||
convolution_param {
|
||||
num_output: 128
|
||||
bias_term: true
|
||||
pad: 0
|
||||
kernel_size: 3
|
||||
stride: 1
|
||||
weight_filler {
|
||||
type: "msra"
|
||||
}
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "ReLU8"
|
||||
type: "ReLU"
|
||||
bottom: "Convolution10"
|
||||
top: "Convolution10"
|
||||
relu_param {
|
||||
negative_slope: 0.1
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Convolution11"
|
||||
type: "Convolution"
|
||||
bottom: "Convolution10"
|
||||
top: "Convolution11"
|
||||
convolution_param {
|
||||
num_output: 128
|
||||
bias_term: true
|
||||
pad: 0
|
||||
kernel_size: 3
|
||||
stride: 1
|
||||
weight_filler {
|
||||
type: "msra"
|
||||
}
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "ReLU9"
|
||||
type: "ReLU"
|
||||
bottom: "Convolution11"
|
||||
top: "Convolution11"
|
||||
relu_param {
|
||||
negative_slope: 0.1
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Crop4"
|
||||
type: "Crop"
|
||||
bottom: "Eltwise3"
|
||||
bottom: "Convolution11"
|
||||
top: "Crop4"
|
||||
crop_param {
|
||||
axis: 2
|
||||
offset: 2
|
||||
offset: 2
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Eltwise4"
|
||||
type: "Eltwise"
|
||||
bottom: "Convolution11"
|
||||
bottom: "Crop4"
|
||||
top: "Eltwise4"
|
||||
eltwise_param {
|
||||
operation: SUM
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Convolution12"
|
||||
type: "Convolution"
|
||||
bottom: "Eltwise4"
|
||||
top: "Convolution12"
|
||||
convolution_param {
|
||||
num_output: 256
|
||||
bias_term: true
|
||||
pad: 0
|
||||
kernel_size: 3
|
||||
stride: 1
|
||||
weight_filler {
|
||||
type: "msra"
|
||||
}
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "ReLU10"
|
||||
type: "ReLU"
|
||||
bottom: "Convolution12"
|
||||
top: "Convolution12"
|
||||
relu_param {
|
||||
negative_slope: 0.1
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Convolution13"
|
||||
type: "Convolution"
|
||||
bottom: "Convolution12"
|
||||
top: "Convolution13"
|
||||
convolution_param {
|
||||
num_output: 256
|
||||
bias_term: true
|
||||
pad: 0
|
||||
kernel_size: 3
|
||||
stride: 1
|
||||
weight_filler {
|
||||
type: "msra"
|
||||
}
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "ReLU11"
|
||||
type: "ReLU"
|
||||
bottom: "Convolution13"
|
||||
top: "Convolution13"
|
||||
relu_param {
|
||||
negative_slope: 0.1
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Convolution14"
|
||||
type: "Convolution"
|
||||
bottom: "Eltwise4"
|
||||
top: "Convolution14"
|
||||
convolution_param {
|
||||
num_output: 256
|
||||
bias_term: true
|
||||
pad: 0
|
||||
kernel_size: 1
|
||||
stride: 1
|
||||
weight_filler {
|
||||
type: "msra"
|
||||
}
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Crop5"
|
||||
type: "Crop"
|
||||
bottom: "Convolution14"
|
||||
bottom: "Convolution13"
|
||||
top: "Crop5"
|
||||
crop_param {
|
||||
axis: 2
|
||||
offset: 2
|
||||
offset: 2
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Eltwise5"
|
||||
type: "Eltwise"
|
||||
bottom: "Convolution13"
|
||||
bottom: "Crop5"
|
||||
top: "Eltwise5"
|
||||
eltwise_param {
|
||||
operation: SUM
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Convolution15"
|
||||
type: "Convolution"
|
||||
bottom: "Eltwise5"
|
||||
top: "Convolution15"
|
||||
convolution_param {
|
||||
num_output: 256
|
||||
bias_term: true
|
||||
pad: 0
|
||||
kernel_size: 3
|
||||
stride: 1
|
||||
weight_filler {
|
||||
type: "msra"
|
||||
}
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "ReLU12"
|
||||
type: "ReLU"
|
||||
bottom: "Convolution15"
|
||||
top: "Convolution15"
|
||||
relu_param {
|
||||
negative_slope: 0.1
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Convolution16"
|
||||
type: "Convolution"
|
||||
bottom: "Convolution15"
|
||||
top: "Convolution16"
|
||||
convolution_param {
|
||||
num_output: 256
|
||||
bias_term: true
|
||||
pad: 0
|
||||
kernel_size: 3
|
||||
stride: 1
|
||||
weight_filler {
|
||||
type: "msra"
|
||||
}
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "ReLU13"
|
||||
type: "ReLU"
|
||||
bottom: "Convolution16"
|
||||
top: "Convolution16"
|
||||
relu_param {
|
||||
negative_slope: 0.1
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Crop6"
|
||||
type: "Crop"
|
||||
bottom: "Eltwise5"
|
||||
bottom: "Convolution16"
|
||||
top: "Crop6"
|
||||
crop_param {
|
||||
axis: 2
|
||||
offset: 2
|
||||
offset: 2
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Eltwise6"
|
||||
type: "Eltwise"
|
||||
bottom: "Convolution16"
|
||||
bottom: "Crop6"
|
||||
top: "Eltwise6"
|
||||
eltwise_param {
|
||||
operation: SUM
|
||||
}
|
||||
}
|
||||
layer {
|
||||
name: "Deconvolution1"
|
||||
type: "Deconvolution"
|
||||
bottom: "Eltwise6"
|
||||
top: "Deconvolution1"
|
||||
convolution_param {
|
||||
num_output: 3
|
||||
pad: 3
|
||||
kernel_size: 4
|
||||
stride: 2
|
||||
}
|
||||
}
|
|
@ -22,7 +22,6 @@ local function includes(s, a)
|
|||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function get_bias(mod)
|
||||
if mod.bias then
|
||||
return mod.bias:float()
|
||||
|
@ -31,20 +30,18 @@ local function get_bias(mod)
|
|||
return torch.FloatTensor(mod.nOutputPlane):zero()
|
||||
end
|
||||
end
|
||||
local function export(model, output)
|
||||
local function export_weight(jmodules, seq)
|
||||
local targets = {"nn.SpatialConvolutionMM",
|
||||
"cudnn.SpatialConvolution",
|
||||
"nn.SpatialFullConvolution",
|
||||
"cudnn.SpatialFullConvolution"
|
||||
}
|
||||
local jmodules = {}
|
||||
local model_config = meta_data(model)
|
||||
local first_layer = true
|
||||
|
||||
for k = 1, #model.modules do
|
||||
local mod = model.modules[k]
|
||||
for k = 1, #seq.modules do
|
||||
local mod = seq.modules[k]
|
||||
local name = torch.typename(mod)
|
||||
if includes(name, targets) then
|
||||
if name == "nn.Sequential" or name == "nn.ConcatTable" then
|
||||
export_weight(jmodules, mod)
|
||||
elseif includes(name, targets) then
|
||||
local weight = mod.weight:float()
|
||||
if name:match("FullConvolution") then
|
||||
weight = torch.totable(weight:reshape(mod.nInputPlane, mod.nOutputPlane, mod.kH, mod.kW))
|
||||
|
@ -71,6 +68,14 @@ local function export(model, output)
|
|||
table.insert(jmodules, jmod)
|
||||
end
|
||||
end
|
||||
end
|
||||
local function export(model, output)
|
||||
local jmodules = {}
|
||||
local model_config = meta_data(model)
|
||||
local first_layer = true
|
||||
|
||||
export_weight(jmodules, model)
|
||||
|
||||
local fp = io.open(output, "w")
|
||||
if not fp then
|
||||
error("IO Error: " .. output)
|
||||
|
|
Loading…
Reference in a new issue