apeforest commented on a change in pull request #13614: Make to_tensor and
normalize to accept 3D or 4D tensor inputs
URL: https://github.com/apache/incubator-mxnet/pull/13614#discussion_r241120167
##########
File path: src/operator/image/image_random-inl.h
##########
@@ -47,9 +47,14 @@ inline bool ToTensorShape(const nnvm::NodeAttrs& attrs,
CHECK_EQ(out_attrs->size(), 1U);
TShape &shp = (*in_attrs)[0];
if (!shp.ndim()) return false;
- CHECK_EQ(shp.ndim(), 3)
- << "Input image must have shape (height, width, channels), but got " <<
shp;
- SHAPE_ASSIGN_CHECK(*out_attrs, 0, TShape({shp[2], shp[0], shp[1]}));
+ CHECK((shp.ndim() == 3) || (shp.ndim() == 4))
+ << "Input image must have shape (height, width, channels), or "
+ << "(N, height, width, channels) but got " << shp;
+ if (shp.ndim() == 3) {
+ SHAPE_ASSIGN_CHECK(*out_attrs, 0, TShape({shp[2], shp[0], shp[1]}));
+ } else if (shp.ndim() == 4) {
+ SHAPE_ASSIGN_CHECK(*out_attrs, 0, TShape({shp[0], shp[3], shp[1],
shp[2]}));
Review comment:
Can shp[0] be zero?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services