fix(YOLOX) fix bugs in utils and evalutor, add user-friendly const value. (#538)
Browse files
demo/OpenVINO/cpp/yolox_openvino.cpp
CHANGED
@@ -23,6 +23,7 @@ using namespace InferenceEngine;
|
|
23 |
|
24 |
static const int INPUT_W = 416;
|
25 |
static const int INPUT_H = 416;
|
|
|
26 |
|
27 |
cv::Mat static_resize(cv::Mat& img) {
|
28 |
float r = std::min(INPUT_W / (img.cols*1.0), INPUT_H / (img.rows*1.0));
|
@@ -97,7 +98,6 @@ static void generate_grids_and_stride(const int target_size, std::vector<int>& s
|
|
97 |
|
98 |
static void generate_yolox_proposals(std::vector<GridAndStride> grid_strides, const float* feat_ptr, float prob_threshold, std::vector<Object>& objects)
|
99 |
{
|
100 |
-
const int num_class = 80; // COCO has 80 classes. Modify this value on your own dataset.
|
101 |
|
102 |
const int num_anchors = grid_strides.size();
|
103 |
|
@@ -107,7 +107,7 @@ static void generate_yolox_proposals(std::vector<GridAndStride> grid_strides, co
|
|
107 |
const int grid1 = grid_strides[anchor_idx].grid1;
|
108 |
const int stride = grid_strides[anchor_idx].stride;
|
109 |
|
110 |
-
const int basic_pos = anchor_idx *
|
111 |
|
112 |
// yolox/models/yolo_head.py decode logic
|
113 |
// outputs[..., :2] = (outputs[..., :2] + grids) * strides
|
@@ -120,7 +120,7 @@ static void generate_yolox_proposals(std::vector<GridAndStride> grid_strides, co
|
|
120 |
float y0 = y_center - h * 0.5f;
|
121 |
|
122 |
float box_objectness = feat_ptr[basic_pos + 4];
|
123 |
-
for (int class_idx = 0; class_idx <
|
124 |
{
|
125 |
float box_cls_score = feat_ptr[basic_pos + 5 + class_idx];
|
126 |
float box_prob = box_objectness * box_cls_score;
|
|
|
23 |
|
24 |
static const int INPUT_W = 416;
|
25 |
static const int INPUT_H = 416;
|
26 |
+
static const int NUM_CLASSES = 80; // COCO has 80 classes. Modify this value on your own dataset.
|
27 |
|
28 |
cv::Mat static_resize(cv::Mat& img) {
|
29 |
float r = std::min(INPUT_W / (img.cols*1.0), INPUT_H / (img.rows*1.0));
|
|
|
98 |
|
99 |
static void generate_yolox_proposals(std::vector<GridAndStride> grid_strides, const float* feat_ptr, float prob_threshold, std::vector<Object>& objects)
|
100 |
{
|
|
|
101 |
|
102 |
const int num_anchors = grid_strides.size();
|
103 |
|
|
|
107 |
const int grid1 = grid_strides[anchor_idx].grid1;
|
108 |
const int stride = grid_strides[anchor_idx].stride;
|
109 |
|
110 |
+
const int basic_pos = anchor_idx * (NUM_CLASSES + 5);
|
111 |
|
112 |
// yolox/models/yolo_head.py decode logic
|
113 |
// outputs[..., :2] = (outputs[..., :2] + grids) * strides
|
|
|
120 |
float y0 = y_center - h * 0.5f;
|
121 |
|
122 |
float box_objectness = feat_ptr[basic_pos + 4];
|
123 |
+
for (int class_idx = 0; class_idx < NUM_CLASSES; class_idx++)
|
124 |
{
|
125 |
float box_cls_score = feat_ptr[basic_pos + 5 + class_idx];
|
126 |
float box_prob = box_objectness * box_cls_score;
|
demo/TensorRT/cpp/yolox.cpp
CHANGED
@@ -30,6 +30,7 @@ using namespace nvinfer1;
|
|
30 |
// stuff we know about the network and the input/output blobs
|
31 |
static const int INPUT_W = 640;
|
32 |
static const int INPUT_H = 640;
|
|
|
33 |
const char* INPUT_BLOB_NAME = "input_0";
|
34 |
const char* OUTPUT_BLOB_NAME = "output_0";
|
35 |
static Logger gLogger;
|
@@ -163,7 +164,6 @@ static void nms_sorted_bboxes(const std::vector<Object>& faceobjects, std::vecto
|
|
163 |
|
164 |
static void generate_yolox_proposals(std::vector<GridAndStride> grid_strides, float* feat_blob, float prob_threshold, std::vector<Object>& objects)
|
165 |
{
|
166 |
-
const int num_class = 80;
|
167 |
|
168 |
const int num_anchors = grid_strides.size();
|
169 |
|
@@ -173,7 +173,7 @@ static void generate_yolox_proposals(std::vector<GridAndStride> grid_strides, fl
|
|
173 |
const int grid1 = grid_strides[anchor_idx].grid1;
|
174 |
const int stride = grid_strides[anchor_idx].stride;
|
175 |
|
176 |
-
const int basic_pos = anchor_idx * (
|
177 |
|
178 |
// yolox/models/yolo_head.py decode logic
|
179 |
float x_center = (feat_blob[basic_pos+0] + grid0) * stride;
|
@@ -184,7 +184,7 @@ static void generate_yolox_proposals(std::vector<GridAndStride> grid_strides, fl
|
|
184 |
float y0 = y_center - h * 0.5f;
|
185 |
|
186 |
float box_objectness = feat_blob[basic_pos+4];
|
187 |
-
for (int class_idx = 0; class_idx <
|
188 |
{
|
189 |
float box_cls_score = feat_blob[basic_pos + 5 + class_idx];
|
190 |
float box_prob = box_objectness * box_cls_score;
|
|
|
30 |
// stuff we know about the network and the input/output blobs
|
31 |
static const int INPUT_W = 640;
|
32 |
static const int INPUT_H = 640;
|
33 |
+
static const int NUM_CLASSES = 80;
|
34 |
const char* INPUT_BLOB_NAME = "input_0";
|
35 |
const char* OUTPUT_BLOB_NAME = "output_0";
|
36 |
static Logger gLogger;
|
|
|
164 |
|
165 |
static void generate_yolox_proposals(std::vector<GridAndStride> grid_strides, float* feat_blob, float prob_threshold, std::vector<Object>& objects)
|
166 |
{
|
|
|
167 |
|
168 |
const int num_anchors = grid_strides.size();
|
169 |
|
|
|
173 |
const int grid1 = grid_strides[anchor_idx].grid1;
|
174 |
const int stride = grid_strides[anchor_idx].stride;
|
175 |
|
176 |
+
const int basic_pos = anchor_idx * (NUM_CLASSES + 5);
|
177 |
|
178 |
// yolox/models/yolo_head.py decode logic
|
179 |
float x_center = (feat_blob[basic_pos+0] + grid0) * stride;
|
|
|
184 |
float y0 = y_center - h * 0.5f;
|
185 |
|
186 |
float box_objectness = feat_blob[basic_pos+4];
|
187 |
+
for (int class_idx = 0; class_idx < NUM_CLASSES; class_idx++)
|
188 |
{
|
189 |
float box_cls_score = feat_blob[basic_pos + 5 + class_idx];
|
190 |
float box_prob = box_objectness * box_cls_score;
|
yolox/evaluators/voc_evaluator.py
CHANGED
@@ -79,7 +79,7 @@ class VOCEvaluator:
|
|
79 |
|
80 |
inference_time = 0
|
81 |
nms_time = 0
|
82 |
-
n_samples = len(self.dataloader) - 1
|
83 |
|
84 |
if trt_file is not None:
|
85 |
from torch2trt import TRTModule
|
|
|
79 |
|
80 |
inference_time = 0
|
81 |
nms_time = 0
|
82 |
+
n_samples = max(len(self.dataloader) - 1, 1)
|
83 |
|
84 |
if trt_file is not None:
|
85 |
from torch2trt import TRTModule
|
yolox/utils/ema.py
CHANGED
@@ -12,12 +12,9 @@ __all__ = ["ModelEMA", "is_parallel"]
|
|
12 |
|
13 |
def is_parallel(model):
|
14 |
"""check if model is in parallel mode."""
|
15 |
-
import apex
|
16 |
-
|
17 |
parallel_type = (
|
18 |
nn.parallel.DataParallel,
|
19 |
nn.parallel.DistributedDataParallel,
|
20 |
-
apex.parallel.distributed.DistributedDataParallel,
|
21 |
)
|
22 |
return isinstance(model, parallel_type)
|
23 |
|
|
|
12 |
|
13 |
def is_parallel(model):
|
14 |
"""check if model is in parallel mode."""
|
|
|
|
|
15 |
parallel_type = (
|
16 |
nn.parallel.DataParallel,
|
17 |
nn.parallel.DistributedDataParallel,
|
|
|
18 |
)
|
19 |
return isinstance(model, parallel_type)
|
20 |
|