forked from apache/mxnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* MobileNetV2 * add mobilenetv2 to gluon vision model zoo. * code reformat use autopep8 and isort. fix pylint style check error. add docstring, disable some check. delete duplicate code in example. * change ver to version. * use exist helper. * model code refactor. * fix line too long. * remove invalid name option. * merge output operations. * change variables name * fix line too long. * s -> stride * add output name_scope * remove relu in first conv2d. * change block name from BottleNeck to LinearBottleneck. * resolve conflict * fix parameter name. * correct strides * add mobilenetv2 to unittest. * use autopep8 to reformat code. * add mobilenetv2 symbols to gluon.vision * add relu in 1st conv2d. * code refactor by using helpers. * split mobilenet v1 and v2 apis.
- Loading branch information
Showing
5 changed files
with
303 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
# -*- coding:utf-8 -*- | ||
''' | ||
MobileNetV2, implemented in Gluon. | ||
Reference: | ||
Inverted Residuals and Linear Bottlenecks: | ||
Mobile Networks for Classification, Detection and Segmentation | ||
https://arxiv.org/abs/1801.04381 | ||
''' | ||
__author__ = 'dwSun' | ||
__date__ = '18/1/31' | ||
|
||
import mxnet as mx | ||
|
||
from mxnet.gluon.model_zoo.vision.mobilenet import MobileNetV2 | ||
|
||
|
||
__all__ = ['MobileNetV2', 'get_symbol'] | ||
|
||
|
||
def get_symbol(num_classes=1000, multiplier=1.0, ctx=mx.cpu(), **kwargs): | ||
r"""MobileNetV2 model from the | ||
`"Inverted Residuals and Linear Bottlenecks: | ||
Mobile Networks for Classification, Detection and Segmentation" | ||
<https://arxiv.org/abs/1801.04381>`_ paper. | ||
Parameters | ||
---------- | ||
num_classes : int, default 1000 | ||
Number of classes for the output layer. | ||
multiplier : float, default 1.0 | ||
The width multiplier for controling the model size. The actual number of channels | ||
is equal to the original channel size multiplied by this multiplier. | ||
ctx : Context, default CPU | ||
The context in which to initialize the model weights. | ||
""" | ||
net = MobileNetV2(multiplier=multiplier, classes=num_classes, **kwargs) | ||
net.initialize(ctx=ctx, init=mx.init.Xavier()) | ||
net.hybridize() | ||
|
||
data = mx.sym.var('data') | ||
out = net(data) | ||
sym = mx.sym.SoftmaxOutput(out, name='softmax') | ||
return sym | ||
|
||
|
||
def plot_net(): | ||
""" | ||
Visualize the network. | ||
""" | ||
sym = get_symbol(1000, prefix='mob_') | ||
|
||
# plot network graph | ||
mx.viz.plot_network(sym, shape={'data': (8, 3, 224, 224)}, | ||
node_attrs={'shape': 'oval', 'fixedsize': 'fasl==false'}).view() | ||
|
||
|
||
if __name__ == '__main__': | ||
plot_net() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.