mxnet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] larroy commented on a change in pull request #8582: Yolo2 operator
Date Thu, 01 Jan 1970 00:00:00 GMT
larroy commented on a change in pull request #8582: Yolo2 operator
URL: https://github.com/apache/incubator-mxnet/pull/8582#discussion_r165448626
 
 

 ##########
 File path: src/operator/contrib/yolo_output-inl.h
 ##########
 @@ -0,0 +1,703 @@
+/*
+ * 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.
+ */
+
+/*!
+ * \file yolo_output-inl.h
+ * \brief yolo-v2 output layer, v1 to be added
+ * \author Joshua Zhang
+*/
+#ifndef MXNET_OPERATOR_CONTRIB_YOLO_OUTPUT_INL_H_
+#define MXNET_OPERATOR_CONTRIB_YOLO_OUTPUT_INL_H_
+#include <dmlc/logging.h>
+#include <dmlc/parameter.h>
+#include <mxnet/operator.h>
+#include <mxnet/base.h>
+#include <nnvm/tuple.h>
+#include <map>
+#include <vector>
+#include <string>
+#include <algorithm>
+#include <utility>
+#include "../operator_common.h"
+#include "../mshadow_op.h"
+#include "../mxnet_op.h"
+#include "../tensor/sort_op.h"
+
+namespace mxnet {
+namespace op {
+namespace yolo2out_enum {
+enum Yolo2OutputOpInputs {kData, kLabel};
+enum Yolo2OutputOpOutputs {kOut, kTemp, kCopy};
+enum Yolo2OutputOpAuxiliary {kCounter};
+enum Yolo2OutputOpResource {kTempSpace};
+}  // namespace yolo2out_enum
+
+struct Yolo2OutputParam : public dmlc::Parameter<Yolo2OutputParam> {
+  int num_class;
+  int num_anchor;
+  float overlap_thresh;
+  float object_grad_scale;
+  float background_grad_scale;
+  float class_grad_scale;
+  float coord_grad_scale;
+  nnvm::Tuple<float> anchors;
+  int warmup_samples;
+  float warmup_grad_scale;
+  float nms_threshold;
+  int nms_topk;
+  bool force_suppress;
+  DMLC_DECLARE_PARAMETER(Yolo2OutputParam) {
+    DMLC_DECLARE_FIELD(num_class).set_lower_bound(1)
+    .describe("Number of object classes.");
+    DMLC_DECLARE_FIELD(num_anchor).set_default(5)
+    .set_lower_bound(1)
+    .describe("Number of anchors.");
+    DMLC_DECLARE_FIELD(overlap_thresh).set_default(0.6)
+    .describe("Positive overlap threshold.");
+    DMLC_DECLARE_FIELD(object_grad_scale).set_default(1.0)
+    .describe("Gradient scale for positive objects.");
+    DMLC_DECLARE_FIELD(background_grad_scale).set_default(1.0)
+    .describe("Gradient scale for background.");
+    DMLC_DECLARE_FIELD(class_grad_scale).set_default(1.0)
+    .describe("Gradient scale for positive objects.");
+    DMLC_DECLARE_FIELD(coord_grad_scale).set_default(1.0)
+    .describe("Gradient scale for box offsets.");
+    DMLC_DECLARE_FIELD(anchors)
+    .set_default({1.08f, 1.19f, 3.42f, 4.41f, 6.63f, 11.38f, 9.42f, 5.11f, 16.62f, 10.52f})
+    .describe("Predefined anchor box widths and heights.");
+    DMLC_DECLARE_FIELD(warmup_samples).set_default(12800)
+    .describe("Number of images to warm up towards averaging position for box "
+    "predictions when starting a new training. ");
+    DMLC_DECLARE_FIELD(warmup_grad_scale).set_default(0.01)
+    .describe("Gradient scale for non-critical anchors during warm-up stage.");
+    DMLC_DECLARE_FIELD(nms_threshold).set_default(0.5f)
+    .describe("Non-maximum suppression threshold.");
+    DMLC_DECLARE_FIELD(force_suppress).set_default(false)
+    .describe("Suppress all detections regardless of class_id.");
+    DMLC_DECLARE_FIELD(nms_topk).set_default(-1)
+    .describe("Keep maximum top k detections before nms, -1 for no limit.");
+  }
+};  // struct Yolo2OutputParam
+
+template<typename DType>
+MSHADOW_XINLINE DType Intersect(DType l1, DType r1, DType l2, DType r2) {
+  DType left = l1 > l2 ? l1 : l2;
+  DType right = r1 < r2 ? r1 : r2;
+  DType w = right - left;
+  return w > 0 ? w : DType(0);
+}
+
+template<typename DType>
+MSHADOW_XINLINE DType Area(DType l1, DType t1, DType r1, DType b1) {
+  DType width = r1 - l1;
+  DType height = b1 - t1;
+  if (width <= 0 || height <= 0) return DType(0);
+  return width * height;
+}
+
+template<typename DType>
+MSHADOW_XINLINE DType IOU(DType l1, DType t1, DType r1, DType b1,
 
 Review comment:
   I would add a comment describing what's Intersection Over Union, to help readers.

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

Mime
View raw message