Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Add more support for mxnet_to_coreml #14222

Merged
merged 6 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion tools/coreml/converter/_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,39 @@ def convert_activation(net, node, module, builder):
output_name = output_name)


def convert_leakyrelu(net, node, module, builder):
szha marked this conversation as resolved.
Show resolved Hide resolved
"""Convert an leakyrelu layer from mxnet to coreml.
szha marked this conversation as resolved.
Show resolved Hide resolved

Parameters
----------
network: net
A mxnet network object.

layer: node
Node to convert.

module: module
An module for MXNet

builder: NeuralNetworkBuilder
A neural network builder object.
"""
input_name, output_name = _get_input_output_name(net, node)
szha marked this conversation as resolved.
Show resolved Hide resolved
name = node['name']
inputs = node['inputs']
args, _ = module.get_params()
mx_non_linearity = _get_attrs(node)['act_type']
if mx_non_linearity == 'prelu':
non_linearity = 'PRELU'
params = args[_get_node_name(net, inputs[1][0])].asnumpy()
else:
raise TypeError('Unknown activation type %s' % mx_non_linearity)
builder.add_activation(name = name,
non_linearity = non_linearity,
input_name = input_name,
output_name = output_name,
params = params)

def convert_elementwise_add(net, node, module, builder):
"""Convert an elementwise add layer from mxnet to coreml.

Expand Down Expand Up @@ -335,6 +368,7 @@ def convert_convolution(net, node, module, builder):
border_mode = "valid"

n_filters = int(param['num_filter'])
n_groups = int(param['num_group'])

W = args[_get_node_name(net, inputs[1][0])].asnumpy()
if has_bias:
Expand All @@ -361,7 +395,7 @@ def convert_convolution(net, node, module, builder):
stride_height=stride_height,
stride_width=stride_width,
border_mode=border_mode,
groups=1,
groups=n_groups,
szha marked this conversation as resolved.
Show resolved Hide resolved
W=W,
b=Wb,
has_bias=has_bias,
Expand Down
3 changes: 3 additions & 0 deletions tools/coreml/converter/_mxnet_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@
'elemwise_add' : _layers.convert_elementwise_add,
'Reshape' : _layers.convert_reshape,
'Deconvolution' : _layers.convert_deconvolution,
'LeakyReLU' : _layers.convert_leakyrelu,
}

_MXNET_SKIP_LAYERS = [
'_MulScalar',
'Dropout',
'_minus_scalar',
'_mul_scalar',
]

def _mxnet_remove_batch(input_data):
Expand Down