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

[IO] Python based ImageIter and Augumenter #3227

Merged
merged 4 commits into from
Sep 16, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix
  • Loading branch information
piiswrong committed Sep 16, 2016
commit cdac9ac701bb3c5954f26d43df6b76b591a3a791
39 changes: 0 additions & 39 deletions include/mxnet/operator_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,45 +481,6 @@ class SimpleOpRegistry {
__make_ ## SimpleOpRegEntry ## _ ## Name ## __ ## DEV ##__ = \
::mxnet::op::SimpleOpRegistry::Get()->__REGISTER_OR_FIND__(#Name)

//-----------------------------------------------
// Utility functions for building NNVM operators
//-----------------------------------------------
/*! \brief Set shape of all inputs/outputs to shape of the first input */
inline bool UniformShape(const nnvm::NodeAttrs& attrs,
std::vector<TShape> *ishape,
std::vector<TShape> *oshape) {
if (ishape->size() == 0 || (*ishape)[0].ndim() == 0) return false;
for (TShape& pshape : *oshape) {
pshape = (*ishape)[0];
}
for (TShape& pshape : *ishape) {
pshape = (*ishape)[0];
}
return true;
}

/*! \brief Set dtype of all inputs/outputs to dtype of the first input */
inline bool UniformType(const nnvm::NodeAttrs& attrs,
std::vector<int> *itype,
std::vector<int> *otype) {
if (itype->size() == 0 || (*itype)[0] == -1) return false;
for (int& ptype : *otype) {
ptype = (*itype)[0];
}
for (int& ptype : *itype) {
ptype = (*itype)[0];
}
return true;
}

/*! \brief Parse keyword arguments as PType arguments and save to parsed */
template<typename PType>
inline void ParamParser(nnvm::NodeAttrs* attrs) {
PType param;
param.Init(attrs->dict);
attrs->parsed = std::move(param);
}

} // namespace op
} // namespace mxnet
#endif // MXNET_OPERATOR_UTIL_H_
8 changes: 5 additions & 3 deletions python/mxnet/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ def aug(src):
def CastAug():
def aug(src):
src = src.astype(np.float32)
src /= 255.0
return src
return aug

Expand All @@ -206,12 +205,16 @@ def CreateAugmenter(data_shape, rand_crop=False, rand_resize=False, rand_mirror=
auglist.append(ColorJitterAug(brightness, contrast, saturation))

if pca_noise > 0:
eigval = np.array([0.2175, 0.0188, 0.0045])
eigval = np.array([ 55.46, 4.794, 1.148 ])
eigvec = np.array([[ -0.5675, 0.7192, 0.4009 ],
[ -0.5808, -0.0045, -0.8140 ],
[ -0.5836, -0.6948, 0.4203 ]])
auglist.append(LightingAug(pca_noise, eigval, eigvec))

if mean is True:
mean = np.array([ 123.68, 116.28 , 103.53 ])
if std is True:
std = np.array([ 58.395, 57.12 , 57.375])
if mean:
auglist.append(ColorNormalizeAug(mean, std))

Expand Down Expand Up @@ -307,7 +310,6 @@ def next(self):
c, h, w = self.data_shape
batch_data = nd.zeros((batch_size, h, w, c))
batch_label = nd.zeros((batch_size, self.label_width))

try:
for i in range(batch_size):
label, data = self.next_sample()
Expand Down
16 changes: 9 additions & 7 deletions src/io/image_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <nnvm/op.h>
#include <nnvm/op_attr_types.h>

#include "../operator/elemwise_op_common.h"

#if MXNET_USE_OPENCV
#include <opencv2/opencv.hpp>
#endif // MXNET_USE_OPENCV
Expand Down Expand Up @@ -243,7 +245,7 @@ NNVM_REGISTER_OP(_cvimdecode)
.set_num_inputs(1)
.set_num_outputs(1)
.set_attr_parser(op::ParamParser<ImdecodeParam>)
.attr<FNDArrayFunction>("FNDArrayFunction", Imdecode)
.set_attr<FNDArrayFunction>("FNDArrayFunction", Imdecode)
.add_argument("buf", "NDArray", "Buffer containing binary encoded image")
.add_arguments(ImdecodeParam::__FIELDS__());

Expand All @@ -252,9 +254,9 @@ NNVM_REGISTER_OP(_cvimresize)
.set_num_inputs(1)
.set_num_outputs(1)
.set_attr_parser(op::ParamParser<ResizeParam>)
.attr<nnvm::FInferShape>("FInferShape", ResizeShape)
.attr<nnvm::FInferType>("FInferType", op::UniformType)
.attr<FCompute>("FCompute<cpu>", Imresize)
.set_attr<nnvm::FInferShape>("FInferShape", ResizeShape)
.set_attr<nnvm::FInferType>("FInferType", op::ElemwiseType<1,1>)
.set_attr<FCompute>("FCompute<cpu>", Imresize)
.add_argument("src", "NDArray", "source image")
.add_arguments(ResizeParam::__FIELDS__());

Expand All @@ -263,9 +265,9 @@ NNVM_REGISTER_OP(_cvcopyMakeBorder)
.set_num_inputs(1)
.set_num_outputs(1)
.set_attr_parser(op::ParamParser<MakeBorderParam>)
.attr<nnvm::FInferShape>("FInferShape", MakeBorderShape)
.attr<nnvm::FInferType>("FInferType", op::UniformType)
.attr<FCompute>("FCompute<cpu>", copyMakeBorder)
.set_attr<nnvm::FInferShape>("FInferShape", MakeBorderShape)
.set_attr<nnvm::FInferType>("FInferType", op::ElemwiseType<1,1>)
.set_attr<FCompute>("FCompute<cpu>", copyMakeBorder)
.add_argument("src", "NDArray", "source image")
.add_arguments(MakeBorderParam::__FIELDS__());

Expand Down
2 changes: 1 addition & 1 deletion src/operator/tensor/elemwise_binary_broadcast_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ inline bool BinaryBroadcastShapeCompact(const TShape& lshape, const TShape& rsha
for (index_t i = 0; i < oshape.ndim(); ++i) {
index_t l = 1, r = 1, o = oshape[i];
if (i >= bl) l = lshape[i-bl];
if (j >= br) r = rshape[i-br];
if (i >= br) r = rshape[i-br];
if ((lprod != rprod || l != r) &&
lprod*l > 1 && rprod*r > 1) {
(*new_lshape)[j] = lprod;
Expand Down