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

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vandanavk committed Feb 19, 2019
1 parent 50d43d4 commit 05cc7ea
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/operator/nn/upsampling-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ struct UpSamplingParam : public dmlc::Parameter<UpSamplingParam> {
.set_range(1, 1000)
.describe("Up sampling scale");
DMLC_DECLARE_FIELD(num_filter)
.describe("Input filter. Only used by bilinear sample_type.")
.describe("Input filter. Only used by bilinear sample_type."
"Since bilinear upsampling uses deconvolution, num_filters "
"is set to the number of channels.")
.set_default(0);
DMLC_DECLARE_FIELD(sample_type)
.add_enum("nearest", up_enum::kNearest)
Expand Down
7 changes: 5 additions & 2 deletions src/operator/nn/upsampling.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ struct UpSamplingGrad {
DMLC_REGISTER_PARAMETER(UpSamplingParam);

NNVM_REGISTER_OP(UpSampling)
.describe("Performs nearest neighbor/bilinear up sampling to inputs.")
.describe("Performs nearest neighbor/bilinear up sampling to inputs. "
"Bilinear upsampling makes use of deconvolution. Therefore, "
"provide 2 inputs - data and weight. ")
.set_num_inputs([](const NodeAttrs& attrs) {
const UpSamplingParam& params = nnvm::get<UpSamplingParam>(attrs.parsed);
return params.sample_type == up_enum::kNearest ? params.num_args : 2;
Expand Down Expand Up @@ -149,7 +151,8 @@ NNVM_REGISTER_OP(UpSampling)
.set_attr<FCompute>("FCompute<cpu>", UpSamplingCompute<cpu>)
.set_attr<nnvm::FGradient>("FGradient", UpSamplingGrad{"_backward_UpSampling"})
.set_attr<std::string>("key_var_num_args", "num_args")
.add_argument("data", "NDArray-or-Symbol[]", "Array of tensors to upsample")
.add_argument("data", "NDArray-or-Symbol[]",
"Array of tensors to upsample. For bilinear upsampling, there should be 2 inputs - 1 data and 1 weight.")
.add_arguments(UpSamplingParam::__FIELDS__())
.set_attr<nnvm::FSetInputVarAttrOnCompose>("FSetInputVarAttrOnCompose",
[](const nnvm::NodeAttrs& attrs, nnvm::NodePtr var, const int index) {
Expand Down
24 changes: 13 additions & 11 deletions tests/python/unittest/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1530,17 +1530,19 @@ def test_nearest_upsampling():

@with_seed()
def test_bilinear_upsampling():
for root_scale in [2,3]:
for scale in [1,2,3]:
for num_filter in [1,2,3]:
for base in [1,2,3]:
# bilinear upsampling takes only 1 data and 1 weight
# multi input mode is not applicable
dimension = base*root_scale*scale
kernel = 2 * root_scale - root_scale % 2
data_shape = (1, num_filter, dimension, dimension)
weight_shape = (num_filter, 1, kernel, kernel)
check_bilinear_upsampling_with_shape(data_shape, weight_shape, scale, root_scale, num_filter)
rootscale = [2,3]
scales = [1,2,3]
filters = [1,2,3]
bases = [1,2,3]
for params in itertools.product(rootscale, scales, filters, bases):
root_scale, scale, num_filter, base = params
# bilinear upsampling takes only 1 data and 1 weight
# multi input mode is not applicable
dimension = base*root_scale*scale
kernel = 2 * root_scale - root_scale % 2
data_shape = (1, num_filter, dimension, dimension)
weight_shape = (1, num_filter, kernel, kernel)
check_bilinear_upsampling_with_shape(data_shape, weight_shape, scale, root_scale, num_filter)

@with_seed()
def test_batchnorm_training():
Expand Down

0 comments on commit 05cc7ea

Please sign in to comment.