提交 7505c65d 编写于 作者: S SunAhong1993

for squeezenet

上级 a829051a
......@@ -60,9 +60,9 @@ class CaffeResolver(object):
class CaffeGraphNode(GraphNode):
def __init__(self, layer, layer_name=None):
if layer_name is None:
super(CaffeGraphNode, self).__init__(layer, layer.name)
super(CaffeGraphNode, self).__init__(layer, layer.name.replace('/', '_'))
else:
super(CaffeGraphNode, self).__init__(layer, layer_name)
super(CaffeGraphNode, self).__init__(layer, layer_name.replace('/', '_'))
self.layer_type = layer.type
self.fluid_code = FluidCode()
......@@ -181,8 +181,8 @@ class CaffeGraph(Graph):
name)
input_node = self.node_map[input_node_name]
if len(input_node.layer.top) > 1:
idx = list(input_node.layer.top).index(node.layer.bottom[need])
name = input_node_name + ':' + str(idx)
need_idx = list(input_node.layer.top).index(node.layer.bottom[idx])
name = input_node_name + ':' + str(need_idx)
else:
name = input_node_name
return self.get_node(name, copy=copy)
......
......@@ -32,8 +32,8 @@ def get_params_w_h(params):
if not isinstance(getattr(params, 'pad'), int):
if len(params.pad) == 0:
pad_h = 1
pad_w = 1
pad_h = 0
pad_w = 0
elif len(params.pad) == 1:
pad_h = params.pad[0]
pad_w = params.pad[0]
......@@ -101,7 +101,6 @@ def get_filter_output_shape(i_h, i_w, params, round_func):
(kernel_h - 1) + 1)) / float(stride_h) + 1
o_w = (i_w + 2 * pad_w - (dila_w *
(kernel_w - 1) + 1)) / float(stride_w) + 1
return (int(round_func(o_h)), int(round_func(o_w)))
......@@ -111,6 +110,7 @@ def get_strided_kernel_output_shape(params, input_shape, round_func):
round_func)
has_c_o = hasattr(params, 'num_output')
c = params.num_output if has_c_o else input_shape[1]
return [[input_shape[0], c, o_h, o_w]]
......@@ -168,3 +168,14 @@ def shape_softmax(layer, input_shape):
def shape_input(layer, input_shape):
return [list(layer.input_param.shape[0].dim)]
def shape_concat(layer, input_shape):
params = layer.concat_param
axis = params.axis
output_shape = None
for shape in input_shape:
if output_shape is None:
output_shape = shape
else:
output_shape[axis] += shape[axis]
return [output_shape]
\ No newline at end of file
......@@ -106,11 +106,11 @@ class CaffeOpMapper(OpMapper):
raise ValueError('Unable to determine kernel parameter!')
return default
def get_kernel_parameters(self, kind, params):
def get_kernel_parameters(self, kind, params, kernel_default=[1, 1]):
assert kind in ['Convolution', 'Pooling', 'Deconvolution']
k_h = self.get_kernel_value(params.kernel_h, params.kernel_size, 0)
k_w = self.get_kernel_value(params.kernel_w, params.kernel_size, 1)
k_h = self.get_kernel_value(params.kernel_h, params.kernel_size, 0, kernel_default[0])
k_w = self.get_kernel_value(params.kernel_w, params.kernel_size, 1, kernel_default[1])
s_h = self.get_kernel_value(params.stride_h,
params.stride,
0,
......@@ -216,8 +216,13 @@ class CaffeOpMapper(OpMapper):
def Pooling(self, node):
params = node.layer.pooling_param
shape = node.input_shape[0]
global_pool = getattr(params, 'global_pooling', False)
kernel_default = [1, 1]
if global_pool:
kernel_default = [shape[2],shape[3]]
channel, kernel, stride, pad, dilation, group = self.get_kernel_parameters(
node.layer_type, params)
node.layer_type, params, kernel_default=kernel_default)
if params.pool == 0:
pool_type = 'max'
else:
......@@ -348,3 +353,55 @@ class CaffeOpMapper(OpMapper):
inputs=node,
output=node,
param_attr=attr)
def Slice(self, node):
assert len(
node.inputs) == 1, 'The count of Slice node\'s input is not 1.'
input = self.graph.get_bottom_node(node, idx=0, copy=True)
params = node.layer.slice_param
axis = params.axis
points = list(params.slice_point)
shape = node.input_shape[0]
count = shape[axis]
sections = []
idx = 0
for p in points:
if idx == 0:
sections.append(p - 0)
elif idx == len(points) - 1:
sections.append(count - p)
else:
sections.append(points[idx + 1] - p)
idx += 1
attr = {
'dim': axis,
'num_or_sections': sections,
'name': string(node.layer_name + '_slice')
}
node.fluid_code.add_layer("split",
inputs=input,
output=node,
param_attr=attr)
def Concat(self, node):
assert len(
node.inputs) > 1, 'The count of Concat node\'s input is not more than 1.'
inputs = []
for i in range(len(node.inputs)):
input = self.graph.get_bottom_node(node, idx=i, copy=True)
inputs.append(input)
params = node.layer.concat_param
axis = params.axis
attr = {
'axis': axis,
'name': string(node.layer_name + '_concat')
}
node.fluid_code.add_layer("concat",
inputs=inputs,
output=node,
param_attr=attr)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册