You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/01/29 17:59:51 UTC

[GitHub] sandeep-krishnamurthy commented on a change in pull request #14014: [WIP] Export resize and support batch size

sandeep-krishnamurthy commented on a change in pull request #14014: [WIP] Export resize and support batch size
URL: https://github.com/apache/incubator-mxnet/pull/14014#discussion_r251947622
 
 

 ##########
 File path: src/operator/image/image_utils.h
 ##########
 @@ -0,0 +1,164 @@
+/*
+* 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) 2019 by Contributors
+ * \file image_utils.h
+ * \brief the image operator utility function implementation
+ * \author Jake Lee
+ */
+
+#ifndef MXNET_OPERATOR_IMAGE_IMAGE_UTILS_H_
+#define MXNET_OPERATOR_IMAGE_IMAGE_UTILS_H_
+
+#include <vector>
+#if MXNET_USE_OPENCV
+  #include <opencv2/opencv.hpp>
+#endif  // MXNET_USE_OPENCV
+
+namespace mxnet {
+namespace op {
+namespace image {
+
+enum ImageLayout {H, W, C};
+enum BatchImageLayout {N, kH, kW, kC};
+
+struct SizeParam {
+  int height;
+  int width;
+  SizeParam() {
+    height = 0;
+    width = 0;
+  }
+  SizeParam(int height_, int width_) {
+    height = height_;
+    width = width_;
+  }
+};  // struct SizeParam
+
+template<typename T>
+inline SizeParam GetHeightAndWidthFromSize(const T& param) {
+  int h, w;
+  if (param.size.ndim() == 1) {
+    h = param.size[0];
+    w = param.size[0];
+  } else {
+    // size should be (w, h) instead of (h, w)
+    h = param.size[1];
+    w = param.size[0];
+  }
+  return SizeParam(h, w);
+}
+
+// Scales down crop size if it's larger than image size.
+inline SizeParam ScaleDown(const SizeParam& src,
+                            const SizeParam& size) {
+  const auto src_h = src.height;
+  const auto src_w = src.width;
+  auto dst_h = size.height;
+  auto dst_w = size.width;
+
+  if (src_h < dst_h) {
+    dst_w = static_cast<int>((dst_w * src_h) / dst_h);
+    dst_h = src_h;
+  }
+  if (src_w < dst_w) {
+    dst_h = static_cast<int>((dst_h * src_w) / dst_w);
+    dst_w = src_w;
+  }
+  return SizeParam(dst_h, dst_w);
+}
+
+inline void CropImpl(const std::vector<TBlob> &inputs,
 
 Review comment:
   Can we separate Crop implementation in a different PR? This will help to keep this PR targeted at one operation - Resize

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services