You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by jx...@apache.org on 2017/11/21 00:31:45 UTC

[incubator-mxnet] branch vision updated (e997559 -> db2f1f4)

This is an automated email from the ASF dual-hosted git repository.

jxie pushed a change to branch vision
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git.


 discard e997559  [Image OP] Normalize (#8731)
    omit e5de497  image to_tensor (#8691)
    omit 37a5cf0  Add Gluon data transform (#8672)
    omit 06fb10c  fix image_random compile (#8665)
    omit 59b7f12  [WIP][vision]fix (#8657)
    omit f7faf9b  add stub (#8650)
    omit 5c2f859  [WIP]]Vision (#8649)
    omit c1de00a  [WIP]Image Augmenter (#8633)
     add 710bf4e  check_format of sparse ndrray (#8259)
     add 25ef9bb  Fix HybridLambda repr (#8565)
     add e27f054  fix custom op error when using auxiliary states (#8637)
     add ca4b683  Imperative bulk execution (#8520)
     add 079fc45  add nightly test for dist-device-sync (#8597)
     add 6b69608  fix bug in TryCrop() (#8644)
     add 938eda9  Support sparse for custom python operators (#8620)
     add c8f7dce  sparse embedding operator, gpu implementation (#8647)
     add 85d4bd2  multi processing and fork fix (#8677)
     add 4d05bff  ctypes speed improvement (#8642)
     add 3107326  Refreshed branch quick_pr (#8643)
     add 33698ea  Fix sparse dot test failure due to launching kernel when nnr = 0 and bug of square_sum (#8470)
     add 257ad1d  Doc updates for sparse operators (#8641)
     add bdd14a8  mac build fix (#8692)
     add a8f79bc  fix random docs (#8676)
     add a499f89  2bit gradient compression (#8662)
     add d2a856a  Restored some copyright attribution that were accidentally removed. (#8688)
     add bf7a0ff  Invert environment check (#8706)
     add 6ca944b  disable test causing mklml-cpu to fail (#8713)
     add 38a032c  [COREML] Update the json getter (#8698)
     add 9dcdf57  Fixing the monitor callback of the bucketing module. (#8696)
     add f79d22d  optimization for dot(csr.T, dense) = rsp (#8611)
     add 7f7e13d  replace `has_key` by `in` (#8317)
     add 504f42f  Revert "2bit gradient compression (#8662)" (#8711)
     add 7fc0396  fix group2ctx with null reqs (#8717)
     add defd3c3  Remove experimental warning on Gluon and add Gluon tutorials (#8710)
     add fd45517  Doc src and fix (#8718)
     new f50e7eb  [WIP]Image Augmenter (#8633)
     new d1a569c  [WIP]]Vision (#8649)
     new 5d3460d  add stub (#8650)
     new 2c7ceba  [WIP][vision]fix (#8657)
     new ae9fd42  fix image_random compile (#8665)
     new e741d8f  Add Gluon data transform (#8672)
     new 303e882  image to_tensor (#8691)
     new db2f1f4  [Image OP] Normalize (#8731)

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (e997559)
            \
             N -- N -- N   refs/heads/vision (db2f1f4)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 amalgamation/dmlc-minimum0.cc                      |   1 +
 cmake/Modules/FindJeMalloc.cmake                   |  10 +-
 cpp-package/include/mxnet-cpp/MxNetCpp.h           |   1 +
 cpp-package/include/mxnet-cpp/base.h               |   1 +
 cpp-package/include/mxnet-cpp/executor.h           |   1 +
 cpp-package/include/mxnet-cpp/initializer.h        |   1 +
 cpp-package/include/mxnet-cpp/io.h                 |   1 +
 cpp-package/include/mxnet-cpp/kvstore.h            |   1 +
 cpp-package/include/mxnet-cpp/lr_scheduler.h       |   1 +
 cpp-package/include/mxnet-cpp/metric.h             |   1 +
 cpp-package/include/mxnet-cpp/model.h              |   1 +
 cpp-package/include/mxnet-cpp/monitor.h            |   1 +
 cpp-package/include/mxnet-cpp/ndarray.h            |   1 +
 cpp-package/include/mxnet-cpp/op_map.h             |   1 +
 cpp-package/include/mxnet-cpp/op_suppl.h           |   1 +
 cpp-package/include/mxnet-cpp/op_util.h            |   1 +
 cpp-package/include/mxnet-cpp/operator.h           |   1 +
 cpp-package/include/mxnet-cpp/optimizer.h          |   1 +
 cpp-package/include/mxnet-cpp/shape.h              |   1 +
 cpp-package/include/mxnet-cpp/symbol.h             |   1 +
 dmlc-core                                          |   2 +-
 docker/install/scala.sh                            |   2 +-
 docs/api/python/autograd/autograd.md               |   5 -
 docs/api/python/gluon/data.md                      |   4 -
 docs/api/python/gluon/gluon.md                     |   4 -
 docs/api/python/gluon/model_zoo.md                 |   7 +-
 docs/api/python/ndarray/ndarray.md                 |  15 +-
 docs/api/python/ndarray/sparse.md                  | 125 +++++++++++++-
 docs/api/python/symbol/sparse.md                   |  97 +++++++++++
 docs/api/python/symbol/symbol.md                   |  15 +-
 docs/conf.py                                       |   1 +
 docs/mxdoc.py                                      |   8 +-
 docs/tutorials/index.md                            |  34 +++-
 docs/tutorials/sparse/row_sparse.md                |   2 +-
 example/gluon/data.py                              |   2 +-
 example/image-classification/symbols/vgg.py        |  16 +-
 example/sparse/linear_classification.py            |   4 +-
 example/sparse/matrix_factorization.py             |   7 +-
 include/mxnet/base.h                               |  33 +++-
 include/mxnet/c_api.h                              |  42 ++++-
 include/mxnet/c_predict_api.h                      |   1 +
 include/mxnet/engine.h                             |  33 +++-
 include/mxnet/executor.h                           |   1 +
 include/mxnet/io.h                                 |   1 +
 include/mxnet/kvstore.h                            |   1 +
 include/mxnet/ndarray.h                            |  48 +++++-
 include/mxnet/op_attr_types.h                      |   1 +
 include/mxnet/operator.h                           |   1 +
 include/mxnet/operator_util.h                      |   1 +
 include/mxnet/resource.h                           |   1 +
 include/mxnet/storage.h                            |  24 ++-
 include/mxnet/tensor_blob.h                        |   1 +
 perl-package/AI-MXNet/lib/AI/MXNet/Types.pm        |   2 +-
 plugin/caffe/caffe_blob.cc                         |   1 +
 plugin/caffe/caffe_blob.h                          |   1 +
 plugin/caffe/caffe_common.cc                       |   1 +
 plugin/caffe/caffe_common.h                        |   1 +
 plugin/caffe/caffe_data_iter.cc                    |   1 +
 plugin/caffe/caffe_fieldentry.h                    |   1 +
 plugin/caffe/caffe_loss-inl.h                      |   1 +
 plugin/caffe/caffe_loss.cc                         |   1 +
 plugin/caffe/caffe_loss.cu                         |   1 +
 plugin/caffe/caffe_op-inl.h                        |   1 +
 plugin/caffe/caffe_op.cc                           |   1 +
 plugin/caffe/caffe_op.cu                           |   1 +
 plugin/caffe/caffe_stream.cc                       |   1 +
 plugin/caffe/caffe_stream.h                        |   1 +
 plugin/opencv/cv_api.cc                            |   1 +
 plugin/opencv/cv_api.h                             |   1 +
 plugin/sframe/iter_sframe.cc                       |   1 +
 plugin/torch/torch_base.cc                         |   1 +
 plugin/torch/torch_base.h                          |   1 +
 plugin/torch/torch_criterion-inl.h                 |   1 +
 plugin/torch/torch_criterion.cc                    |   1 +
 plugin/torch/torch_criterion.cu                    |   1 +
 plugin/torch/torch_function.cc                     |   1 +
 plugin/torch/torch_function.h                      |   1 +
 plugin/torch/torch_module-inl.h                    |   1 +
 plugin/torch/torch_module.cc                       |   1 +
 plugin/torch/torch_module.cu                       |   1 +
 plugin/warpctc/warpctc-inl.h                       |   1 +
 plugin/warpctc/warpctc.cc                          |   1 +
 plugin/warpctc/warpctc.cu                          |   1 +
 python/mxnet/__init__.py                           |   1 +
 python/mxnet/_ctypes/ndarray.py                    |  14 +-
 python/mxnet/_ctypes/symbol.py                     |  18 +-
 python/mxnet/autograd.py                           |  31 ++--
 python/mxnet/base.py                               |  85 +++++++++-
 python/mxnet/context.py                            |  51 ++++--
 python/mxnet/contrib/autograd.py                   |  29 ++--
 python/mxnet/engine.py                             |  75 +++++++++
 python/mxnet/executor.py                           |   4 +-
 python/mxnet/gluon/data/dataloader.py              | 156 +++++++++++++++++-
 python/mxnet/gluon/model_zoo/vision/__init__.py    |   5 +-
 python/mxnet/gluon/nn/basic_layers.py              |  15 +-
 python/mxnet/gluon/rnn/rnn_layer.py                |  14 +-
 python/mxnet/io.py                                 |  10 +-
 python/mxnet/kvstore.py                            |  19 ++-
 python/mxnet/module/bucketing_module.py            |   4 +
 python/mxnet/ndarray/ndarray.py                    |  32 +++-
 python/mxnet/ndarray/sparse.py                     |  29 +++-
 python/mxnet/ndarray/utils.py                      |  30 ++--
 python/mxnet/notebook/callback.py                  |   2 +-
 python/mxnet/operator.py                           | 182 ++++++++++++++++++---
 python/mxnet/optimizer.py                          |  40 +++--
 python/mxnet/rtc.py                                |  13 +-
 python/mxnet/symbol/symbol.py                      | 142 ++++++++--------
 python/mxnet/torch.py                              |  12 +-
 .../main/native/ml_dmlc_mxnet_init_native_c_api.cc |   1 +
 .../native/src/main/native/jni_helper_func.h       |   1 +
 .../src/main/native/ml_dmlc_mxnet_native_c_api.cc  |   1 +
 src/c_api/c_api.cc                                 |  43 +++++
 src/c_api/c_api_common.h                           |   1 +
 src/c_api/c_api_error.cc                           |   1 +
 src/c_api/c_api_executor.cc                        |   1 +
 src/c_api/c_api_symbolic.cc                        |   1 +
 src/c_api/c_predict_api.cc                         |   1 +
 src/common/cuda_utils.h                            |   1 +
 src/common/lazy_alloc_array.h                      |  21 +--
 src/common/object_pool.h                           |   1 +
 src/common/rtc.cc                                  |   2 +-
 src/common/utils.cc                                |   6 +
 src/common/utils.cu                                |   6 +
 src/common/utils.h                                 | 169 +++++++++++++++++++
 src/engine/engine.cc                               |   1 +
 src/engine/engine_impl.h                           |   1 +
 src/engine/naive_engine.cc                         |   1 +
 src/engine/openmp.cc                               |   4 +-
 src/engine/profiler.cc                             |   1 +
 src/engine/profiler.h                              |   1 +
 src/engine/stream_manager.h                        |   5 +
 src/engine/thread_pool.h                           |   1 +
 src/engine/threaded_engine.cc                      |  33 +++-
 src/engine/threaded_engine.h                       |  76 +++++++++
 src/engine/threaded_engine_perdevice.cc            |  46 ++++--
 src/engine/threaded_engine_pooled.cc               |   1 +
 src/executor/attach_op_execs_pass.cc               |   1 +
 src/executor/attach_op_resource_pass.cc            |   1 +
 src/executor/exec_pass.h                           |   1 +
 src/executor/graph_executor.cc                     |  23 ++-
 src/executor/graph_executor.h                      |   1 +
 src/executor/inplace_addto_detect_pass.cc          |   1 +
 src/imperative/cached_op.cc                        |  18 +-
 src/imperative/imperative.cc                       |   4 +
 src/imperative/imperative_utils.h                  |  43 +++--
 src/initialize.cc                                  |   1 +
 src/io/image_aug_default.cc                        |   1 +
 src/io/image_augmenter.h                           |   1 +
 src/io/image_det_aug_default.cc                    |   7 +-
 src/io/image_io.cc                                 |   3 +-
 src/io/image_iter_common.h                         |   1 +
 src/io/image_recordio.h                            |   1 +
 src/io/inst_vector.h                               |   1 +
 src/io/io.cc                                       |   1 +
 src/io/iter_batchloader.h                          |   1 +
 src/io/iter_csv.cc                                 |   1 +
 src/io/iter_image_det_recordio.cc                  |   1 +
 src/io/iter_image_recordio.cc                      |   1 +
 src/io/iter_image_recordio_2.cc                    |   1 +
 src/io/iter_mnist.cc                               |   1 +
 src/io/iter_normalize.h                            |   1 +
 src/io/iter_prefetcher.h                           |   1 +
 src/kvstore/comm.h                                 |  17 +-
 src/kvstore/kvstore.cc                             |   1 +
 src/kvstore/kvstore_dist.h                         |   1 +
 src/kvstore/kvstore_dist_server.h                  |  21 +--
 src/kvstore/kvstore_local.h                        |   5 +-
 src/ndarray/ndarray.cc                             |  79 +++++++--
 src/ndarray/ndarray_function-inl.h                 |   1 +
 src/ndarray/ndarray_function.h                     |   1 +
 src/operator/activation-inl.h                      |   1 +
 src/operator/activation.cc                         |   1 +
 src/operator/activation.cu                         |   1 +
 src/operator/batch_norm-inl.h                      |   1 +
 src/operator/batch_norm.cc                         |   1 +
 src/operator/batch_norm.cu                         |   1 +
 src/operator/batch_norm_v1-inl.h                   |   1 +
 src/operator/batch_norm_v1.cc                      |   1 +
 src/operator/batch_norm_v1.cu                      |   1 +
 src/operator/bilinear_sampler-inl.h                |   1 +
 src/operator/bilinear_sampler.cc                   |   1 +
 src/operator/bilinear_sampler.cu                   |   1 +
 src/operator/channel_op_common.h                   |   1 +
 src/operator/concat-inl.h                          |   1 +
 src/operator/concat.cc                             |   1 +
 src/operator/concat.cu                             |   1 +
 src/operator/contrib/count_sketch-inl.h            |   1 +
 src/operator/contrib/count_sketch.cc               |   1 +
 src/operator/contrib/count_sketch.cu               |   1 +
 src/operator/contrib/ctc_loss-inl.h                |   1 +
 src/operator/contrib/ctc_loss.cc                   |   1 +
 src/operator/contrib/ctc_loss.cu                   |   1 +
 src/operator/contrib/dequantize-inl.h              |   1 +
 src/operator/contrib/dequantize.cc                 |   1 +
 src/operator/contrib/dequantize.cu                 |   1 +
 src/operator/contrib/fft-inl.h                     |   1 +
 src/operator/contrib/fft.cc                        |   1 +
 src/operator/contrib/fft.cu                        |   1 +
 src/operator/contrib/ifft-inl.h                    |   1 +
 src/operator/contrib/ifft.cc                       |   1 +
 src/operator/contrib/ifft.cu                       |   1 +
 src/operator/contrib/krprod.h                      |   1 +
 src/operator/contrib/multi_proposal-inl.h          |   1 +
 src/operator/contrib/multi_proposal.cu             |   1 +
 src/operator/contrib/multibox_detection-inl.h      |   1 +
 src/operator/contrib/multibox_detection.cc         |   1 +
 src/operator/contrib/multibox_detection.cu         |   1 +
 src/operator/contrib/multibox_prior-inl.h          |   1 +
 src/operator/contrib/multibox_prior.cc             |   1 +
 src/operator/contrib/multibox_prior.cu             |   1 +
 src/operator/contrib/multibox_target-inl.h         |   1 +
 src/operator/contrib/multibox_target.cc            |   1 +
 src/operator/contrib/multibox_target.cu            |   1 +
 src/operator/contrib/proposal-inl.h                |   1 +
 src/operator/contrib/proposal.cc                   |   1 +
 src/operator/contrib/proposal.cu                   |   1 +
 src/operator/contrib/psroi_pooling-inl.h           |   1 +
 src/operator/contrib/psroi_pooling.cc              |   1 +
 src/operator/contrib/psroi_pooling.cu              |   1 +
 src/operator/contrib/quantize-inl.h                |   1 +
 src/operator/contrib/quantize.cc                   |   1 +
 src/operator/contrib/quantize.cu                   |   1 +
 src/operator/convolution-inl.h                     |   1 +
 src/operator/convolution.cc                        |   1 +
 src/operator/convolution.cu                        |   1 +
 src/operator/convolution_v1-inl.h                  |   1 +
 src/operator/convolution_v1.cc                     |   1 +
 src/operator/convolution_v1.cu                     |   1 +
 src/operator/correlation-inl.h                     |   1 +
 src/operator/correlation.cc                        |   1 +
 src/operator/crop-inl.h                            |   1 +
 src/operator/crop.cc                               |   1 +
 src/operator/crop.cu                               |   1 +
 src/operator/cross_device_copy.cc                  |   1 +
 src/operator/cudnn_activation-inl.h                |   1 +
 src/operator/cudnn_algoreg-inl.h                   |   1 +
 src/operator/cudnn_algoreg.cc                      |   1 +
 src/operator/cudnn_batch_norm-inl.h                |   1 +
 src/operator/cudnn_batch_norm.cc                   |   1 +
 src/operator/cudnn_batch_norm.cu                   |   1 +
 src/operator/cudnn_bilinear_sampler-inl.h          |   1 +
 src/operator/cudnn_convolution-inl.h               |   4 +-
 src/operator/cudnn_deconvolution-inl.h             |   4 +-
 src/operator/cudnn_lrn-inl.h                       |   1 +
 src/operator/cudnn_pooling-inl.h                   |   1 +
 src/operator/cudnn_rnn-inl.h                       |   1 +
 src/operator/cudnn_softmax_activation-inl.h        |   1 +
 src/operator/cudnn_spatial_transformer-inl.h       |   1 +
 src/operator/custom/custom-inl.h                   |   1 +
 src/operator/custom/custom.cc                      | 117 +++++++++++--
 src/operator/custom/native_op-inl.h                |   1 +
 src/operator/custom/native_op.cc                   |   1 +
 src/operator/custom/native_op.cu                   |   1 +
 src/operator/custom/ndarray_op-inl.h               |   1 +
 src/operator/custom/ndarray_op.cc                  |  17 +-
 src/operator/deconvolution-inl.h                   |   1 +
 src/operator/deconvolution.cc                      |   1 +
 src/operator/deconvolution.cu                      |   1 +
 src/operator/dropout-inl.h                         |   1 +
 src/operator/dropout.cc                            |   1 +
 src/operator/dropout.cu                            |   1 +
 src/operator/elemwise_op_common.h                  |   1 +
 src/operator/fully_connected-inl.h                 |   1 +
 src/operator/fully_connected.cc                    |   1 +
 src/operator/fully_connected.cu                    |   1 +
 src/operator/grid_generator-inl.h                  |   1 +
 src/operator/grid_generator.cc                     |   1 +
 src/operator/grid_generator.cu                     |   1 +
 src/operator/identity_attach_KL_sparse_reg-inl.h   |   1 +
 src/operator/identity_attach_KL_sparse_reg.cc      |   1 +
 src/operator/identity_attach_KL_sparse_reg.cu      |   1 +
 src/operator/instance_norm-inl.h                   |   1 +
 src/operator/instance_norm.cc                      |   1 +
 src/operator/instance_norm.cu                      |   1 +
 src/operator/l2_normalization-inl.h                |   1 +
 src/operator/l2_normalization.cc                   |   1 +
 src/operator/l2_normalization.cu                   |   1 +
 src/operator/leaky_relu-inl.h                      |   1 +
 src/operator/leaky_relu.cc                         |   1 +
 src/operator/leaky_relu.cu                         |   1 +
 src/operator/loss_binary_op-inl.h                  |   1 +
 src/operator/loss_binary_op.cc                     |   1 +
 src/operator/loss_binary_op.cu                     |   1 +
 src/operator/lrn-inl.h                             |   1 +
 src/operator/lrn.cc                                |   1 +
 src/operator/lrn.cu                                |   1 +
 src/operator/make_loss-inl.h                       |   1 +
 src/operator/make_loss.cc                          |   1 +
 src/operator/make_loss.cu                          |   1 +
 src/operator/mshadow_op.h                          |   1 +
 src/operator/mxnet_op.h                            |   1 +
 src/operator/nn/im2col.h                           |   1 +
 src/operator/nn/pool.h                             |   1 +
 src/operator/nn/softmax-inl.h                      |   1 +
 src/operator/nn/softmax.cc                         |   1 +
 src/operator/nn/softmax.cu                         |   1 +
 src/operator/nnpack/nnpack_convolution-inl.h       |   1 +
 src/operator/nnpack/nnpack_fully_connected-inl.h   |   1 +
 src/operator/nnpack/nnpack_pooling-inl.h           |   1 +
 src/operator/nnpack/nnpack_util.cc                 |   1 +
 src/operator/nnpack/nnpack_util.h                  |   1 +
 src/operator/operator.cc                           |   1 +
 src/operator/operator_common.h                     |   5 +
 src/operator/operator_util.cc                      |   1 +
 src/operator/optimizer_op-inl.h                    |   1 +
 src/operator/optimizer_op.cc                       |   5 +
 src/operator/optimizer_op.cu                       |   1 +
 src/operator/pad-inl.h                             |   1 +
 src/operator/pad.cc                                |   1 +
 src/operator/pad.cu                                |   1 +
 src/operator/pooling-inl.h                         |   1 +
 src/operator/pooling.cc                            |   1 +
 src/operator/pooling.cu                            |   1 +
 src/operator/pooling_v1-inl.h                      |   1 +
 src/operator/pooling_v1.cc                         |   1 +
 src/operator/pooling_v1.cu                         |   1 +
 src/operator/random/multisample_op.cc              |   1 +
 src/operator/random/multisample_op.h               |   1 +
 src/operator/random/sample_multinomial_op.cc       |   1 +
 src/operator/random/sample_multinomial_op.cu       |   1 +
 src/operator/random/sample_multinomial_op.h        |   1 +
 src/operator/random/sample_op.cc                   |   1 +
 src/operator/random/sample_op.cu                   |   1 +
 src/operator/random/sample_op.h                    |   1 +
 src/operator/regression_output-inl.h               |   1 +
 src/operator/regression_output.cc                  |   1 +
 src/operator/regression_output.cu                  |   1 +
 src/operator/rnn-inl.h                             |   1 +
 src/operator/rnn.cc                                |   1 +
 src/operator/rnn.cu                                |   1 +
 src/operator/roi_pooling-inl.h                     |   1 +
 src/operator/roi_pooling.cc                        |   1 +
 src/operator/roi_pooling.cu                        |   1 +
 src/operator/sequence_last-inl.h                   |   1 +
 src/operator/sequence_last.cc                      |   1 +
 src/operator/sequence_last.cu                      |   1 +
 src/operator/sequence_mask-inl.h                   |   1 +
 src/operator/sequence_mask.cc                      |   1 +
 src/operator/sequence_mask.cu                      |   1 +
 src/operator/sequence_op_common.h                  |   1 +
 src/operator/sequence_reverse-inl.h                |   1 +
 src/operator/sequence_reverse.cc                   |   1 +
 src/operator/sequence_reverse.cu                   |   1 +
 src/operator/slice_channel-inl.h                   |   1 +
 src/operator/slice_channel.cc                      |   1 +
 src/operator/slice_channel.cu                      |   1 +
 src/operator/softmax_activation-inl.h              |   1 +
 src/operator/softmax_activation.cc                 |   1 +
 src/operator/softmax_activation.cu                 |   1 +
 src/operator/softmax_output-inl.h                  |   1 +
 src/operator/softmax_output.cc                     |   1 +
 src/operator/softmax_output.cu                     |   1 +
 src/operator/spatial_transformer-inl.h             |   1 +
 src/operator/spatial_transformer.cc                |   1 +
 src/operator/spatial_transformer.cu                |   1 +
 src/operator/special_functions-inl.h               |   1 +
 src/operator/svm_output-inl.h                      |   1 +
 src/operator/svm_output.cc                         |   1 +
 src/operator/svm_output.cu                         |   1 +
 src/operator/swapaxis-inl.h                        |   1 +
 src/operator/swapaxis.cc                           |   1 +
 src/operator/swapaxis.cu                           |   1 +
 src/operator/tensor/broadcast_reduce-inl.h         |   1 +
 src/operator/tensor/broadcast_reduce_op.h          |   1 +
 src/operator/tensor/broadcast_reduce_op_index.cc   |   1 +
 src/operator/tensor/broadcast_reduce_op_index.cu   |   1 +
 src/operator/tensor/broadcast_reduce_op_value.cc   |   3 +-
 src/operator/tensor/broadcast_reduce_op_value.cu   |   1 +
 src/operator/tensor/control_flow_op.cc             |   1 +
 src/operator/tensor/control_flow_op.cu             |   1 +
 src/operator/tensor/control_flow_op.h              |   1 +
 src/operator/tensor/dot-inl.cuh                    |  29 +++-
 src/operator/tensor/dot-inl.h                      | 115 ++++++++-----
 src/operator/tensor/elemwise_binary_broadcast_op.h |   6 +-
 .../tensor/elemwise_binary_broadcast_op_basic.cc   |   1 +
 .../tensor/elemwise_binary_broadcast_op_basic.cu   |   1 +
 .../elemwise_binary_broadcast_op_extended.cc       |   1 +
 .../elemwise_binary_broadcast_op_extended.cu       |   1 +
 .../tensor/elemwise_binary_broadcast_op_logic.cc   |   1 +
 .../tensor/elemwise_binary_broadcast_op_logic.cu   |   1 +
 src/operator/tensor/elemwise_binary_op.h           |   1 +
 src/operator/tensor/elemwise_binary_op_basic.cc    |   8 +-
 src/operator/tensor/elemwise_binary_op_basic.cu    |   1 +
 src/operator/tensor/elemwise_binary_op_extended.cc |   1 +
 src/operator/tensor/elemwise_binary_op_extended.cu |   1 +
 src/operator/tensor/elemwise_binary_op_logic.cc    |   1 +
 src/operator/tensor/elemwise_binary_op_logic.cu    |   1 +
 src/operator/tensor/elemwise_binary_scalar_op.h    |   1 +
 .../tensor/elemwise_binary_scalar_op_basic.cc      |   1 +
 .../tensor/elemwise_binary_scalar_op_basic.cu      |   1 +
 .../tensor/elemwise_binary_scalar_op_extended.cc   |   1 +
 .../tensor/elemwise_binary_scalar_op_extended.cu   |   1 +
 .../tensor/elemwise_binary_scalar_op_logic.cc      |   1 +
 .../tensor/elemwise_binary_scalar_op_logic.cu      |   1 +
 src/operator/tensor/elemwise_sum.cc                |   1 +
 src/operator/tensor/elemwise_sum.cu                |   1 +
 src/operator/tensor/elemwise_sum.h                 |   1 +
 src/operator/tensor/elemwise_unary_op.h            |   5 +-
 src/operator/tensor/indexing_op.cc                 | 113 ++++++++++++-
 src/operator/tensor/indexing_op.cu                 | 157 ++++++++++++++++++
 src/operator/tensor/indexing_op.h                  | 114 ++-----------
 src/operator/tensor/init_op.cc                     |   1 +
 src/operator/tensor/init_op.cu                     |   1 +
 src/operator/tensor/init_op.h                      |   1 +
 src/operator/tensor/la_op.cc                       |   1 +
 src/operator/tensor/la_op.h                        |   1 +
 src/operator/tensor/la_op_inline.h                 |   1 +
 src/operator/tensor/matrix_op-inl.h                |   3 +-
 src/operator/tensor/matrix_op.cc                   |   4 +-
 src/operator/tensor/matrix_op.cu                   |   1 +
 src/operator/tensor/ordering_op-inl.h              |   1 +
 src/operator/tensor/ordering_op.cc                 |   1 +
 src/operator/tensor/ordering_op.cu                 |   1 +
 src/operator/tensor/sort_op.h                      |   1 +
 src/operator/tensor/square_sum-inl.h               |  88 +++++++---
 src/operator/upsampling-inl.h                      |   1 +
 src/operator/upsampling.cc                         |   1 +
 src/operator/upsampling.cu                         |   1 +
 src/optimizer/sgd-inl.h                            |   1 +
 src/resource.cc                                    |   9 +-
 src/storage/cpu_device_storage.h                   |   1 +
 src/storage/cpu_shared_storage_manager.h           | 174 ++++++++++++++++++++
 src/storage/gpu_device_storage.h                   |   1 +
 src/storage/naive_storage_manager.h                |  17 +-
 src/storage/pinned_memory_storage.h                |   1 +
 src/storage/pooled_storage_manager.h               |  30 ++--
 src/storage/storage.cc                             |  52 +++---
 src/storage/storage_manager.h                      |   9 +-
 tests/cpp/engine/threaded_engine_test.cc           |   1 +
 tests/cpp/include/test_core_op.h                   |  44 +++++
 tests/cpp/include/test_op.h                        |   1 +
 tests/cpp/include/test_op_runner.h                 |  10 +-
 tests/cpp/include/test_perf.h                      |   1 +
 tests/cpp/include/test_util.h                      |   1 +
 tests/cpp/misc/memory_test.cc                      |   4 +-
 tests/cpp/operator/batchnorm_test.cc               |   3 +-
 tests/cpp/operator/broadcast_perf.cc               |  64 +++-----
 tests/cpp/operator/krprod_test.cc                  |   1 +
 tests/cpp/storage/storage_test.cc                  |   1 +
 tests/cpp/test_main.cc                             |   1 +
 tests/nightly/TestDoc/doc_spell_checker.py         |   2 +-
 tests/nightly/dist_device_sync_kvstore.py          |  95 +++++++++++
 tests/python/gpu/test_operator_gpu.py              |   1 +
 .../python/unittest/test_engine.py                 |  23 ++-
 tests/python/unittest/test_gluon_data.py           |  15 ++
 tests/python/unittest/test_io.py                   |   6 +-
 tests/python/unittest/test_kvstore.py              |   2 +-
 tests/python/unittest/test_module.py               |   2 +-
 tests/python/unittest/test_multi_device_exec.py    |  26 ++-
 tests/python/unittest/test_ndarray.py              |   2 +-
 tests/python/unittest/test_operator.py             |  69 ++++++--
 tests/python/unittest/test_sparse_ndarray.py       |  96 +++++++++--
 tests/python/unittest/test_sparse_operator.py      | 118 ++++++++-----
 tools/accnn/rank_selection.py                      |   2 +-
 tools/accnn/utils.py                               |   5 +-
 tools/coreml/converter/__init__.py                 |   1 -
 tools/coreml/converter/_layers.py                  |  40 ++++-
 tools/im2rec.cc                                    |   1 +
 tools/license_header.py                            |   7 -
 459 files changed, 3422 insertions(+), 830 deletions(-)
 create mode 100644 python/mxnet/engine.py
 create mode 100644 src/storage/cpu_shared_storage_manager.h
 create mode 100644 tests/nightly/dist_device_sync_kvstore.py
 copy example/speech_recognition/stt_layer_slice.py => tests/python/unittest/test_engine.py (69%)

-- 
To stop receiving notification emails like this one, please contact
['"commits@mxnet.apache.org" <co...@mxnet.apache.org>'].

[incubator-mxnet] 01/08: [WIP]Image Augmenter (#8633)

Posted by jx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jxie pushed a commit to branch vision
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git

commit f50e7ebb60eb6582296b3f7c5177b7ee24493f96
Author: Hu Shiwen <ya...@gmail.com>
AuthorDate: Tue Nov 14 08:32:47 2017 +0800

    [WIP]Image Augmenter (#8633)
    
    * add file
    
    * add random_brightness
    add python mx.sym/nd.image
    
    * fix lint
    
    * add image/image_common.h
    
    * add RandomContrast
    
    * change name
    
    * fix
---
 python/mxnet/base.py                               |  8 +-
 python/mxnet/ndarray/__init__.py                   |  4 +-
 .../mxnet/{symbol/__init__.py => ndarray/image.py} | 15 ++--
 python/mxnet/symbol/__init__.py                    |  4 +-
 python/mxnet/symbol/{__init__.py => image.py}      | 15 ++--
 src/operator/batch_norm_v1-inl.h                   |  2 +-
 src/operator/image/image_common.h                  | 88 +++++++++++++++++++
 src/operator/image/image_random-inl.h              | 99 ++++++++++++++++++++++
 src/operator/image/image_random.cc                 | 50 +++++++++++
 src/operator/random/multisample_op.h               |  2 +-
 src/operator/tensor/broadcast_reduce_op_index.cc   |  2 +-
 .../elemwise_binary_broadcast_op_extended.cc       |  2 +-
 .../tensor/elemwise_binary_broadcast_op_logic.cc   |  2 +-
 13 files changed, 261 insertions(+), 32 deletions(-)

diff --git a/python/mxnet/base.py b/python/mxnet/base.py
index 80fc901..4f97bed 100644
--- a/python/mxnet/base.py
+++ b/python/mxnet/base.py
@@ -449,7 +449,7 @@ def _as_list(obj):
         return [obj]
 
 
-_OP_NAME_PREFIX_LIST = ['_contrib_', '_linalg_', '_sparse_']
+_OP_NAME_PREFIX_LIST = ['_contrib_', '_linalg_', '_sparse_', '_image_']
 
 
 def _get_op_name_prefix(op_name):
@@ -503,10 +503,11 @@ def _init_op_module(root_namespace, module_name, make_op_func):
         hdl = OpHandle()
         check_call(_LIB.NNGetOpHandle(c_str(name), ctypes.byref(hdl)))
         op_name_prefix = _get_op_name_prefix(name)
+        module_name_local = module_name
         if len(op_name_prefix) > 0:
             func_name = name[len(op_name_prefix):]
             cur_module = submodule_dict[op_name_prefix]
-            module_name = "%s.%s.%s" % (root_namespace, module_name, op_name_prefix[1:-1])
+            module_name_local = "%s.%s.%s" % (root_namespace, module_name, op_name_prefix[1:-1])
         elif name.startswith('_'):
             func_name = name
             cur_module = module_internal
@@ -515,10 +516,11 @@ def _init_op_module(root_namespace, module_name, make_op_func):
             cur_module = module_op
 
         function = make_op_func(hdl, name, func_name)
-        function.__module__ = module_name
+        function.__module__ = module_name_local
         setattr(cur_module, function.__name__, function)
         cur_module.__all__.append(function.__name__)
 
+
         if op_name_prefix == '_contrib_':
             hdl = OpHandle()
             check_call(_LIB.NNGetOpHandle(c_str(name), ctypes.byref(hdl)))
diff --git a/python/mxnet/ndarray/__init__.py b/python/mxnet/ndarray/__init__.py
index 586dc9e..86a3a20 100644
--- a/python/mxnet/ndarray/__init__.py
+++ b/python/mxnet/ndarray/__init__.py
@@ -17,7 +17,7 @@
 
 """NDArray API of MXNet."""
 
-from . import _internal, contrib, linalg, op, random, sparse, utils
+from . import _internal, contrib, linalg, op, random, sparse, utils, image
 # pylint: disable=wildcard-import, redefined-builtin
 try:
     from .gen_op import * # pylint: disable=unused-wildcard-import
@@ -31,4 +31,4 @@ from .utils import load, save, zeros, empty, array
 from .sparse import _ndarray_cls
 from .ndarray import _GRAD_REQ_MAP
 
-__all__ = op.__all__ + ndarray.__all__ + utils.__all__ + ['contrib', 'linalg', 'random', 'sparse']
+__all__ = op.__all__ + ndarray.__all__ + utils.__all__ + ['contrib', 'linalg', 'random', 'sparse', 'image']
diff --git a/python/mxnet/symbol/__init__.py b/python/mxnet/ndarray/image.py
similarity index 67%
copy from python/mxnet/symbol/__init__.py
copy to python/mxnet/ndarray/image.py
index a07025e..0afab24 100644
--- a/python/mxnet/symbol/__init__.py
+++ b/python/mxnet/ndarray/image.py
@@ -15,17 +15,12 @@
 # specific language governing permissions and limitations
 # under the License.
 
-"""Symbol API of MXNet."""
-
-from . import _internal, contrib, linalg, op, random, sparse
-# pylint: disable=wildcard-import, redefined-builtin
+# coding: utf-8
+# pylint: disable=wildcard-import, unused-wildcard-import
+"""Image NDArray API of MXNet."""
 try:
-    from .gen_op import * # pylint: disable=unused-wildcard-import
+    from .gen_iamge import *
 except ImportError:
     pass
-from . import register
-from .op import *
-from .symbol import *
-# pylint: enable=wildcard-import
 
-__all__ = op.__all__ + symbol.__all__ + ['contrib', 'linalg', 'random', 'sparse']
+__all__ = []
diff --git a/python/mxnet/symbol/__init__.py b/python/mxnet/symbol/__init__.py
index a07025e..a10b64e 100644
--- a/python/mxnet/symbol/__init__.py
+++ b/python/mxnet/symbol/__init__.py
@@ -17,7 +17,7 @@
 
 """Symbol API of MXNet."""
 
-from . import _internal, contrib, linalg, op, random, sparse
+from . import _internal, contrib, linalg, op, random, sparse, image
 # pylint: disable=wildcard-import, redefined-builtin
 try:
     from .gen_op import * # pylint: disable=unused-wildcard-import
@@ -28,4 +28,4 @@ from .op import *
 from .symbol import *
 # pylint: enable=wildcard-import
 
-__all__ = op.__all__ + symbol.__all__ + ['contrib', 'linalg', 'random', 'sparse']
+__all__ = op.__all__ + symbol.__all__ + ['contrib', 'linalg', 'random', 'sparse', 'image']
diff --git a/python/mxnet/symbol/__init__.py b/python/mxnet/symbol/image.py
similarity index 67%
copy from python/mxnet/symbol/__init__.py
copy to python/mxnet/symbol/image.py
index a07025e..7624bcc 100644
--- a/python/mxnet/symbol/__init__.py
+++ b/python/mxnet/symbol/image.py
@@ -15,17 +15,12 @@
 # specific language governing permissions and limitations
 # under the License.
 
-"""Symbol API of MXNet."""
-
-from . import _internal, contrib, linalg, op, random, sparse
-# pylint: disable=wildcard-import, redefined-builtin
+# coding: utf-8
+# pylint: disable=wildcard-import, unused-wildcard-import
+"""Image Symbol API of MXNet."""
 try:
-    from .gen_op import * # pylint: disable=unused-wildcard-import
+    from .gen_iamge import *
 except ImportError:
     pass
-from . import register
-from .op import *
-from .symbol import *
-# pylint: enable=wildcard-import
 
-__all__ = op.__all__ + symbol.__all__ + ['contrib', 'linalg', 'random', 'sparse']
+__all__ = []
diff --git a/src/operator/batch_norm_v1-inl.h b/src/operator/batch_norm_v1-inl.h
index 329d66d..1e04845 100644
--- a/src/operator/batch_norm_v1-inl.h
+++ b/src/operator/batch_norm_v1-inl.h
@@ -19,7 +19,7 @@
 
 /*!
  * Copyright (c) 2015 by Contributors
- * \file batch_norm-inl_v1.h
+ * \file batch_norm_v1-inl.h
  * \brief
  * \author Bing Xu
 */
diff --git a/src/operator/image/image_common.h b/src/operator/image/image_common.h
new file mode 100644
index 0000000..7cf3f96
--- /dev/null
+++ b/src/operator/image/image_common.h
@@ -0,0 +1,88 @@
+/*
+* 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.
+*/
+
+/*!
+* \file image_common.h
+* \brief
+* \author
+*/
+#ifndef MXNET_OPERATOR_IMAGE_IMAGE_COMMON_H_
+#define MXNET_OPERATOR_IMAGE_IMAGE_COMMON_H_
+
+#include <mxnet/base.h>
+
+namespace mxnet {
+namespace op {
+
+/**
+* @brief convert TBlob to cv::Mat
+* @param input @see TBlob
+* @param hight
+* @param weight
+* @param channel
+* @return
+*/
+static cv::Mat mat_convert(TBlob input, int hight, int weight, int channel) {
+  cv::Mat m;
+  switch (input.type_flag_) {
+    case mshadow::kFloat32: {
+      typedef float DType;
+      m = cv::Mat(hight, weight, CV_MAKETYPE(CV_32F, channel), input.dptr<DType>());
+    }
+    break;
+    case mshadow::kFloat64: {
+      typedef double DType;
+      m = cv::Mat(hight, weight, CV_MAKETYPE(CV_64F, channel), input.dptr<DType>());
+    }
+    break;
+    case mshadow::kFloat16: {
+      typedef mshadow::half::half_t DType;
+      LOG(FATAL) << "not support type enum " << input.type_flag_;
+    }
+    break;
+    case mshadow::kUint8: {
+      typedef uint8_t DType;
+      m = cv::Mat(hight, weight, CV_MAKETYPE(CV_8U, channel), input.dptr<DType>());
+    }
+    break;
+    case mshadow::kInt8: {
+      typedef int8_t DType;
+      m = cv::Mat(hight, weight, CV_MAKETYPE(CV_8S, channel), input.dptr<DType>());
+    }
+    break;
+    case mshadow::kInt32: {
+      typedef int32_t DType;
+      m = cv::Mat(hight, weight, CV_MAKETYPE(CV_32S, channel), input.dptr<DType>());
+    }
+    break;
+    case mshadow::kInt64: {
+      typedef int64_t DType;
+      LOG(FATAL) << "not support type enum " << input.type_flag_;
+    }
+    break;
+    default:
+      LOG(FATAL) << "Unknown type enum " << input.type_flag_;
+  }
+  return m;
+}
+} // namespace op
+} // namespace mxnet
+
+
+#endif // MXNET_OPERATOR_IMAGE_IMAGE_COMMON_H_
\ No newline at end of file
diff --git a/src/operator/image/image_random-inl.h b/src/operator/image/image_random-inl.h
new file mode 100644
index 0000000..027d587
--- /dev/null
+++ b/src/operator/image/image_random-inl.h
@@ -0,0 +1,99 @@
+/*
+* 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.
+*/
+
+/*!
+* \file image_random-inl.h
+* \brief
+* \author
+*/
+#ifndef MXNET_OPERATOR_IMAGE_IMAGE_RANDOM_INL_H_
+#define MXNET_OPERATOR_IMAGE_IMAGE_RANDOM_INL_H_
+
+#include <vector>
+#include <mxnet/base.h>
+#include <opencv2/opencv.hpp>
+#include <opencv2/core/mat.hpp>
+#include "mxnet/op_attr_types.h"
+#include "image_common.h"
+
+
+namespace mxnet {
+namespace op {
+struct RandomBrightnessParam : public dmlc::Parameter<RandomBrightnessParam> {
+  float max_brightness;
+  DMLC_DECLARE_PARAMETER(RandomBrightnessParam) {
+    DMLC_DECLARE_FIELD(max_brightness)
+    .set_default(0.0)
+    .describe("Max Contrast.");
+  }
+};
+
+
+template<typename xpu>
+static void RandomBrightness(const nnvm::NodeAttrs &attrs,
+                             const OpContext &ctx,
+                             const std::vector<TBlob> &inputs,
+                             const std::vector<OpReqType> &req,
+                             const std::vector<TBlob> &outputs) {
+  auto input = inputs[0];
+  auto output = outputs[0];
+  int hight = input.shape_[0];
+  int weight = input.shape_[1];
+  int channel = input.shape_[2];
+
+  auto input_mat = mat_convert(input, hight, weight, channel);
+  auto output_mat = mat_convert(output, hight, weight, channel);
+  //input_mat.convertTo(output_mat, -1, 1/255.0, 0);
+  std::default_random_engine generator;
+  const RandomBrightnessParam &param = nnvm::get<RandomBrightnessParam>(attrs.parsed);
+  float alpha_b = 1.0 + std::uniform_real_distribution<float>(-param.max_brightness, param.max_brightness)(generator);
+  output_mat.convertTo(output_mat, -1, alpha_b, 0);
+}
+
+
+template<typename xpu>
+static void RandomContrast(const nnvm::NodeAttrs &attrs,
+  const OpContext &ctx,
+  const std::vector<TBlob> &inputs,
+  const std::vector<OpReqType> &req,
+  const std::vector<TBlob> &outputs) {
+  auto input = inputs[0];
+  auto output = outputs[0];
+  int hight = input.shape_[0];
+  int weight = input.shape_[1];
+  int channel = input.shape_[2];
+
+  auto input_mat = mat_convert(input, hight, weight, channel);
+  auto output_mat = mat_convert(output, hight, weight, channel);
+  //input_mat.convertTo(output_mat, -1, 1/255.0, 0);
+  std::default_random_engine generator;
+  const RandomBrightnessParam &param = nnvm::get<RandomBrightnessParam>(attrs.parsed);
+  float alpha_c = 1.0 + std::uniform_real_distribution<float>(-param.max_brightness, param.max_brightness)(generator);
+  cv::Mat temp_;
+  cv::cvtColor(input_mat, temp_,  CV_RGB2GRAY);
+  float gray_mean = cv::mean(temp_)[0];
+  input_mat.convertTo(output_mat, -1, alpha_c, (1 - alpha_c) * gray_mean);
+
+}
+
+
+} // namespace op
+} // namespace mxnet
+
+#endif  // MXNET_OPERATOR_IMAGE_IMAGE_RANDOM_INL_H_
diff --git a/src/operator/image/image_random.cc b/src/operator/image/image_random.cc
new file mode 100644
index 0000000..3777e43
--- /dev/null
+++ b/src/operator/image/image_random.cc
@@ -0,0 +1,50 @@
+/*
+* 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.
+*/
+
+/*!
+* \file image_random.cc
+* \brief
+* \author
+*/
+
+#include <mxnet/base.h>
+#include "./image_random-inl.h"
+#include "operator/operator_common.h"
+#include "operator/elemwise_op_common.h"
+
+
+
+namespace mxnet {
+namespace op {
+
+DMLC_REGISTER_PARAMETER(RandomBrightnessParam);
+NNVM_REGISTER_OP(_image_random_brightness)
+.describe(R"code()code" ADD_FILELINE)
+.set_num_inputs(1)
+.set_num_outputs(1)
+.set_attr_parser(ParamParser<RandomBrightnessParam>)
+.set_attr<nnvm::FInferShape>("FInferShape", ElemwiseShape<1, 1>)
+.set_attr<nnvm::FInferType>("FInferType", ElemwiseType<1, 1>)
+.set_attr<FCompute>("FCompute<cpu>", RandomBrightness<cpu>)
+.set_attr<nnvm::FGradient>("FGradient", ElemwiseGradUseNone{ "_copy" })
+.add_argument("data", "NDArray-or-Symbol", "The input.")
+.add_arguments(RandomBrightnessParam::__FIELDS__());
+
+}
+}
diff --git a/src/operator/random/multisample_op.h b/src/operator/random/multisample_op.h
index 38ccbb6..2338384 100644
--- a/src/operator/random/multisample_op.h
+++ b/src/operator/random/multisample_op.h
@@ -19,7 +19,7 @@
 
 /*!
  * Copyright (c) 2017 by Contributors
- * \file sampling_op.h
+ * \file multisample_op.h
  * \brief Function definitions of operators for sampling from multiple distributions
  */
 #ifndef MXNET_OPERATOR_RANDOM_MULTISAMPLE_OP_H_
diff --git a/src/operator/tensor/broadcast_reduce_op_index.cc b/src/operator/tensor/broadcast_reduce_op_index.cc
index dc07e67..6fd90df 100644
--- a/src/operator/tensor/broadcast_reduce_op_index.cc
+++ b/src/operator/tensor/broadcast_reduce_op_index.cc
@@ -19,7 +19,7 @@
 
 /*!
  *  Copyright (c) 2016 by Contributors
- * \file broadcast_reduce_op.cc
+ * \file broadcast_reduce_op_index.cc
  * \brief CPU Implementation of broadcast and reduce functions.
  */
 #include "./broadcast_reduce_op.h"
diff --git a/src/operator/tensor/elemwise_binary_broadcast_op_extended.cc b/src/operator/tensor/elemwise_binary_broadcast_op_extended.cc
index fe7ad76..8fc3c48 100644
--- a/src/operator/tensor/elemwise_binary_broadcast_op_extended.cc
+++ b/src/operator/tensor/elemwise_binary_broadcast_op_extended.cc
@@ -19,7 +19,7 @@
 
 /*!
  *  Copyright (c) 2016 by Contributors
- * \file elemwise_binary_scalar_op.cc
+ * \file elemwise_binary_broadcast_op_extended.cc
  * \brief CPU Implementation of unary function.
  */
 #include "./elemwise_unary_op.h"
diff --git a/src/operator/tensor/elemwise_binary_broadcast_op_logic.cc b/src/operator/tensor/elemwise_binary_broadcast_op_logic.cc
index 6d74f2d..31f34bb 100644
--- a/src/operator/tensor/elemwise_binary_broadcast_op_logic.cc
+++ b/src/operator/tensor/elemwise_binary_broadcast_op_logic.cc
@@ -19,7 +19,7 @@
 
 /*!
  *  Copyright (c) 2016 by Contributors
- * \file elemwise_binary_scalar_op.cc
+ * \file elemwise_binary_broadcast_op_logic.cc
  * \brief CPU Implementation of unary function.
  */
 #include "./elemwise_unary_op.h"

-- 
To stop receiving notification emails like this one, please contact
"commits@mxnet.apache.org" <co...@mxnet.apache.org>.

[incubator-mxnet] 04/08: [WIP][vision]fix (#8657)

Posted by jx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jxie pushed a commit to branch vision
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git

commit 2c7ceba67ef10d59c5873cd318bcd97aa5962259
Author: Hu Shiwen <ya...@gmail.com>
AuthorDate: Wed Nov 15 12:16:23 2017 +0800

    [WIP][vision]fix (#8657)
    
    * fix
    
    * lint
---
 src/operator/image/image_random-inl.h | 118 ++++++++++++++++++++++++----------
 src/operator/image/image_random.cc    |  32 +++++++++
 src/operator/mxnet_op.h               |   6 ++
 3 files changed, 122 insertions(+), 34 deletions(-)

diff --git a/src/operator/image/image_random-inl.h b/src/operator/image/image_random-inl.h
index 1281a71..fa1d6dc 100644
--- a/src/operator/image/image_random-inl.h
+++ b/src/operator/image/image_random-inl.h
@@ -31,6 +31,7 @@
 #include <opencv2/core/mat.hpp>
 #include "../mxnet_op.h"
 #include "image_common.h"
+#include "operator/operator_common.h"
 
 
 namespace mxnet {
@@ -41,32 +42,32 @@ enum ImageRandomResource { kRandom };
 
 template<typename xpu>
 static void RandomFlip(const nnvm::NodeAttrs &attrs,
-  const OpContext &ctx,
-  const std::vector<TBlob> &inputs,
-  const std::vector<OpReqType> &req,
-  const std::vector<TBlob> &outputs) {
+                       const OpContext &ctx,
+                       const std::vector<TBlob> &inputs,
+                       const std::vector<OpReqType> &req,
+                       const std::vector<TBlob> &outputs) {
 }
 template<typename xpu>
 static void ToTensor(const nnvm::NodeAttrs &attrs,
-  const OpContext &ctx,
-  const std::vector<TBlob> &inputs,
-  const std::vector<OpReqType> &req,
-  const std::vector<TBlob> &outputs) {
+                     const OpContext &ctx,
+                     const std::vector<TBlob> &inputs,
+                     const std::vector<OpReqType> &req,
+                     const std::vector<TBlob> &outputs) {
 }
 template<typename xpu>
 static void Normalize(const nnvm::NodeAttrs &attrs,
-  const OpContext &ctx,
-  const std::vector<TBlob> &inputs,
-  const std::vector<OpReqType> &req,
-  const std::vector<TBlob> &outputs) {
+                      const OpContext &ctx,
+                      const std::vector<TBlob> &inputs,
+                      const std::vector<OpReqType> &req,
+                      const std::vector<TBlob> &outputs) {
 }
 
 struct RandomBrightnessParam : public dmlc::Parameter<RandomBrightnessParam> {
   float max_brightness;
   DMLC_DECLARE_PARAMETER(RandomBrightnessParam) {
     DMLC_DECLARE_FIELD(max_brightness)
-      .set_default(0.0)
-      .describe("Max Brightness.");
+    .set_default(0.0)
+    .describe("Max Brightness.");
   }
 };
 
@@ -88,7 +89,7 @@ static void RandomBrightness(const nnvm::NodeAttrs &attrs,
   const RandomBrightnessParam &param = nnvm::get<RandomBrightnessParam>(attrs.parsed);
   float alpha_b = 1.0 + std::uniform_real_distribution<float>(-param.max_brightness, param.max_brightness)(prnd->GetRndEngine());
   MSHADOW_TYPE_SWITCH(outputs[0].type_flag_, DType, {
-    MXNET_ASSIGN_REQ_SWITCH(req[0], Req,{
+    MXNET_ASSIGN_REQ_SWITCH(req[0], Req, {
       mxnet_op::Kernel<mxnet_op::op_with_req<mshadow::op::mul, Req>, xpu>::Launch(
         s, inputs[0].Size(), outputs[0].dptr<DType>(), inputs[0].dptr<DType>(), DType(alpha_b));
     });
@@ -100,8 +101,8 @@ struct RandomContrastParam : public dmlc::Parameter<RandomContrastParam> {
   float max_contrast;
   DMLC_DECLARE_PARAMETER(RandomContrastParam) {
     DMLC_DECLARE_FIELD(max_contrast)
-      .set_default(0.0)
-      .describe("Max Contrast.");
+    .set_default(0.0)
+    .describe("Max Contrast.");
   }
 };
 
@@ -139,7 +140,7 @@ static void RandomContrast(const nnvm::NodeAttrs &attrs,
   static const float coeffs0[] = { R2YF, G2YF, B2YF };
 
   MSHADOW_TYPE_SWITCH(outputs[0].type_flag_, DType, {
-    auto input_3d = input.FlatTo3D<xpu, DType>(s);
+    auto input_3d = input.get<xpu, 3, DType>(s);
     DType sum = (DType)0.0;
     for (int c = 0; c < channel; ++c) {
       for (int h = 0; h < hight; ++h) {
@@ -160,36 +161,85 @@ static void RandomContrast(const nnvm::NodeAttrs &attrs,
 
 }
 
+struct RandomSaturationParam : public dmlc::Parameter<RandomSaturationParam> {
+  float max_saturation;
+  DMLC_DECLARE_PARAMETER(RandomSaturationParam) {
+    DMLC_DECLARE_FIELD(max_saturation)
+    .set_default(0.0)
+    .describe("Max Saturation.");
+  }
+};
+
 template<typename xpu>
 static void RandomSaturation(const nnvm::NodeAttrs &attrs,
-  const OpContext &ctx,
-  const std::vector<TBlob> &inputs,
-  const std::vector<OpReqType> &req,
-  const std::vector<TBlob> &outputs) {
+                             const OpContext &ctx,
+                             const std::vector<TBlob> &inputs,
+                             const std::vector<OpReqType> &req,
+                             const std::vector<TBlob> &outputs) {
+  using namespace mshadow;
+  auto input = inputs[0];
+  auto output = outputs[0];
+  int channel = input.shape_[0];
+  int hight = input.shape_[1];
+  int weight = input.shape_[2];
+  Stream<xpu> *s = ctx.get_stream<xpu>();
+  Random<xpu> *prnd = ctx.requested[kRandom].get_random<xpu, real_t>(s);
+  const RandomSaturationParam &param = nnvm::get<RandomSaturationParam>(attrs.parsed);
+  float alpha_s = 1.0 + std::uniform_real_distribution<float>(-param.max_saturation, param.max_saturation)(prnd->GetRndEngine());
+  float alpha_o = 1 - alpha_s;
+  const float R2YF = 0.299f;
+  const float G2YF = 0.587f;
+  const float B2YF = 0.114f;
+  static const float coeffs0[] = { R2YF, G2YF, B2YF };
+
+
+  MSHADOW_TYPE_SWITCH(outputs[0].type_flag_, DType, {
+    MXNET_ASSIGN_REQ_SWITCH(req[0], Req, {
+      auto input_3d =  input.get<xpu, 3, DType>(s);
+      auto output_3d = output.get<xpu, 3, DType>(s);
+      switch (channel) {
+        case 1:
+          Assign(output_3d, Req, input_3d)
+          break;
+        case 3:
+          for (int h = 0; h < hight; ++h) {
+            for (int w = 0; w < weight; ++w) {
+              float gray = input_3d[0][h][w] * R2YF + input_3d[1][h][w] * G2YF + input_3d[2][h][w] * B2YF;
+              Assign(output_3d[0][h][w], Req, DType(gray * alpha_s + input_3d[0][h][w] * alpha_o))
+            }
+          }
+          break;
+        default:
+          LOG(FATAL) << "not support channel" << channel;
+
+      }
+    });
+  });
+
 }
 
 template<typename xpu>
 static void RandomHue(const nnvm::NodeAttrs &attrs,
-  const OpContext &ctx,
-  const std::vector<TBlob> &inputs,
-  const std::vector<OpReqType> &req,
-  const std::vector<TBlob> &outputs) {
+                      const OpContext &ctx,
+                      const std::vector<TBlob> &inputs,
+                      const std::vector<OpReqType> &req,
+                      const std::vector<TBlob> &outputs) {
 }
 
 template<typename xpu>
 static void RandomColorJitter(const nnvm::NodeAttrs &attrs,
-  const OpContext &ctx,
-  const std::vector<TBlob> &inputs,
-  const std::vector<OpReqType> &req,
-  const std::vector<TBlob> &outputs) {
+                              const OpContext &ctx,
+                              const std::vector<TBlob> &inputs,
+                              const std::vector<OpReqType> &req,
+                              const std::vector<TBlob> &outputs) {
 }
 
 template<typename xpu>
 static void RandomLighting(const nnvm::NodeAttrs &attrs,
-  const OpContext &ctx,
-  const std::vector<TBlob> &inputs,
-  const std::vector<OpReqType> &req,
-  const std::vector<TBlob> &outputs) {
+                           const OpContext &ctx,
+                           const std::vector<TBlob> &inputs,
+                           const std::vector<OpReqType> &req,
+                           const std::vector<TBlob> &outputs) {
 }
 
 
diff --git a/src/operator/image/image_random.cc b/src/operator/image/image_random.cc
index ade43d8..32648bb 100644
--- a/src/operator/image/image_random.cc
+++ b/src/operator/image/image_random.cc
@@ -49,5 +49,37 @@ NNVM_REGISTER_OP(_image_random_brightness)
 .add_argument("data", "NDArray-or-Symbol", "The input.")
 .add_arguments(RandomBrightnessParam::__FIELDS__());
 
+DMLC_REGISTER_PARAMETER(RandomContrastParam);
+NNVM_REGISTER_OP(_image_random_contrast)
+.describe(R"code()code" ADD_FILELINE)
+.set_num_inputs(1)
+.set_num_outputs(1)
+.set_attr_parser(ParamParser<RandomContrastParam>)
+.set_attr<FResourceRequest>("FResourceRequest", [](const NodeAttrs& attrs) {
+  return std::vector<ResourceRequest>{ResourceRequest::kRandom};
+})
+.set_attr<nnvm::FInferShape>("FInferShape", ElemwiseShape<1, 1>)
+.set_attr<nnvm::FInferType>("FInferType", ElemwiseType<1, 1>)
+.set_attr<FCompute>("FCompute<cpu>", RandomContrast<cpu>)
+.set_attr<nnvm::FGradient>("FGradient", ElemwiseGradUseNone{ "_copy" })
+.add_argument("data", "NDArray-or-Symbol", "The input.")
+.add_arguments(RandomContrastParam::__FIELDS__());
+
+DMLC_REGISTER_PARAMETER(RandomSaturationParam);
+NNVM_REGISTER_OP(_image_random_saturation)
+.describe(R"code()code" ADD_FILELINE)
+.set_num_inputs(1)
+.set_num_outputs(1)
+.set_attr_parser(ParamParser<RandomSaturationParam>)
+.set_attr<FResourceRequest>("FResourceRequest", [](const NodeAttrs& attrs) {
+  return std::vector<ResourceRequest>{ResourceRequest::kRandom};
+})
+.set_attr<nnvm::FInferShape>("FInferShape", ElemwiseShape<1, 1>)
+.set_attr<nnvm::FInferType>("FInferType", ElemwiseType<1, 1>)
+.set_attr<FCompute>("FCompute<cpu>", RandomSaturation<cpu>)
+.set_attr<nnvm::FGradient>("FGradient", ElemwiseGradUseNone{ "_copy" })
+.add_argument("data", "NDArray-or-Symbol", "The input.")
+.add_arguments(RandomSaturationParam::__FIELDS__());
+
 }
 }
diff --git a/src/operator/mxnet_op.h b/src/operator/mxnet_op.h
index c34d9c9..f6d91dc 100644
--- a/src/operator/mxnet_op.h
+++ b/src/operator/mxnet_op.h
@@ -314,6 +314,12 @@ struct op_with_req {
     KERNEL_ASSIGN(out[i], req, OP::Map(in[i], value));
   }
 
+  /*! \brief input is tensor and two scalar value */
+  template<typename DType>
+  MSHADOW_XINLINE static void Map(int i, DType *out, const DType *in, const DType value_1, const DType value_2) {
+    KERNEL_ASSIGN(out[i], req, OP::Map(in[i], value_1, value_2));
+  }
+
   /*! \brief No inputs (ie fill to constant value) */
   template<typename DType>
   MSHADOW_XINLINE static void Map(int i, DType *out) {

-- 
To stop receiving notification emails like this one, please contact
"commits@mxnet.apache.org" <co...@mxnet.apache.org>.

[incubator-mxnet] 02/08: [WIP]]Vision (#8649)

Posted by jx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jxie pushed a commit to branch vision
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git

commit d1a569c007216199d648d5fb5a8a75022c77d41e
Author: Hu Shiwen <ya...@gmail.com>
AuthorDate: Tue Nov 14 21:11:53 2017 +0800

    [WIP]]Vision (#8649)
    
    * not use opencv
---
 src/operator/image/image_random-inl.h | 93 ++++++++++++++++++++++++-----------
 src/operator/image/image_random.cc    |  3 ++
 2 files changed, 68 insertions(+), 28 deletions(-)

diff --git a/src/operator/image/image_random-inl.h b/src/operator/image/image_random-inl.h
index 027d587..9506607 100644
--- a/src/operator/image/image_random-inl.h
+++ b/src/operator/image/image_random-inl.h
@@ -29,7 +29,7 @@
 #include <mxnet/base.h>
 #include <opencv2/opencv.hpp>
 #include <opencv2/core/mat.hpp>
-#include "mxnet/op_attr_types.h"
+#include "../mxnet_op.h"
 #include "image_common.h"
 
 
@@ -44,6 +44,7 @@ struct RandomBrightnessParam : public dmlc::Parameter<RandomBrightnessParam> {
   }
 };
 
+enum ImageRandomResource { kRandom };
 
 template<typename xpu>
 static void RandomBrightness(const nnvm::NodeAttrs &attrs,
@@ -51,44 +52,80 @@ static void RandomBrightness(const nnvm::NodeAttrs &attrs,
                              const std::vector<TBlob> &inputs,
                              const std::vector<OpReqType> &req,
                              const std::vector<TBlob> &outputs) {
+  using namespace mshadow;
   auto input = inputs[0];
   auto output = outputs[0];
-  int hight = input.shape_[0];
-  int weight = input.shape_[1];
-  int channel = input.shape_[2];
-
-  auto input_mat = mat_convert(input, hight, weight, channel);
-  auto output_mat = mat_convert(output, hight, weight, channel);
-  //input_mat.convertTo(output_mat, -1, 1/255.0, 0);
-  std::default_random_engine generator;
+  int channel = input.shape_[0];
+  int hight = input.shape_[1];
+  int weight = input.shape_[2];
+  Stream<xpu> *s = ctx.get_stream<xpu>();
+  Random<xpu> *prnd = ctx.requested[kRandom].get_random<xpu, real_t>(s);
+
   const RandomBrightnessParam &param = nnvm::get<RandomBrightnessParam>(attrs.parsed);
-  float alpha_b = 1.0 + std::uniform_real_distribution<float>(-param.max_brightness, param.max_brightness)(generator);
-  output_mat.convertTo(output_mat, -1, alpha_b, 0);
+  float alpha_b = 1.0 + std::uniform_real_distribution<float>(-param.max_brightness, param.max_brightness)(prnd->GetRndEngine());
+  MSHADOW_TYPE_SWITCH(outputs[0].type_flag_, DType, {
+    MXNET_ASSIGN_REQ_SWITCH(req[0], Req,{
+      mxnet_op::Kernel<mxnet_op::op_with_req<mshadow::op::mul, Req>, xpu>::Launch(
+        s, inputs[0].Size(), outputs[0].dptr<DType>(), inputs[0].dptr<DType>(), DType(alpha_b));
+    });
+  });
+
 }
 
 
+/*! \brief mul_add operator */
+struct mul_add {
+  /*! \brief map a, b, c to result using defined operation */
+  template<typename DType>
+  MSHADOW_XINLINE static DType Map(DType a, DType b, DType c) {
+    return a * b + c;
+  }
+};
+
+
 template<typename xpu>
 static void RandomContrast(const nnvm::NodeAttrs &attrs,
-  const OpContext &ctx,
-  const std::vector<TBlob> &inputs,
-  const std::vector<OpReqType> &req,
-  const std::vector<TBlob> &outputs) {
+                           const OpContext &ctx,
+                           const std::vector<TBlob> &inputs,
+                           const std::vector<OpReqType> &req,
+                           const std::vector<TBlob> &outputs) {
+  using namespace mshadow;
   auto input = inputs[0];
   auto output = outputs[0];
-  int hight = input.shape_[0];
-  int weight = input.shape_[1];
-  int channel = input.shape_[2];
-
-  auto input_mat = mat_convert(input, hight, weight, channel);
-  auto output_mat = mat_convert(output, hight, weight, channel);
-  //input_mat.convertTo(output_mat, -1, 1/255.0, 0);
-  std::default_random_engine generator;
+  int channel = input.shape_[0];
+  int hight = input.shape_[1];
+  int weight = input.shape_[2];
+  Stream<xpu> *s = ctx.get_stream<xpu>();
+  Random<xpu> *prnd = ctx.requested[kRandom].get_random<xpu, real_t>(s);
+
+
   const RandomBrightnessParam &param = nnvm::get<RandomBrightnessParam>(attrs.parsed);
-  float alpha_c = 1.0 + std::uniform_real_distribution<float>(-param.max_brightness, param.max_brightness)(generator);
-  cv::Mat temp_;
-  cv::cvtColor(input_mat, temp_,  CV_RGB2GRAY);
-  float gray_mean = cv::mean(temp_)[0];
-  input_mat.convertTo(output_mat, -1, alpha_c, (1 - alpha_c) * gray_mean);
+  float alpha_c = 1.0 + std::uniform_real_distribution<float>(-param.max_brightness, param.max_brightness)(prnd->GetRndEngine());
+
+  const float R2YF = 0.299f;
+  const float G2YF = 0.587f;
+  const float B2YF = 0.114f;
+  static const float coeffs0[] = { R2YF, G2YF, B2YF };
+
+  MSHADOW_TYPE_SWITCH(outputs[0].type_flag_, DType, {
+    auto input_3d = input.FlatTo3D<xpu, DType>(s);
+    DType sum = (DType)0.0;
+    for (int c = 0; c < channel; ++c) {
+      for (int h = 0; h < hight; ++h) {
+        for (int w = 0; w < weight; ++w) {
+          sum += input_3d[c][h][w] * coeffs0[c];
+        }
+      }
+    }
+    float gray_mean = sum / (float)(hight * weight);
+    float beta = (1 - alpha_c) * gray_mean;
+
+    MXNET_ASSIGN_REQ_SWITCH(req[0], Req, {
+      mxnet_op::Kernel<mxnet_op::op_with_req<mul_add, Req>, xpu>::Launch(
+        s, inputs[0].Size(), outputs[0].dptr<DType>(), inputs[0].dptr<DType>(), DType(alpha_c), DType(beta));
+    });
+
+  });
 
 }
 
diff --git a/src/operator/image/image_random.cc b/src/operator/image/image_random.cc
index 3777e43..ade43d8 100644
--- a/src/operator/image/image_random.cc
+++ b/src/operator/image/image_random.cc
@@ -39,6 +39,9 @@ NNVM_REGISTER_OP(_image_random_brightness)
 .set_num_inputs(1)
 .set_num_outputs(1)
 .set_attr_parser(ParamParser<RandomBrightnessParam>)
+.set_attr<FResourceRequest>("FResourceRequest", [](const NodeAttrs& attrs) { 
+  return std::vector<ResourceRequest>{ResourceRequest::kRandom}; 
+})
 .set_attr<nnvm::FInferShape>("FInferShape", ElemwiseShape<1, 1>)
 .set_attr<nnvm::FInferType>("FInferType", ElemwiseType<1, 1>)
 .set_attr<FCompute>("FCompute<cpu>", RandomBrightness<cpu>)

-- 
To stop receiving notification emails like this one, please contact
"commits@mxnet.apache.org" <co...@mxnet.apache.org>.

[incubator-mxnet] 06/08: Add Gluon data transform (#8672)

Posted by jx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jxie pushed a commit to branch vision
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git

commit e741d8f290e9f490c2db0b08e8b5021db641535b
Author: Eric Junyuan Xie <pi...@users.noreply.github.com>
AuthorDate: Wed Nov 15 15:16:51 2017 -0800

    Add Gluon data transform (#8672)
    
    * fix
    
    * fix
    
    * fix
---
 python/mxnet/gluon/data/dataset.py                 |  43 +++++-
 python/mxnet/gluon/data/vision/__init__.py         |  22 +++
 .../gluon/data/{vision.py => vision/datasets.py}   |   0
 python/mxnet/gluon/data/vision/transforms.py       | 153 +++++++++++++++++++++
 src/operator/image/image_aug_op.h                  |  70 ++++++++++
 src/operator/image/image_random.cc                 |   4 +-
 6 files changed, 289 insertions(+), 3 deletions(-)

diff --git a/python/mxnet/gluon/data/dataset.py b/python/mxnet/gluon/data/dataset.py
index 059c2a6..740a2a4 100644
--- a/python/mxnet/gluon/data/dataset.py
+++ b/python/mxnet/gluon/data/dataset.py
@@ -18,12 +18,14 @@
 # coding: utf-8
 # pylint: disable=
 """Dataset container."""
-__all__ = ['Dataset', 'ArrayDataset', 'RecordFileDataset']
+__all__ = ['Dataset', 'SimpleDataset', 'ArrayDataset', 'LabeledDataset',
+           'RecordFileDataset']
 
 import os
 
 from ... import recordio, ndarray
 
+
 class Dataset(object):
     """Abstract dataset class. All datasets should have this interface.
 
@@ -38,6 +40,45 @@ class Dataset(object):
     def __len__(self):
         raise NotImplementedError
 
+    def transform(self, fn, lazy=True):
+        trans = _LazyTransformDataset(self, fn)
+        if lazy:
+            return trans
+        return SimpleDataset([i for i in trans])
+
+    def transform_first(self, fn, lazy=True):
+        def base_fn(x, *args):
+            if args:
+                return (fn(x),) + args
+            return fn(x)
+        return self.transform(base_fn, lazy)
+
+
+class SimpleDataset(Dataset):
+    def __init__(self, data):
+        self._data = data
+
+    def __len__(self):
+        return len(self._data)
+
+    def __getitem__(self, idx):
+        return self._data[idx]
+
+
+class _LazyTransformDataset(Dataset):
+    def __init__(self, data, fn):
+        self._data = data
+        self._fn = fn
+
+    def __len__(self):
+        return len(self._data)
+
+    def __getitem__(self, idx):
+        item = self._data[idx]
+        if isinstance(item, tuple):
+            return self._fn(*item)
+        return self._fn(item)
+
 
 class ArrayDataset(Dataset):
     """A dataset of multiple arrays.
diff --git a/python/mxnet/gluon/data/vision/__init__.py b/python/mxnet/gluon/data/vision/__init__.py
new file mode 100644
index 0000000..8837984
--- /dev/null
+++ b/python/mxnet/gluon/data/vision/__init__.py
@@ -0,0 +1,22 @@
+# 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
+
+from .datasets import *
+
+from . import transforms
diff --git a/python/mxnet/gluon/data/vision.py b/python/mxnet/gluon/data/vision/datasets.py
similarity index 100%
rename from python/mxnet/gluon/data/vision.py
rename to python/mxnet/gluon/data/vision/datasets.py
diff --git a/python/mxnet/gluon/data/vision/transforms.py b/python/mxnet/gluon/data/vision/transforms.py
new file mode 100644
index 0000000..fa7c0f2
--- /dev/null
+++ b/python/mxnet/gluon/data/vision/transforms.py
@@ -0,0 +1,153 @@
+# 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
+
+from .. import dataset
+from ...block import Block, HybridBlock
+from ...nn import Sequential, HybridSequential
+from .... import ndarray, initializer
+
+
+class Compose(Sequential):
+    def __init__(self, transforms):
+        super(Compose, self).__init__()
+        transforms.append(None)
+        hybrid = []
+        for i in transforms:
+            if isinstance(i, HybridBlock):
+                hybrid.append(i)
+                continue
+            elif len(hybrid) == 1:
+                self.register_child(hybrid[0])
+            elif len(hybrid) > 1:
+                hblock = HybridSequential()
+                for j in hybrid:
+                    hblock.add(j)
+                self.register_child(hblock)
+            if i is not None:
+                self.register_child(i)
+        self.hybridize()
+
+
+class Cast(HybridBlock):
+    def __init__(self, dtype='float32'):
+        super(Cast, self).__init__()
+        self._dtype = dtype
+
+    def hybrid_forward(self, F, x):
+        return F.cast(x, self._dtype)
+
+
+class ToTensor(HybridBlock):
+    def __init__(self):
+        super(ToTensor, self).__init__()
+
+    def hybrid_forward(self, F, x):
+        return F.cast(x, 'float32').transpose((2, 0, 1))
+
+
+class Normalize(HybridBlock):
+    def __init__(self, mean, std):
+        super(Normalize, self).__init__()
+        self._mean = mean
+        self._std = std
+
+    def hybrid_forward(self, F, x):
+        return F.image.normalize(x, self._mean, self._std)
+
+
+class RandomResizedCrop(HybridBlock):
+    def __init__(self, size, area=(0.08, 1.0), ratio=(3.0/4.0, 4.0/3.0),
+                 interpolation=2):
+        super(RandomResizedCrop, self).__init__()
+        self._args = (size, area, ratio, interpolation)
+
+    def hybrid_forward(self, F, x):
+        return F.image.random_resized_crop(x, *self._args)
+
+
+class CenterCrop(HybridBlock):
+    def __init__(self, size):
+        super(CenterCrop, self).__init__()
+        self._size = size
+
+    def hybrid_forward(self, F, x):
+        return F.image.center_crop(x, size)
+
+
+class Resize(HybridBlock):
+    def __init__(self, size, interpolation=2):
+        super(Resize, self).__init__()
+        self._args = (size, interpolation)
+
+    def hybrid_forward(self, F, x):
+        return F.image.resize(x, *self._args)
+
+
+class RandomFlip(HybridBlock):
+    def __init__(self, axis=1):
+        super(RandomFlip, self).__init__()
+        self._axis = axis
+
+    def hybrid_forward(self, F, x):
+        return F.image.random_flip(x, self._axis)
+
+
+class RandomBrightness(HybridBlock):
+    def __init__(self, max_brightness):
+        super(RandomBrightness, self).__init__()
+        self._max_brightness = max_brightness
+
+    def hybrid_forward(self, F, x):
+        return F.image.random_brightness(x, self._max_brightness)
+
+
+class RandomContrast(HybridBlock):
+    def __init__(self, max_contrast):
+        super(RandomContrast, self).__init__()
+        self._max_contrast = max_contrast
+
+    def hybrid_forward(self, F, x):
+        return F.image.random_contrast(x, self._max_contrast)
+
+
+class RandomSaturation(HybridBlock):
+    def __init__(self, max_saturation):
+        super(RandomSaturation, self).__init__()
+        self._max_saturation = max_saturation
+
+    def hybrid_forward(self, F, x):
+        return F.image.random_saturation(x, self._max_saturation)
+
+
+class RandomHue(HybridBlock):
+    def __init__(self, max_hue):
+        super(RandomHue, self).__init__()
+        self._max_hue = max_hue
+
+    def hybrid_forward(self, F, x):
+        return F.image.random_hue(x, self._max_hue)
+
+
+class RandomColorJitter(HybridBlock):
+    def __init__(self, max_brightness=0, max_contrast=0, max_saturation=0, max_hue=0):
+        super(RandomColorJitter, self).__init__()
+        self._args = (max_brightness, max_contrast, max_saturation, max_hue)
+
+    def hybrid_forward(self, F, x):
+        return F.image.random_color_jitter(x, *self._args)
diff --git a/src/operator/image/image_aug_op.h b/src/operator/image/image_aug_op.h
new file mode 100644
index 0000000..40315ec
--- /dev/null
+++ b/src/operator/image/image_aug_op.h
@@ -0,0 +1,70 @@
+/*
+ * 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.
+ */
+
+#ifndef MXNET_OPERATOR_IMAGE_IMAGE_AUG_OP_H_
+#define MXNET_OPERATOR_IMAGE_IMAGE_AUG_OP_H_
+
+#include <mxnet/operator_util.h>
+#include <vector>
+#include <utility>
+#include <algorithm>
+#include "../mshadow_op.h"
+#include "../elemwise_op_common.h"
+#include "../mxnet_op.h"
+
+namespace mxnet {
+namespace op {
+
+struct NormalizeParam : public dmlc::Parameter<NormalizeParam> {
+  nnvm::Tuple<float> mean, std;
+  DMLC_DECLARE_PARAMETER(NormalizeParam) {
+    DMLC_DECLARE_FIELD(mean).set_default(nnvm::Tuple<float>({0.f}))
+      .describe("");
+    DMLC_DECLARE_FIELD(std).set_default(nnvm::Tuple<float>({1.f}))
+      .describe("");
+  }
+};
+
+
+void NormalizeCompute(const nnvm::NodeAttrs& attrs,
+                      const OpContext& ctx,
+                      const std::vector<NDArray>& inputs,
+                      const std::vector<OpReqType>& req,
+                      const std::vector<NDArray>& outputs) {
+  using namespace mxnet_op;
+  const auto& params = dmlc::get<NormalizeParam>(attrs.parsed);
+  CHECK_NE(req[0], kAddTo);
+  MSHADOW_TYPE_SWITCH(inputs[0].type_flag_, DType, {
+    auto num_channel = inputs[0].shape_[0];
+    auto size = inputs[0].Size(1, inputs[0].ndim());
+    nnvm::Tuple<DType> mean(params.mean.begin(), params.mean.end());
+    nnvm::Tuple<DType> std(params.std.begin(), params.std.end());
+    DType* src = inputs[0].dptr<DType>();
+    DType* dst = outputs[0].dptr<DType>();
+    for (int i = 0; i < num_channel; ++i) {
+      for (int j = 0; j < size; ++j, ++out, ++src) {
+        *out = (*src - mean[i]) / std[i];
+      }
+    }
+  });
+}
+
+}  // namespace op
+}  // namespace mxnet
+#endif  // MXNET_OPERATOR_IMAGE_IMAGE_AUG_OP_H_
diff --git a/src/operator/image/image_random.cc b/src/operator/image/image_random.cc
index 83abc17..63f7904 100644
--- a/src/operator/image/image_random.cc
+++ b/src/operator/image/image_random.cc
@@ -25,8 +25,8 @@
 
 #include <mxnet/base.h>
 #include "./image_random-inl.h"
-#include "../../operator/operator_common.h"
-#include "../../operator/elemwise_op_common.h"
+#include "../operator_common.h"
+#include "../elemwise_op_common.h"
 
 
 

-- 
To stop receiving notification emails like this one, please contact
"commits@mxnet.apache.org" <co...@mxnet.apache.org>.

[incubator-mxnet] 03/08: add stub (#8650)

Posted by jx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jxie pushed a commit to branch vision
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git

commit 5d3460d33b45af04048fbd7f9657b98d75707c0c
Author: Hu Shiwen <ya...@gmail.com>
AuthorDate: Tue Nov 14 21:28:34 2017 +0800

    add stub (#8650)
    
    * add stub
---
 src/operator/image/image_random-inl.h | 79 +++++++++++++++++++++++++++++++----
 1 file changed, 72 insertions(+), 7 deletions(-)

diff --git a/src/operator/image/image_random-inl.h b/src/operator/image/image_random-inl.h
index 9506607..1281a71 100644
--- a/src/operator/image/image_random-inl.h
+++ b/src/operator/image/image_random-inl.h
@@ -35,17 +35,41 @@
 
 namespace mxnet {
 namespace op {
+
+
+enum ImageRandomResource { kRandom };
+
+template<typename xpu>
+static void RandomFlip(const nnvm::NodeAttrs &attrs,
+  const OpContext &ctx,
+  const std::vector<TBlob> &inputs,
+  const std::vector<OpReqType> &req,
+  const std::vector<TBlob> &outputs) {
+}
+template<typename xpu>
+static void ToTensor(const nnvm::NodeAttrs &attrs,
+  const OpContext &ctx,
+  const std::vector<TBlob> &inputs,
+  const std::vector<OpReqType> &req,
+  const std::vector<TBlob> &outputs) {
+}
+template<typename xpu>
+static void Normalize(const nnvm::NodeAttrs &attrs,
+  const OpContext &ctx,
+  const std::vector<TBlob> &inputs,
+  const std::vector<OpReqType> &req,
+  const std::vector<TBlob> &outputs) {
+}
+
 struct RandomBrightnessParam : public dmlc::Parameter<RandomBrightnessParam> {
   float max_brightness;
   DMLC_DECLARE_PARAMETER(RandomBrightnessParam) {
     DMLC_DECLARE_FIELD(max_brightness)
-    .set_default(0.0)
-    .describe("Max Contrast.");
+      .set_default(0.0)
+      .describe("Max Brightness.");
   }
 };
 
-enum ImageRandomResource { kRandom };
-
 template<typename xpu>
 static void RandomBrightness(const nnvm::NodeAttrs &attrs,
                              const OpContext &ctx,
@@ -72,6 +96,14 @@ static void RandomBrightness(const nnvm::NodeAttrs &attrs,
 
 }
 
+struct RandomContrastParam : public dmlc::Parameter<RandomContrastParam> {
+  float max_contrast;
+  DMLC_DECLARE_PARAMETER(RandomContrastParam) {
+    DMLC_DECLARE_FIELD(max_contrast)
+      .set_default(0.0)
+      .describe("Max Contrast.");
+  }
+};
 
 /*! \brief mul_add operator */
 struct mul_add {
@@ -82,7 +114,6 @@ struct mul_add {
   }
 };
 
-
 template<typename xpu>
 static void RandomContrast(const nnvm::NodeAttrs &attrs,
                            const OpContext &ctx,
@@ -99,8 +130,8 @@ static void RandomContrast(const nnvm::NodeAttrs &attrs,
   Random<xpu> *prnd = ctx.requested[kRandom].get_random<xpu, real_t>(s);
 
 
-  const RandomBrightnessParam &param = nnvm::get<RandomBrightnessParam>(attrs.parsed);
-  float alpha_c = 1.0 + std::uniform_real_distribution<float>(-param.max_brightness, param.max_brightness)(prnd->GetRndEngine());
+  const RandomContrastParam &param = nnvm::get<RandomContrastParam>(attrs.parsed);
+  float alpha_c = 1.0 + std::uniform_real_distribution<float>(-param.max_contrast, param.max_contrast)(prnd->GetRndEngine());
 
   const float R2YF = 0.299f;
   const float G2YF = 0.587f;
@@ -129,6 +160,40 @@ static void RandomContrast(const nnvm::NodeAttrs &attrs,
 
 }
 
+template<typename xpu>
+static void RandomSaturation(const nnvm::NodeAttrs &attrs,
+  const OpContext &ctx,
+  const std::vector<TBlob> &inputs,
+  const std::vector<OpReqType> &req,
+  const std::vector<TBlob> &outputs) {
+}
+
+template<typename xpu>
+static void RandomHue(const nnvm::NodeAttrs &attrs,
+  const OpContext &ctx,
+  const std::vector<TBlob> &inputs,
+  const std::vector<OpReqType> &req,
+  const std::vector<TBlob> &outputs) {
+}
+
+template<typename xpu>
+static void RandomColorJitter(const nnvm::NodeAttrs &attrs,
+  const OpContext &ctx,
+  const std::vector<TBlob> &inputs,
+  const std::vector<OpReqType> &req,
+  const std::vector<TBlob> &outputs) {
+}
+
+template<typename xpu>
+static void RandomLighting(const nnvm::NodeAttrs &attrs,
+  const OpContext &ctx,
+  const std::vector<TBlob> &inputs,
+  const std::vector<OpReqType> &req,
+  const std::vector<TBlob> &outputs) {
+}
+
+
+
 
 } // namespace op
 } // namespace mxnet

-- 
To stop receiving notification emails like this one, please contact
"commits@mxnet.apache.org" <co...@mxnet.apache.org>.

[incubator-mxnet] 07/08: image to_tensor (#8691)

Posted by jx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jxie pushed a commit to branch vision
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git

commit 303e8821d858f44da3b148e3535a94d3b59e1549
Author: Yizhi Liu <ja...@gmail.com>
AuthorDate: Thu Nov 16 23:01:37 2017 -0800

    image to_tensor (#8691)
---
 src/operator/image/image_common.h     |  7 +--
 src/operator/image/image_random-inl.h | 92 +++++++++++++++++++++++++++--------
 src/operator/image/image_random.cc    | 21 ++++++--
 src/operator/mxnet_op.h               |  3 +-
 4 files changed, 95 insertions(+), 28 deletions(-)

diff --git a/src/operator/image/image_common.h b/src/operator/image/image_common.h
index 7cf3f96..3b6b8e3 100644
--- a/src/operator/image/image_common.h
+++ b/src/operator/image/image_common.h
@@ -81,8 +81,9 @@ static cv::Mat mat_convert(TBlob input, int hight, int weight, int channel) {
   }
   return m;
 }
-} // namespace op
-} // namespace mxnet
+}  // namespace op
+}  // namespace mxnet
 
 
-#endif // MXNET_OPERATOR_IMAGE_IMAGE_COMMON_H_
\ No newline at end of file
+#endif  // MXNET_OPERATOR_IMAGE_IMAGE_COMMON_H_
+
diff --git a/src/operator/image/image_random-inl.h b/src/operator/image/image_random-inl.h
index 8a3acf6..c50ecb7 100644
--- a/src/operator/image/image_random-inl.h
+++ b/src/operator/image/image_random-inl.h
@@ -25,15 +25,14 @@
 #ifndef MXNET_OPERATOR_IMAGE_IMAGE_RANDOM_INL_H_
 #define MXNET_OPERATOR_IMAGE_IMAGE_RANDOM_INL_H_
 
-#include <vector>
 #include <mxnet/base.h>
+#include <vector>
 #include <opencv2/opencv.hpp>
 #include <opencv2/core/mat.hpp>
 #include "../mxnet_op.h"
 #include "image_common.h"
 #include "../../operator/operator_common.h"
 
-
 namespace mxnet {
 namespace op {
 
@@ -47,13 +46,66 @@ static void RandomFlip(const nnvm::NodeAttrs &attrs,
                        const std::vector<OpReqType> &req,
                        const std::vector<TBlob> &outputs) {
 }
+
+inline bool ToTensorType(const nnvm::NodeAttrs& attrs,
+                         std::vector<int> *in_attrs,
+                         std::vector<int> *out_attrs) {
+  CHECK_EQ(in_attrs->size(), 1U);
+  CHECK_EQ(out_attrs->size(), 1U);
+  CHECK_EQ((*in_attrs)[0], mshadow::kUint8)
+    << "`to_tensor` only supports uint8 input";
+  TYPE_ASSIGN_CHECK(*out_attrs, 0, mshadow::kFloat32);
+  return (*in_attrs)[0] != -1;
+}
+
+inline bool ToTensorShape(const nnvm::NodeAttrs& attrs,
+                          std::vector<TShape> *in_attrs,
+                          std::vector<TShape> *out_attrs) {
+  CHECK_EQ(in_attrs->size(), 1U);
+  CHECK_EQ(out_attrs->size(), 1U);
+  TShape &shp = (*in_attrs)[0];
+  CHECK_EQ(shp.ndim(), 3U) << "`to_tensor` only supports 3 dimensions";
+  TShape ret(3);
+  ret[0] = shp[2];
+  ret[1] = shp[0];
+  ret[2] = shp[1];
+  SHAPE_ASSIGN_CHECK(*out_attrs, 0, ret);
+  return true;
+}
+
 template<typename xpu>
 static void ToTensor(const nnvm::NodeAttrs &attrs,
                      const OpContext &ctx,
                      const std::vector<TBlob> &inputs,
                      const std::vector<OpReqType> &req,
                      const std::vector<TBlob> &outputs) {
+  auto input = inputs[0];
+  auto output = outputs[0];
+
+  int height = input.shape_[0];
+  int weight = input.shape_[1];
+  int channel = input.shape_[2];
+
+  typedef float   DstDType;
+  typedef uint8_t SrcDType;
+
+  CHECK_EQ(req[0], kWriteTo)
+    << "`to_tensor` does not support inplace";
+
+  mshadow::Stream<xpu> *s = ctx.get_stream<xpu>();
+  MXNET_ASSIGN_REQ_SWITCH(req[0], Req, {
+    auto input_3d =  input.get<xpu, 3, SrcDType>(s);
+    auto output_3d = output.get<xpu, 3, DstDType>(s);
+    for (int h = 0; h < height; ++h) {
+      for (int w = 0; w < weight; ++w) {
+        for (int c = 0; c < channel; ++c) {
+          Assign(output_3d[c][h][w], Req, DstDType(input_3d[h][w][c] / 255.0));
+        }
+      }
+    }
+  });
 }
+
 template<typename xpu>
 static void Normalize(const nnvm::NodeAttrs &attrs,
                       const OpContext &ctx,
@@ -81,20 +133,20 @@ static void RandomBrightness(const nnvm::NodeAttrs &attrs,
   auto input = inputs[0];
   auto output = outputs[0];
   int channel = input.shape_[0];
-  int hight = input.shape_[1];
+  int height = input.shape_[1];
   int weight = input.shape_[2];
   Stream<xpu> *s = ctx.get_stream<xpu>();
   Random<xpu> *prnd = ctx.requested[kRandom].get_random<xpu, real_t>(s);
 
   const RandomBrightnessParam &param = nnvm::get<RandomBrightnessParam>(attrs.parsed);
-  float alpha_b = 1.0 + std::uniform_real_distribution<float>(-param.max_brightness, param.max_brightness)(prnd->GetRndEngine());
+  float alpha_b = 1.0 + std::uniform_real_distribution<float>(
+    -param.max_brightness, param.max_brightness)(prnd->GetRndEngine());
   MSHADOW_TYPE_SWITCH(outputs[0].type_flag_, DType, {
     MXNET_ASSIGN_REQ_SWITCH(req[0], Req, {
       mxnet_op::Kernel<mxnet_op::op_with_req<mshadow::op::mul, Req>, xpu>::Launch(
         s, inputs[0].Size(), outputs[0].dptr<DType>(), inputs[0].dptr<DType>(), DType(alpha_b));
     });
   });
-
 }
 
 struct RandomContrastParam : public dmlc::Parameter<RandomContrastParam> {
@@ -125,14 +177,15 @@ static void RandomContrast(const nnvm::NodeAttrs &attrs,
   auto input = inputs[0];
   auto output = outputs[0];
   int channel = input.shape_[0];
-  int hight = input.shape_[1];
+  int height = input.shape_[1];
   int weight = input.shape_[2];
   Stream<xpu> *s = ctx.get_stream<xpu>();
   Random<xpu> *prnd = ctx.requested[kRandom].get_random<xpu, real_t>(s);
 
 
   const RandomContrastParam &param = nnvm::get<RandomContrastParam>(attrs.parsed);
-  float alpha_c = 1.0 + std::uniform_real_distribution<float>(-param.max_contrast, param.max_contrast)(prnd->GetRndEngine());
+  float alpha_c = 1.0 + std::uniform_real_distribution<float>(
+    -param.max_contrast, param.max_contrast)(prnd->GetRndEngine());
 
   const float R2YF = 0.299f;
   const float G2YF = 0.587f;
@@ -143,22 +196,21 @@ static void RandomContrast(const nnvm::NodeAttrs &attrs,
     auto input_3d = input.get<xpu, 3, DType>(s);
     DType sum = (DType)0.0;
     for (int c = 0; c < channel; ++c) {
-      for (int h = 0; h < hight; ++h) {
+      for (int h = 0; h < height; ++h) {
         for (int w = 0; w < weight; ++w) {
           sum += input_3d[c][h][w] * coeffs0[c];
         }
       }
     }
-    float gray_mean = sum / (float)(hight * weight);
+    float gray_mean = sum / static_cast<float>(height * weight);
     float beta = (1 - alpha_c) * gray_mean;
 
     MXNET_ASSIGN_REQ_SWITCH(req[0], Req, {
       mxnet_op::Kernel<mxnet_op::op_with_req<mul_add, Req>, xpu>::Launch(
-        s, inputs[0].Size(), outputs[0].dptr<DType>(), inputs[0].dptr<DType>(), DType(alpha_c), DType(beta));
+        s, inputs[0].Size(), outputs[0].dptr<DType>(),
+        inputs[0].dptr<DType>(), DType(alpha_c), DType(beta));
     });
-
   });
-
 }
 
 struct RandomSaturationParam : public dmlc::Parameter<RandomSaturationParam> {
@@ -180,12 +232,13 @@ static void RandomSaturation(const nnvm::NodeAttrs &attrs,
   auto input = inputs[0];
   auto output = outputs[0];
   int channel = input.shape_[0];
-  int hight = input.shape_[1];
+  int height = input.shape_[1];
   int weight = input.shape_[2];
   Stream<xpu> *s = ctx.get_stream<xpu>();
   Random<xpu> *prnd = ctx.requested[kRandom].get_random<xpu, real_t>(s);
   const RandomSaturationParam &param = nnvm::get<RandomSaturationParam>(attrs.parsed);
-  float alpha_s = 1.0 + std::uniform_real_distribution<float>(-param.max_saturation, param.max_saturation)(prnd->GetRndEngine());
+  float alpha_s = 1.0 + std::uniform_real_distribution<float>(
+    -param.max_saturation, param.max_saturation)(prnd->GetRndEngine());
   float alpha_o = 1 - alpha_s;
   const float R2YF = 0.299f;
   const float G2YF = 0.587f;
@@ -202,20 +255,19 @@ static void RandomSaturation(const nnvm::NodeAttrs &attrs,
           Assign(output_3d, Req, input_3d)
           break;
         case 3:
-          for (int h = 0; h < hight; ++h) {
+          for (int h = 0; h < height; ++h) {
             for (int w = 0; w < weight; ++w) {
-              float gray = input_3d[0][h][w] * R2YF + input_3d[1][h][w] * G2YF + input_3d[2][h][w] * B2YF;
+              float gray =
+                input_3d[0][h][w] * R2YF + input_3d[1][h][w] * G2YF + input_3d[2][h][w] * B2YF;
               Assign(output_3d[0][h][w], Req, DType(gray * alpha_s + input_3d[0][h][w] * alpha_o))
             }
           }
           break;
         default:
           LOG(FATAL) << "not support channel" << channel;
-
       }
     });
   });
-
 }
 
 template<typename xpu>
@@ -245,7 +297,7 @@ static void RandomLighting(const nnvm::NodeAttrs &attrs,
 
 
 
-} // namespace op
-} // namespace mxnet
+}  // namespace op
+}  // namespace mxnet
 
 #endif  // MXNET_OPERATOR_IMAGE_IMAGE_RANDOM_INL_H_
diff --git a/src/operator/image/image_random.cc b/src/operator/image/image_random.cc
index 63f7904..26fa843 100644
--- a/src/operator/image/image_random.cc
+++ b/src/operator/image/image_random.cc
@@ -33,14 +33,27 @@
 namespace mxnet {
 namespace op {
 
+NNVM_REGISTER_OP(_image_to_tensor)
+.describe(R"code()code" ADD_FILELINE)
+.set_num_inputs(1)
+.set_num_outputs(1)
+.set_attr<FResourceRequest>("FResourceRequest", [](const NodeAttrs& attrs) {
+  return std::vector<ResourceRequest>{ResourceRequest::kRandom};
+})
+.set_attr<nnvm::FInferShape>("FInferShape", ToTensorShape)
+.set_attr<nnvm::FInferType>("FInferType", ToTensorType)
+.set_attr<FCompute>("FCompute<cpu>", ToTensor<cpu>)
+.set_attr<nnvm::FGradient>("FGradient", ElemwiseGradUseNone{ "_copy" })
+.add_argument("data", "NDArray-or-Symbol", "The input.");
+
 DMLC_REGISTER_PARAMETER(RandomBrightnessParam);
 NNVM_REGISTER_OP(_image_random_brightness)
 .describe(R"code()code" ADD_FILELINE)
 .set_num_inputs(1)
 .set_num_outputs(1)
 .set_attr_parser(ParamParser<RandomBrightnessParam>)
-.set_attr<FResourceRequest>("FResourceRequest", [](const NodeAttrs& attrs) { 
-  return std::vector<ResourceRequest>{ResourceRequest::kRandom}; 
+.set_attr<FResourceRequest>("FResourceRequest", [](const NodeAttrs& attrs) {
+  return std::vector<ResourceRequest>{ResourceRequest::kRandom};
 })
 .set_attr<nnvm::FInferShape>("FInferShape", ElemwiseShape<1, 1>)
 .set_attr<nnvm::FInferType>("FInferType", ElemwiseType<1, 1>)
@@ -81,5 +94,5 @@ NNVM_REGISTER_OP(_image_random_saturation)
 .add_argument("data", "NDArray-or-Symbol", "The input.")
 .add_arguments(RandomSaturationParam::__FIELDS__());
 
-}
-}
+}  // namespace op
+}  // namespace mxnet
diff --git a/src/operator/mxnet_op.h b/src/operator/mxnet_op.h
index f6d91dc..707d0fa 100644
--- a/src/operator/mxnet_op.h
+++ b/src/operator/mxnet_op.h
@@ -316,7 +316,8 @@ struct op_with_req {
 
   /*! \brief input is tensor and two scalar value */
   template<typename DType>
-  MSHADOW_XINLINE static void Map(int i, DType *out, const DType *in, const DType value_1, const DType value_2) {
+  MSHADOW_XINLINE static void Map(int i, DType *out, const DType *in,
+                                  const DType value_1, const DType value_2) {
     KERNEL_ASSIGN(out[i], req, OP::Map(in[i], value_1, value_2));
   }
 

-- 
To stop receiving notification emails like this one, please contact
"commits@mxnet.apache.org" <co...@mxnet.apache.org>.

[incubator-mxnet] 08/08: [Image OP] Normalize (#8731)

Posted by jx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jxie pushed a commit to branch vision
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git

commit db2f1f443050585f6a939c412eb8491c5ec3e1b1
Author: Yizhi Liu <ja...@gmail.com>
AuthorDate: Mon Nov 20 11:57:22 2017 -0800

    [Image OP] Normalize (#8731)
    
    * image normalize op
    
    * image normalize op param check
---
 src/operator/image/image_random-inl.h | 93 +++++++++++++++++++++++++++++++++++
 src/operator/image/image_random.cc    | 34 ++++++++++++-
 2 files changed, 125 insertions(+), 2 deletions(-)

diff --git a/src/operator/image/image_random-inl.h b/src/operator/image/image_random-inl.h
index c50ecb7..6f9cdc0 100644
--- a/src/operator/image/image_random-inl.h
+++ b/src/operator/image/image_random-inl.h
@@ -106,12 +106,105 @@ static void ToTensor(const nnvm::NodeAttrs &attrs,
   });
 }
 
+struct NormalizeParam : public dmlc::Parameter<NormalizeParam> {
+  nnvm::Tuple<float> mean;
+  nnvm::Tuple<float> std;
+  DMLC_DECLARE_PARAMETER(NormalizeParam) {
+    DMLC_DECLARE_FIELD(mean)
+    .describe("Sequence of mean for each channel.");
+    DMLC_DECLARE_FIELD(std)
+    .describe("Sequence of standard deviations for each channel.");
+  }
+};
+
+struct normalize {
+  template<typename DType>
+  MSHADOW_XINLINE static void Map(int i, DType *out, const DType *in,
+                                  const OpReqType req,
+                                  const int nchannel, const int size,
+                                  const float *mean, const float *std) {
+    int c = 0;
+    switch (nchannel) {
+      case 1:
+        break;
+      case 3:
+        if (i < size) {
+          c = 0;
+        } else if (i < (size << 1)) {
+          c = 1;
+        } else {
+          c = 2;
+        }
+        break;
+      default:
+        LOG(FATAL) << "not support channel" << nchannel;
+    }
+    float m = (mean ? mean[c] : 0);
+    KERNEL_ASSIGN(out[i], req, static_cast<DType>((in[i] - m) / std[c]));
+  }
+};
+
+static void NormalizeCheckParam(const nnvm::Tuple<float> &mean,
+                                const nnvm::Tuple<float> &std,
+                                const int nchannel) {
+  CHECK(mean.ndim() == 1 || mean.ndim() == 3)
+    << "Mean must be in dimension 1 or 3.";
+  CHECK(std.ndim() == 1 || std.ndim() == 3)
+    << "Standard deviations must be in dimension 1 or 3.";
+  CHECK(nchannel == 1 || nchannel == 3) << "Image channel must be 1 or 3.";
+  CHECK_EQ(mean.ndim(), nchannel)
+    << "Mean dimension does not agree with image channel.";
+  CHECK_EQ(std.ndim(), nchannel)
+    << "Standard deviations dimension does not agree with image channel.";
+  for (uint32_t c = 0; c < std.ndim(); ++c) {
+    CHECK(std[c] > 0) << "Invalid standard deviation " << std[c];
+  }
+}
+
 template<typename xpu>
 static void Normalize(const nnvm::NodeAttrs &attrs,
                       const OpContext &ctx,
                       const std::vector<TBlob> &inputs,
                       const std::vector<OpReqType> &req,
                       const std::vector<TBlob> &outputs) {
+  const NormalizeParam &param = nnvm::get<NormalizeParam>(attrs.parsed);
+  auto mean = param.mean;
+  auto std = param.std;
+
+  int nchannel = inputs[0].shape_[0];
+  NormalizeCheckParam(mean, std, nchannel);
+
+  int size = inputs[0].Size() / nchannel;
+  mshadow::Stream<xpu> *s = ctx.get_stream<xpu>();
+  MXNET_ASSIGN_REQ_SWITCH(req[0], Req, {
+    MSHADOW_TYPE_SWITCH(outputs[0].type_flag_, DType, {
+      mxnet_op::Kernel<normalize, xpu>::Launch(
+        s, inputs[0].Size(), outputs[0].dptr<DType>(), inputs[0].dptr<DType>(),
+        Req, nchannel, size, mean.begin(), std.begin());
+    });
+  });
+}
+
+template<typename xpu>
+static void NormalizeBackward(const nnvm::NodeAttrs &attrs,
+                              const OpContext &ctx,
+                              const std::vector<TBlob> &inputs,
+                              const std::vector<OpReqType> &req,
+                              const std::vector<TBlob> &outputs) {
+  const NormalizeParam &param = nnvm::get<NormalizeParam>(attrs.parsed);
+  int nchannel = inputs[0].shape_[0];
+
+  NormalizeCheckParam(param.mean, param.std, nchannel);
+
+  int size = inputs[0].Size() / nchannel;
+  mshadow::Stream<xpu> *s = ctx.get_stream<xpu>();
+  MXNET_ASSIGN_REQ_SWITCH(req[0], Req, {
+    MSHADOW_TYPE_SWITCH(outputs[0].type_flag_, DType, {
+      mxnet_op::Kernel<normalize, xpu>::Launch(
+        s, inputs[0].Size(), outputs[0].dptr<DType>(), inputs[0].dptr<DType>(),
+        Req, nchannel, size, nullptr, param.std.begin());
+      });
+  });
 }
 
 struct RandomBrightnessParam : public dmlc::Parameter<RandomBrightnessParam> {
diff --git a/src/operator/image/image_random.cc b/src/operator/image/image_random.cc
index 26fa843..e32a677 100644
--- a/src/operator/image/image_random.cc
+++ b/src/operator/image/image_random.cc
@@ -28,8 +28,6 @@
 #include "../operator_common.h"
 #include "../elemwise_op_common.h"
 
-
-
 namespace mxnet {
 namespace op {
 
@@ -46,6 +44,38 @@ NNVM_REGISTER_OP(_image_to_tensor)
 .set_attr<nnvm::FGradient>("FGradient", ElemwiseGradUseNone{ "_copy" })
 .add_argument("data", "NDArray-or-Symbol", "The input.");
 
+DMLC_REGISTER_PARAMETER(NormalizeParam);
+NNVM_REGISTER_OP(_image_normalize)
+.describe(R"code()code" ADD_FILELINE)
+.set_num_inputs(1)
+.set_num_outputs(1)
+.set_attr_parser(ParamParser<NormalizeParam>)
+.set_attr<FResourceRequest>("FResourceRequest", [](const NodeAttrs& attrs) {
+  return std::vector<ResourceRequest>{ResourceRequest::kRandom};
+})
+.set_attr<nnvm::FInferShape>("FInferShape", ElemwiseShape<1, 1>)
+.set_attr<nnvm::FInferType>("FInferType", ElemwiseType<1, 1>)
+.set_attr<nnvm::FInplaceOption>("FInplaceOption",
+[](const NodeAttrs& attrs){
+  return std::vector<std::pair<int, int> >{{0, 0}};
+})
+.set_attr<FCompute>("FCompute<cpu>", Normalize<cpu>)
+.set_attr<nnvm::FGradient>("FGradient", ElemwiseGradUseNone{ "_image_backward_normalize" })
+.add_argument("data", "NDArray-or-Symbol", "The input.")
+.add_arguments(NormalizeParam::__FIELDS__());
+
+NNVM_REGISTER_OP(_image_backward_normalize)
+.describe(R"code()code" ADD_FILELINE)
+.set_num_inputs(1)
+.set_num_outputs(1)
+.set_attr_parser(ParamParser<NormalizeParam>)
+.set_attr<nnvm::TIsBackward>("TIsBackward", true)
+.set_attr<nnvm::FInplaceOption>("FInplaceOption",
+[](const NodeAttrs& attrs){
+  return std::vector<std::pair<int, int> >{{0, 0}};
+})
+.set_attr<FCompute>("FCompute<cpu>", NormalizeBackward<cpu>);
+
 DMLC_REGISTER_PARAMETER(RandomBrightnessParam);
 NNVM_REGISTER_OP(_image_random_brightness)
 .describe(R"code()code" ADD_FILELINE)

-- 
To stop receiving notification emails like this one, please contact
"commits@mxnet.apache.org" <co...@mxnet.apache.org>.

[incubator-mxnet] 05/08: fix image_random compile (#8665)

Posted by jx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jxie pushed a commit to branch vision
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git

commit ae9fd42e838a5d251db76397158c91799fddfb8b
Author: Yizhi Liu <ja...@gmail.com>
AuthorDate: Wed Nov 15 10:40:34 2017 -0800

    fix image_random compile (#8665)
---
 src/operator/image/image_random-inl.h                  | 2 +-
 src/operator/image/image_random.cc                     | 4 ++--
 src/operator/tensor/elemwise_binary_scalar_op_basic.cc | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/operator/image/image_random-inl.h b/src/operator/image/image_random-inl.h
index fa1d6dc..8a3acf6 100644
--- a/src/operator/image/image_random-inl.h
+++ b/src/operator/image/image_random-inl.h
@@ -31,7 +31,7 @@
 #include <opencv2/core/mat.hpp>
 #include "../mxnet_op.h"
 #include "image_common.h"
-#include "operator/operator_common.h"
+#include "../../operator/operator_common.h"
 
 
 namespace mxnet {
diff --git a/src/operator/image/image_random.cc b/src/operator/image/image_random.cc
index 32648bb..83abc17 100644
--- a/src/operator/image/image_random.cc
+++ b/src/operator/image/image_random.cc
@@ -25,8 +25,8 @@
 
 #include <mxnet/base.h>
 #include "./image_random-inl.h"
-#include "operator/operator_common.h"
-#include "operator/elemwise_op_common.h"
+#include "../../operator/operator_common.h"
+#include "../../operator/elemwise_op_common.h"
 
 
 
diff --git a/src/operator/tensor/elemwise_binary_scalar_op_basic.cc b/src/operator/tensor/elemwise_binary_scalar_op_basic.cc
index 2d6662e..13f806d 100644
--- a/src/operator/tensor/elemwise_binary_scalar_op_basic.cc
+++ b/src/operator/tensor/elemwise_binary_scalar_op_basic.cc
@@ -58,7 +58,7 @@ static bool BinaryScalarStorageTypeWithDenseResultStorageType(const NodeAttrs& a
                                      kDefaultStorage,
                                      dispatch_mode,
                                      DispatchMode::kFCompute);
-  } else if (dev_mask == kCPU) {
+  } else if (dev_mask == Context::kCPU) {
     dispatched = storage_type_assign(&out_attrs[0],
                                      kDefaultStorage,
                                      dispatch_mode,

-- 
To stop receiving notification emails like this one, please contact
"commits@mxnet.apache.org" <co...@mxnet.apache.org>.