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

add contrib package #5499

Merged
merged 2 commits into from Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions example/rcnn/README.md
Expand Up @@ -58,9 +58,6 @@ See if `bash script/additional_deps.sh` will do the following for you.
* Suppose `HOME` represents where this file is located. All commands, unless stated otherwise, should be started from `HOME`.
Executing scripts in `script` must also be from `HOME`.
* Install python package `cython easydict matplotlib scikit-image`.
* Install MXNet with additional operators.
If you know Makefile, change `EXTRA_OPERATORS` in `config.mk` to include the `example/rcnn/operator` folder.
If not, copy all files in `operator` to `../../src/operator` (namely `mxnet/src/operator`).
* Install MXNet Python Interface. Open `python` type `import mxnet` to confirm.
* Run `make` in `HOME`.

Expand Down
4 changes: 2 additions & 2 deletions example/rcnn/rcnn/symbol/symbol_resnet.py
Expand Up @@ -96,7 +96,7 @@ def get_resnet_train(num_classes=config.NUM_CLASSES, num_anchors=config.NUM_ANCH
rpn_cls_act_reshape = mx.symbol.Reshape(
data=rpn_cls_act, shape=(0, 2 * num_anchors, -1, 0), name='rpn_cls_act_reshape')
if config.TRAIN.CXX_PROPOSAL:
rois = mx.symbol.Proposal(
rois = mx.symbol.contrib.Proposal(
cls_prob=rpn_cls_act_reshape, bbox_pred=rpn_bbox_pred, im_info=im_info, name='rois',
feature_stride=config.RPN_FEAT_STRIDE, scales=tuple(config.ANCHOR_SCALES), ratios=tuple(config.ANCHOR_RATIOS),
rpn_pre_nms_top_n=config.TRAIN.RPN_PRE_NMS_TOP_N, rpn_post_nms_top_n=config.TRAIN.RPN_POST_NMS_TOP_N,
Expand Down Expand Up @@ -172,7 +172,7 @@ def get_resnet_test(num_classes=config.NUM_CLASSES, num_anchors=config.NUM_ANCHO
rpn_cls_prob_reshape = mx.symbol.Reshape(
data=rpn_cls_prob, shape=(0, 2 * num_anchors, -1, 0), name='rpn_cls_prob_reshape')
if config.TEST.CXX_PROPOSAL:
rois = mx.symbol.Proposal(
rois = mx.symbol.contrib.Proposal(
cls_prob=rpn_cls_prob_reshape, bbox_pred=rpn_bbox_pred, im_info=im_info, name='rois',
feature_stride=config.RPN_FEAT_STRIDE, scales=tuple(config.ANCHOR_SCALES), ratios=tuple(config.ANCHOR_RATIOS),
rpn_pre_nms_top_n=config.TEST.RPN_PRE_NMS_TOP_N, rpn_post_nms_top_n=config.TEST.RPN_POST_NMS_TOP_N,
Expand Down
6 changes: 3 additions & 3 deletions example/rcnn/rcnn/symbol/symbol_vgg.py
Expand Up @@ -225,7 +225,7 @@ def get_vgg_rpn_test(num_anchors=config.NUM_ANCHORS):
rpn_cls_prob_reshape = mx.symbol.Reshape(
data=rpn_cls_prob, shape=(0, 2 * num_anchors, -1, 0), name='rpn_cls_prob_reshape')
if config.TEST.CXX_PROPOSAL:
group = mx.symbol.Proposal(
group = mx.symbol.contrib.Proposal(
cls_prob=rpn_cls_prob_reshape, bbox_pred=rpn_bbox_pred, im_info=im_info, name='rois', output_score=True,
feature_stride=config.RPN_FEAT_STRIDE, scales=tuple(config.ANCHOR_SCALES), ratios=tuple(config.ANCHOR_RATIOS),
rpn_pre_nms_top_n=config.TEST.PROPOSAL_PRE_NMS_TOP_N, rpn_post_nms_top_n=config.TEST.PROPOSAL_POST_NMS_TOP_N,
Expand Down Expand Up @@ -273,7 +273,7 @@ def get_vgg_test(num_classes=config.NUM_CLASSES, num_anchors=config.NUM_ANCHORS)
rpn_cls_prob_reshape = mx.symbol.Reshape(
data=rpn_cls_prob, shape=(0, 2 * num_anchors, -1, 0), name='rpn_cls_prob_reshape')
if config.TEST.CXX_PROPOSAL:
rois = mx.symbol.Proposal(
rois = mx.symbol.contrib.Proposal(
cls_prob=rpn_cls_prob_reshape, bbox_pred=rpn_bbox_pred, im_info=im_info, name='rois',
feature_stride=config.RPN_FEAT_STRIDE, scales=tuple(config.ANCHOR_SCALES), ratios=tuple(config.ANCHOR_RATIOS),
rpn_pre_nms_top_n=config.TEST.RPN_PRE_NMS_TOP_N, rpn_post_nms_top_n=config.TEST.RPN_POST_NMS_TOP_N,
Expand Down Expand Up @@ -356,7 +356,7 @@ def get_vgg_train(num_classes=config.NUM_CLASSES, num_anchors=config.NUM_ANCHORS
rpn_cls_act_reshape = mx.symbol.Reshape(
data=rpn_cls_act, shape=(0, 2 * num_anchors, -1, 0), name='rpn_cls_act_reshape')
if config.TRAIN.CXX_PROPOSAL:
rois = mx.symbol.Proposal(
rois = mx.symbol.contrib.Proposal(
cls_prob=rpn_cls_act_reshape, bbox_pred=rpn_bbox_pred, im_info=im_info, name='rois',
feature_stride=config.RPN_FEAT_STRIDE, scales=tuple(config.ANCHOR_SCALES), ratios=tuple(config.ANCHOR_RATIOS),
rpn_pre_nms_top_n=config.TRAIN.RPN_PRE_NMS_TOP_N, rpn_post_nms_top_n=config.TRAIN.RPN_POST_NMS_TOP_N,
Expand Down
6 changes: 1 addition & 5 deletions example/ssd/README.md
Expand Up @@ -45,14 +45,10 @@ sudo apt-get install python-opencv python-matplotlib python-numpy
sudo pip install easydict
```

* Build MXNet: Follow the official instructions, make sure the extra operators for this example is enabled
* Build MXNet: Follow the official instructions
```
# for Ubuntu/Debian
cp make/config.mk ./config.mk
# modify it if with vim or whatever editor
EXTRA_OPERATORS = example/ssd/operator
# or add a line if you have other EXTRA_OPERATORS directory
EXTRA_OPERATORS += example/ssd/operator
```
Remember to enable CUDA if you want to be able to train, since CPU training is
insanely slow. Using CUDNN is optional.
Expand Down
2 changes: 1 addition & 1 deletion example/ssd/symbol/common.py
Expand Up @@ -161,7 +161,7 @@ def multibox_layer(from_layers, num_classes, sizes=[.2, .95],
cls_pred_layers.append(cls_pred)

# create anchor generation layer
anchors = mx.symbol.MultiBoxPrior(from_layer, sizes=size_str, ratios=ratio_str, \
anchors = mx.symbol.contrib.MultiBoxPrior(from_layer, sizes=size_str, ratios=ratio_str, \
clip=clip, name="{}_anchors".format(from_name))
anchors = mx.symbol.Flatten(data=anchors)
anchor_layers.append(anchors)
Expand Down
4 changes: 2 additions & 2 deletions example/ssd/symbol/symbol_vgg16_reduced.py
Expand Up @@ -118,7 +118,7 @@ def get_symbol_train(num_classes=20):
num_classes, sizes=sizes, ratios=ratios, normalization=normalizations, \
num_channels=num_channels, clip=True, interm_layer=0)

tmp = mx.symbol.MultiBoxTarget(
tmp = mx.symbol.contrib.MultiBoxTarget(
*[anchor_boxes, label, cls_preds], overlap_threshold=.5, \
ignore_label=-1, negative_mining_ratio=3, minimum_negative_samples=0, \
negative_mining_thresh=.5, variances=(0.1, 0.1, 0.2, 0.2),
Expand Down Expand Up @@ -170,7 +170,7 @@ def get_symbol(num_classes=20, nms_thresh=0.5, force_suppress=True):
name='cls_prob')
# group output
# out = mx.symbol.Group([loc_preds, cls_preds, anchor_boxes])
out = mx.symbol.MultiBoxDetection(*[cls_prob, loc_preds, anchor_boxes], \
out = mx.symbol.contrib.MultiBoxDetection(*[cls_prob, loc_preds, anchor_boxes], \
name="detection", nms_threshold=nms_thresh, force_suppress=force_suppress,
variances=(0.1, 0.1, 0.2, 0.2))
return out
1 change: 1 addition & 0 deletions python/mxnet/__init__.py
Expand Up @@ -6,6 +6,7 @@
from .context import Context, current_context, cpu, gpu
from .base import MXNetError
from . import base
from . import contrib
from . import ndarray
from . import name
# use mx.sym as short for symbol
Expand Down
7 changes: 6 additions & 1 deletion python/mxnet/_ctypes/ndarray.py
Expand Up @@ -166,11 +166,16 @@ def _init_ndarray_module(ndarray_class, root_namespace):

module_obj = _sys.modules["%s.ndarray" % root_namespace]
module_internal = _sys.modules["%s._ndarray_internal" % root_namespace]
module_contrib = _sys.modules["%s.contrib.ndarray" % root_namespace]
for name in op_names:
hdl = OpHandle()
check_call(_LIB.NNGetOpHandle(c_str(name), ctypes.byref(hdl)))
function = _make_ndarray_function(hdl, name)
if function.__name__.startswith('_'):
if function.__name__.startswith('_contrib_'):
function.__name__ = function.__name__[9:]
function.__module__ = 'mxnet.contrib.ndarray'
setattr(module_contrib, function.__name__, function)
elif function.__name__.startswith('_'):
setattr(module_internal, function.__name__, function)
else:
setattr(module_obj, function.__name__, function)
7 changes: 6 additions & 1 deletion python/mxnet/_ctypes/symbol.py
Expand Up @@ -211,11 +211,16 @@ def _init_symbol_module(symbol_class, root_namespace):

module_obj = sys.modules["%s.symbol" % root_namespace]
module_internal = sys.modules["%s._symbol_internal" % root_namespace]
module_contrib = sys.modules["%s.contrib.symbol" % root_namespace]
for name in op_names:
hdl = OpHandle()
check_call(_LIB.NNGetOpHandle(c_str(name), ctypes.byref(hdl)))
function = _make_atomic_symbol_function(hdl, name)
if function.__name__.startswith('_'):
if function.__name__.startswith('_contrib_'):
function.__name__ = function.__name__[9:]
function.__module__ = 'mxnet.contrib.symbol'
setattr(module_contrib, function.__name__, function)
elif function.__name__.startswith('_'):
setattr(module_internal, function.__name__, function)
else:
setattr(module_obj, function.__name__, function)
8 changes: 8 additions & 0 deletions python/mxnet/contrib/__init__.py
@@ -0,0 +1,8 @@
# coding: utf-8
"""Experimental contributions"""

from . import symbol
from . import ndarray

from . import symbol as sym
from . import ndarray as nd
2 changes: 2 additions & 0 deletions python/mxnet/contrib/ndarray.py
@@ -0,0 +1,2 @@
# coding: utf-8
"""NDArray namespace used to register contrib functions"""
2 changes: 2 additions & 0 deletions python/mxnet/contrib/symbol.py
@@ -0,0 +1,2 @@
# coding: utf-8
"""Symbol namespace used to register contrib functions"""
2 changes: 1 addition & 1 deletion python/setup.py
Expand Up @@ -71,7 +71,7 @@ def config_cython():
zip_safe=False,
packages=[
'mxnet', 'mxnet.module', 'mxnet._ctypes', 'mxnet.rnn',
'mxnet._cy2', 'mxnet._cy3', 'mxnet.notebook'
'mxnet._cy2', 'mxnet._cy3', 'mxnet.notebook', 'mxnet.contrib'
],
data_files=[('mxnet', [LIB_PATH[0]])],
url='https://github.com/dmlc/mxnet',
Expand Down
Expand Up @@ -4,8 +4,8 @@
* \brief post-process multibox detection predictions
* \author Joshua Zhang
*/
#ifndef MXNET_OPERATOR_MULTIBOX_DETECTION_INL_H_
#define MXNET_OPERATOR_MULTIBOX_DETECTION_INL_H_
#ifndef MXNET_OPERATOR_CONTRIB_MULTIBOX_DETECTION_INL_H_
#define MXNET_OPERATOR_CONTRIB_MULTIBOX_DETECTION_INL_H_
#include <dmlc/logging.h>
#include <dmlc/parameter.h>
#include <mxnet/operator.h>
Expand All @@ -15,7 +15,7 @@
#include <string>
#include <utility>
#include <valarray>
#include "./operator_common.h"
#include "../operator_common.h"

namespace mxnet {
namespace op {
Expand Down Expand Up @@ -216,7 +216,7 @@ class MultiBoxDetectionProp : public OperatorProperty {
}

std::string TypeString() const override {
return "MultiBoxDetection";
return "_contrib_MultiBoxDetection";
}

std::vector<ResourceRequest> ForwardResource(
Expand All @@ -240,4 +240,4 @@ class MultiBoxDetectionProp : public OperatorProperty {
} // namespace op
} // namespace mxnet

#endif // MXNET_OPERATOR_MULTIBOX_DETECTION_INL_H_
#endif // MXNET_OPERATOR_CONTRIB_MULTIBOX_DETECTION_INL_H_
Expand Up @@ -165,7 +165,7 @@ Operator* MultiBoxDetectionProp::CreateOperatorEx(Context ctx,
}

DMLC_REGISTER_PARAMETER(MultiBoxDetectionParam);
MXNET_REGISTER_OP_PROPERTY(MultiBoxDetection, MultiBoxDetectionProp)
MXNET_REGISTER_OP_PROPERTY(_contrib_MultiBoxDetection, MultiBoxDetectionProp)
.describe("Convert multibox detection predictions.")
.add_argument("cls_prob", "Symbol", "Class probabilities.")
.add_argument("loc_pred", "Symbol", "Location regression predictions.")
Expand Down
Expand Up @@ -4,8 +4,8 @@
* \brief generate multibox prior boxes
* \author Joshua Zhang
*/
#ifndef MXNET_OPERATOR_MULTIBOX_PRIOR_INL_H_
#define MXNET_OPERATOR_MULTIBOX_PRIOR_INL_H_
#ifndef MXNET_OPERATOR_CONTRIB_MULTIBOX_PRIOR_INL_H_
#define MXNET_OPERATOR_CONTRIB_MULTIBOX_PRIOR_INL_H_
#include <dmlc/logging.h>
#include <dmlc/parameter.h>
#include <mxnet/operator.h>
Expand All @@ -15,7 +15,7 @@
#include <string>
#include <utility>
#include <valarray>
#include "./operator_common.h"
#include "../operator_common.h"


namespace mxnet {
Expand Down Expand Up @@ -228,7 +228,7 @@ class MultiBoxPriorProp: public OperatorProperty {
}

std::string TypeString() const override {
return "MultiBoxPrior";
return "_contrib_MultiBoxPrior";
}

Operator* CreateOperator(Context ctx) const override {
Expand All @@ -247,4 +247,4 @@ class MultiBoxPriorProp: public OperatorProperty {
} // namespace op
} // namespace mxnet

#endif // MXNET_OPERATOR_MULTIBOX_PRIOR_INL_H_
#endif // MXNET_OPERATOR_CONTRIB_MULTIBOX_PRIOR_INL_H_
Expand Up @@ -73,7 +73,7 @@ Operator* MultiBoxPriorProp::CreateOperatorEx(Context ctx, std::vector<TShape> *

DMLC_REGISTER_PARAMETER(MultiBoxPriorParam);

MXNET_REGISTER_OP_PROPERTY(MultiBoxPrior, MultiBoxPriorProp)
MXNET_REGISTER_OP_PROPERTY(_contrib_MultiBoxPrior, MultiBoxPriorProp)
.add_argument("data", "Symbol", "Input data.")
.add_arguments(MultiBoxPriorParam::__FIELDS__())
.describe("Generate prior(anchor) boxes from data, sizes and ratios.");
Expand Down
Expand Up @@ -4,8 +4,8 @@
* \brief
* \author Joshua Zhang
*/
#ifndef MXNET_OPERATOR_MULTIBOX_TARGET_INL_H_
#define MXNET_OPERATOR_MULTIBOX_TARGET_INL_H_
#ifndef MXNET_OPERATOR_CONTRIB_MULTIBOX_TARGET_INL_H_
#define MXNET_OPERATOR_CONTRIB_MULTIBOX_TARGET_INL_H_
#include <dmlc/logging.h>
#include <dmlc/parameter.h>
#include <mxnet/operator.h>
Expand All @@ -15,8 +15,8 @@
#include <string>
#include <utility>
#include <valarray>
#include "./operator_common.h"
#include "./mshadow_op.h"
#include "../operator_common.h"
#include "../mshadow_op.h"

namespace mxnet {
namespace op {
Expand Down Expand Up @@ -294,7 +294,7 @@ class MultiBoxTargetProp : public OperatorProperty {
}

std::string TypeString() const override {
return "MultiBoxTarget";
return "_contrib_MultiBoxTarget";
}

// decalre dependency and inplace optimization options
Expand Down Expand Up @@ -326,4 +326,4 @@ class MultiBoxTargetProp : public OperatorProperty {
} // namespace op
} // namespace mxnet

#endif // MXNET_OPERATOR_MULTIBOX_TARGET_INL_H_
#endif // MXNET_OPERATOR_CONTRIB_MULTIBOX_TARGET_INL_H_
Expand Up @@ -4,9 +4,9 @@
* \brief MultiBoxTarget op
* \author Joshua Zhang
*/
#include "./multibox_target-inl.h"
#include "./mshadow_op.h"
#include <algorithm>
#include "./multibox_target-inl.h"
#include "../mshadow_op.h"

namespace mshadow {
template<typename DType>
Expand Down Expand Up @@ -281,7 +281,7 @@ Operator* MultiBoxTargetProp::CreateOperatorEx(Context ctx, std::vector<TShape>
}

DMLC_REGISTER_PARAMETER(MultiBoxTargetParam);
MXNET_REGISTER_OP_PROPERTY(MultiBoxTarget, MultiBoxTargetProp)
MXNET_REGISTER_OP_PROPERTY(_contrib_MultiBoxTarget, MultiBoxTargetProp)
.describe("Compute Multibox training targets")
.add_argument("anchor", "Symbol", "Generated anchor boxes.")
.add_argument("label", "Symbol", "Object detection labels.")
Expand Down