Skip to content

Commit eb20200

Browse files
committed
yolov3-spp update
1 parent 35d59c9 commit eb20200

File tree

5 files changed

+47
-69
lines changed

5 files changed

+47
-69
lines changed

yolov3-spp/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@ find_package(CUDA REQUIRED)
1313
set(CUDA_NVCC_PLAGS ${CUDA_NVCC_PLAGS};-std=c++11;-g;-G;-gencode;arch=compute_30;code=sm_30)
1414

1515
include_directories(${PROJECT_SOURCE_DIR}/include)
16-
include_directories(/usr/local/cuda/targets/aarch64-linux/include)
17-
link_directories(/usr/local/cuda/targets/aarch64-linux/lib)
16+
if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
17+
message("embed_platform on")
18+
include_directories(/usr/local/cuda/targets/aarch64-linux/include)
19+
link_directories(/usr/local/cuda/targets/aarch64-linux/lib)
20+
else()
21+
message("embed_platform off")
22+
include_directories(/usr/local/cuda/include)
23+
link_directories(/usr/local/cuda/lib64)
24+
endif()
25+
1826

1927
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Ofast -Wfatal-errors -D_MWAITXINTRIN_H_INCLUDED")
2028

yolov3-spp/YoloConfigs.h

Lines changed: 0 additions & 55 deletions
This file was deleted.

yolov3-spp/yololayer.cu

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include "YoloConfigs.h"
21
#include "yololayer.h"
32

43
using namespace Yolo;
@@ -205,7 +204,7 @@ namespace nvinfer1
205204
}
206205
}
207206
float box_prob = Logist(input[input_col + k * info_len_i * total_grid + 4 * total_grid]);
208-
if (max_cls_prob < 0.1 || box_prob < 0.1) continue;
207+
if (max_cls_prob < IGNORE_THRESH || box_prob < IGNORE_THRESH) continue;
209208

210209
float *res_count = output;
211210
int count = (int)atomicAdd(res_count, 1);

yolov3-spp/yololayer.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,34 @@
1212

1313
namespace Yolo
1414
{
15-
struct YoloKernel;
15+
static constexpr int CHECK_COUNT = 3;
16+
static constexpr float IGNORE_THRESH = 0.1f;
17+
static constexpr int CLASS_NUM = 80;
18+
static constexpr int INPUT_H = 608;
19+
static constexpr int INPUT_W = 608;
20+
21+
struct YoloKernel
22+
{
23+
int width;
24+
int height;
25+
float anchors[CHECK_COUNT*2];
26+
};
27+
28+
static YoloKernel yolo1 = {
29+
INPUT_W / 32,
30+
INPUT_H / 32,
31+
{116,90, 156,198, 373,326}
32+
};
33+
static YoloKernel yolo2 = {
34+
INPUT_W / 16,
35+
INPUT_H / 16,
36+
{30,61, 62,45, 59,119}
37+
};
38+
static YoloKernel yolo3 = {
39+
INPUT_W / 8,
40+
INPUT_H / 8,
41+
{10,13, 16,30, 33,23}
42+
};
1643

1744
static constexpr int LOCATIONS = 4;
1845
struct alignas(float) Detection{

yolov3-spp/yolov3-spp.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
#define DEVICE 0 // GPU id
1818

1919
using namespace nvinfer1;
20-
using namespace Yolo;
2120

2221
// stuff we know about the network and the input/output blobs
23-
static const int INPUT_H = 256;
24-
static const int INPUT_W = 416;
22+
static const int INPUT_H = Yolo::INPUT_H;
23+
static const int INPUT_W = Yolo::INPUT_W;
2524
static const int OUTPUT_SIZE = 1000 * 7 + 1; // we assume the yololayer outputs no more than 1000 boxes that conf >= 0.1
2625
const char* INPUT_BLOB_NAME = "data";
2726
const char* OUTPUT_BLOB_NAME = "prob";
@@ -90,17 +89,17 @@ float iou(float lbox[4], float rbox[4]) {
9089
return interBoxS/(lbox[2]*lbox[3] + rbox[2]*rbox[3] -interBoxS);
9190
}
9291

93-
bool cmp(Detection& a, Detection& b) {
92+
bool cmp(Yolo::Detection& a, Yolo::Detection& b) {
9493
return a.det_confidence > b.det_confidence;
9594
}
9695

97-
void nms(std::vector<Detection>& res, float *output, float nms_thresh = 0.4) {
98-
std::map<float, std::vector<Detection>> m;
96+
void nms(std::vector<Yolo::Detection>& res, float *output, float nms_thresh = 0.4) {
97+
std::map<float, std::vector<Yolo::Detection>> m;
9998
for (int i = 0; i < output[0] && i < 1000; i++) {
10099
if (output[1 + 7 * i + 4] <= 0.5) continue;
101-
Detection det;
100+
Yolo::Detection det;
102101
memcpy(&det, &output[1 + 7 * i], 7 * sizeof(float));
103-
if (m.count(det.class_id) == 0) m.emplace(det.class_id, std::vector<Detection>());
102+
if (m.count(det.class_id) == 0) m.emplace(det.class_id, std::vector<Yolo::Detection>());
104103
m[det.class_id].push_back(det);
105104
}
106105
for (auto it = m.begin(); it != m.end(); it++) {
@@ -535,7 +534,7 @@ int main(int argc, char** argv) {
535534
// Run inference
536535
auto start = std::chrono::system_clock::now();
537536
doInference(*context, data, prob, 1);
538-
std::vector<Detection> res;
537+
std::vector<Yolo::Detection> res;
539538
nms(res, prob);
540539
auto end = std::chrono::system_clock::now();
541540
std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;

0 commit comments

Comments
 (0)