本文整理汇总了Python中mmdnn.conversion.caffe.common_graph.Node类的典型用法代码示例。如果您正苦于以下问题:Python Node类的具体用法?Python Node怎么用?Python Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: map_crop
def map_crop(cls, node):
offset = node.parameters.offset
if offset:
kwargs = {'offset': int(node.parameters.offset[0])}
return Node.create('crop', **kwargs)
else:
return Node.create('crop')
示例2: map_convolution
def map_convolution(cls, node):
parent, _ = node.get_only_parent()
kwargs = cls.get_kernel_params(node, parent.output_shape)
kwargs['kernel_shape'] = [node.kernel_parameters.k_h, node.kernel_parameters.k_w, parent.output_shape.channels, node.parameters.num_output]
kwargs['use_bias'] = node.parameters.bias_term
kwargs['group'] = node.parameters.group
return Node.create('Conv', **kwargs)
示例3: map_scale
def map_scale(cls, node):
raise NotImplementedError
# TODO: The gamma parameter has to be set (in node.data?) and this should work.
# Also, mean should be set to 0, and var to 1, just to be safe.
scale_value = float(node.parameters.filler.value)
kwargs = {'scale' : True, 'bias' : False, 'gamma' : scale_value, 'epsilon': 0}
return Node.create('BatchNorm', **kwargs)
示例4: map_eltwise
def map_eltwise(cls, node):
operations = {0: 'Mul', 1: 'Add', 2: 'Max'}
op_code = node.parameters.operation
try:
return Node.create(operations[op_code])
except KeyError:
raise ConversionError('Unknown elementwise operation: {}'.format(op_code))
示例5: map_deconvolution
def map_deconvolution(cls, node):
raise NotImplementedError()
parent, _ = node.get_only_parent()
kwargs = cls.get_kernel_params(node, parent.output_shape)
kwargs['kernel_shape'] = [node.kernel_parameters.k_h, node.kernel_parameters.k_w, parent.output_shape.channels, node.parameters.num_output]
kwargs['group'] = node.parameters.group
return Node.create('deconv', **kwargs)
示例6: _add_flatten_layer
def _add_flatten_layer(cls, node):
shape = TensorShape()
dim = shape.dim.add()
dim.size = -1
dim = shape.dim.add()
dim.size = 1
for i in node.output_shape[1:]:
dim.size *= i
kwargs = {'_output_shapes' : [shape]}
return Node.create('Flatten', **kwargs)
示例7: map_pooling
def map_pooling(cls, node):
parent, _ = node.get_only_parent()
kwargs = cls.get_kernel_params(node, parent.output_shape)
if node.parameters.pool == 0:
kwargs['pooling_type'] = 'MAX'
elif node.parameters.pool == 1:
kwargs['pooling_type'] = 'AVG'
else:
# Stochastic pooling, for instance.
raise ConversionError('Unsupported pooling type.')
cls._convert_output_shape(kwargs, node)
return Node.create('Pool', **kwargs)
示例8: map_deconvolution
def map_deconvolution(cls, node):
parent, _ = node.get_only_parent()
kwargs = cls.get_kernel_params(node, parent.output_shape)
kwargs['kernel_shape'] = [node.kernel_parameters.k_h, node.kernel_parameters.k_w, node.parameters.num_output, parent.output_shape.channels]
kwargs['use_bias'] = node.parameters.bias_term
if node.parameters.dilation:
dilation = node.parameters.dilation[0]
if dilation != 1:
kwargs['dilations'] = [1, dilation, dilation, 1]
kwargs['group'] = node.parameters.group
return Node.create('ConvTranspose', **kwargs)
示例9: map_inner_product
def map_inner_product(cls, node):
#TODO: Axis
assert node.parameters.axis == 1
#TODO: Unbiased
kwargs = {'use_bias' : node.parameters.bias_term, 'units' : node.parameters.num_output}
# check if need the Flatten layer
parent, _ = node.get_only_parent()
ret = []
# if parent.output_shape.height > 1 or parent.output_shape.width > 1:
ret.append(cls._add_flatten_layer(parent))
ret.append(Node.create('FullyConnected', **kwargs))
return ret
示例10: map_data
def map_data(cls, node):
# TODO: We need to identify whether this is 4D image data, otherwise we shouldn't change the dimension order
shape = TensorShape()
dim = shape.dim.add()
dim.size = -1
for i in node.output_shape[2:]:
dim = shape.dim.add()
dim.size = i
dim = shape.dim.add()
dim.size = node.output_shape.channels
kwargs = {'shape': shape} # Ignore the dimension of batch size
cls._convert_output_shape(kwargs, node)
return Node.create('DataInput', **kwargs)
示例11: map_tanh
def map_tanh(cls, node):
return Node.create('Tanh')
示例12: map_reshape
def map_reshape(cls, node):
kwargs = {'shape' : [dim for dim in node.output_shape]}
cls._convert_output_shape(kwargs, node)
return Node.create('Reshape', **kwargs)
示例13: map_abs_val
def map_abs_val(cls, node):
return Node.create('Abs')
示例14: map_batch_norm
def map_batch_norm(cls, node):
kwargs = {'scale' : len(node.data) >= 3, 'bias' : len(node.data) == 4}
epsilon = node.parameters.eps
kwargs['epsilon'] = epsilon
cls._convert_output_shape(kwargs, node)
return Node.create('BatchNorm', **kwargs)
示例15: map_flatten
def map_flatten(cls, node):
return Node.create('Flatten')