anirudh2290 commented on a change in pull request #13679: add crop gluon 
transform
URL: https://github.com/apache/incubator-mxnet/pull/13679#discussion_r243454505
 
 

 ##########
 File path: src/operator/image/crop-inl.h
 ##########
 @@ -0,0 +1,268 @@
+/*
+* 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.
+*/
+
+/*!
+ *  Copyright (c) 2016 by Contributors
+ * \file crop-inl.h
+ * \brief the image crop operator implementation
+ */
+
+#ifndef MXNET_OPERATOR_IMAGE_CROP_INL_H_
+#define MXNET_OPERATOR_IMAGE_CROP_INL_H_
+
+
+#include <algorithm>
+#include <vector>
+
+#include "mxnet/base.h"
+#include "dmlc/optional.h"
+#include "image_utils.h"
+#include "../mxnet_op.h"
+#include "../operator_common.h"
+
+#if MXNET_USE_OPENCV
+  #include <opencv2/opencv.hpp>
+#endif  // MXNET_USE_OPENCV
+
+namespace mxnet {
+namespace op {
+namespace image {
+
+struct CropParam : public dmlc::Parameter<CropParam> {
+  int x;
+  int y;
+  int width;
+  int height;
+  dmlc::optional<nnvm::Tuple<int>> size;
+  dmlc::optional<int> interp;
+  DMLC_DECLARE_PARAMETER(CropParam) {
+    DMLC_DECLARE_FIELD(x)
+    .describe("Left boundary of the cropping area.");
+    DMLC_DECLARE_FIELD(y)
+    .describe("Top boundary of the cropping area.");
+    DMLC_DECLARE_FIELD(width)
+    .describe("Width of the cropping area.");
+    DMLC_DECLARE_FIELD(height)
+    .describe("Top boundary of the cropping area");
+    DMLC_DECLARE_FIELD(size)
+    .describe("Size of image for resizing after crop. Could be (width, height) 
or size");
+    DMLC_DECLARE_FIELD(interp)
+    .describe("Interpolation method for resizing. By default uses bilinear 
interpolation"
+        "Options are INTER_NEAREST - a nearest-neighbor interpolation"
+        "INTER_LINEAR - a bilinear interpolation"
+        "INTER_AREA - resampling using pixel area relation"
+        "INTER_CUBIC - a bicubic interpolation over 4x4 pixel neighborhood"
+        "INTER_LANCZOS4 - a Lanczos interpolation over 8x8 pixel 
neighborhood");
+  }
+};
+
+inline bool CropShape(const nnvm::NodeAttrs& attrs,
+                             std::vector<TShape> *in_attrs,
+                             std::vector<TShape> *out_attrs) {
+  // input attrs should only be (h, w, c) or (n, h, w, c)
+  CHECK((in_attrs->at(0).ndim() == 3U) || (in_attrs->at(0).ndim() == 4U))
+    << "Input image dimension should be 3 or 4 but got "
+    << in_attrs->at(0).ndim();
+
+  const auto& ishape = (*in_attrs)[0];
+  const CropParam& param = nnvm::get<CropParam>(attrs.parsed);
+  const bool has_size = param.size.has_value();
+  const bool has_interp = param.interp.has_value();
+
+  CHECK(has_size == has_interp)
+      << "Missing input. Either size or interp is not assigned the value.";
+  CHECK((param.height > 0) && (param.width > 0))
+      << "Input height and width must be greater than 0";
+  if (has_size) {
+    int height;
+    int width;
+    CHECK(param.size.value().ndim() == 1 || param.size.value().ndim() == 2)
 
 Review comment:
   why do you need these `value()` calls ?

----------------------------------------------------------------
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

Reply via email to