Skip to content
This repository was archived by the owner on Aug 11, 2023. It is now read-only.

Commit 72591c3

Browse files
authored
Merge pull request #63 from hhk7734/dev-v3.0.0
yolov4 v3.0.0
2 parents 4f75970 + 44d33c1 commit 72591c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+6424
-3285
lines changed

.clang-format

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# clang-format-9
2+
Language: Cpp
3+
AccessModifierOffset: -4 # public: private: 들여쓰기 offset
4+
AlignAfterOpenBracket: Align # 매개변수 정렬
5+
AlignConsecutiveMacros: true # 매크로 정렬
6+
AlignConsecutiveAssignments: true # 연속적인 변수 초기화 정렬
7+
AlignConsecutiveDeclarations: true # 연속적인 타입 변수 정렬
8+
AlignEscapedNewlines: Left # \ 줄바꾸기 가장 가까운 쪽
9+
AlignOperands: true # 연산자 정렬
10+
AlignTrailingComments: true # 끝의 주석 정렬
11+
12+
AllowAllConstructorInitializersOnNextLine: false
13+
AllowAllParametersOfDeclarationOnNextLine: false # 길면 한 줄에 하나씩
14+
15+
AllowShortBlocksOnASingleLine: true # 짧으면 한 줄로
16+
AllowShortCaseLabelsOnASingleLine: true
17+
AllowShortFunctionsOnASingleLine: All
18+
AllowShortIfStatementsOnASingleLine: Always
19+
AllowShortLambdasOnASingleLine: All
20+
AllowShortLoopsOnASingleLine: true
21+
22+
AlwaysBreakAfterReturnType: None # 리턴타입 줄 바꿈
23+
AlwaysBreakBeforeMultilineStrings: true # 여러 줄 str 처음 줄 바꿈
24+
AlwaysBreakTemplateDeclarations: Yes # 템플릿 줄 바꿈
25+
26+
BinPackArguments: false # 매개변수 정렬
27+
BinPackParameters: false # 선언시 매개변수 정렬
28+
29+
BreakBeforeBraces: Custom
30+
BraceWrapping: # 다음줄에 괄호를 시작할지 결정
31+
AfterCaseLabel: false
32+
AfterClass: false
33+
AfterControlStatement: false
34+
AfterEnum: false
35+
AfterFunction: false
36+
AfterNamespace: false
37+
AfterStruct: false
38+
AfterUnion: false
39+
AfterExternBlock: false
40+
BeforeCatch: false
41+
BeforeElse: false
42+
IndentBraces: false
43+
SplitEmptyFunction: false
44+
SplitEmptyRecord: false
45+
SplitEmptyNamespace: false
46+
47+
BreakBeforeBinaryOperators: All # 연산자 전에 줄 바꿈
48+
BreakBeforeTernaryOperators: true # ? : (삼항)연산자 전에 줄 바꿈
49+
BreakConstructorInitializers: BeforeComma
50+
BreakInheritanceList: BeforeComma
51+
52+
ColumnLimit: 80 # 한 줄 간격
53+
# CommentPragmas: '^ IWYU pragma:'
54+
CompactNamespaces: false
55+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
56+
ConstructorInitializerIndentWidth: 4
57+
ContinuationIndentWidth: 4
58+
59+
Cpp11BracedListStyle: true # {} 시작과 끝 띄어쓰기 x
60+
DerivePointerAlignment: false # .PointerAlignmet fallback
61+
DisableFormat: false
62+
63+
FixNamespaceComments: true
64+
IncludeBlocks: Regroup
65+
IncludeCategories:
66+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
67+
Priority: 2
68+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
69+
Priority: 3
70+
- Regex: '<[[:alnum:].]+>'
71+
Priority: 4
72+
- Regex: '.*'
73+
Priority: 1
74+
IncludeIsMainRegex: '(Test)?$'
75+
76+
IndentCaseLabels: false
77+
IndentPPDirectives: None # 전처리 indent 안함
78+
IndentWidth: 4
79+
IndentWrappedFunctionNames: true
80+
81+
KeepEmptyLinesAtTheStartOfBlocks: false # 시작 시 빈줄 제거
82+
MaxEmptyLinesToKeep: 2 # 최대 빈 줄
83+
NamespaceIndentation: Inner
84+
85+
PointerAlignment: Right # uint16_t *a;
86+
ReflowComments: true # comment 줄 변경
87+
88+
SortIncludes: true
89+
SortUsingDeclarations: true
90+
91+
SpaceAfterCStyleCast: false
92+
SpaceAfterLogicalNot: true
93+
SpaceAfterTemplateKeyword: false
94+
95+
SpaceBeforeAssignmentOperators: true # = 앞 공백
96+
SpaceBeforeCpp11BracedList: true
97+
SpaceBeforeCtorInitializerColon: false
98+
SpaceBeforeInheritanceColon: false
99+
SpaceBeforeParens: Never # () 앞 띄어쓰기
100+
SpaceBeforeRangeBasedForLoopColon: false
101+
SpacesBeforeTrailingComments: 4 # // 앞 공백
102+
103+
SpaceInEmptyParentheses: false
104+
SpacesInAngles: false
105+
SpacesInCStyleCastParentheses: false
106+
SpacesInContainerLiterals: false
107+
SpacesInParentheses: false
108+
SpacesInSquareBrackets: false
109+
110+
Standard: Cpp11
111+
TabWidth: 4
112+
UseTab: Never
113+

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ __pycache__
44
build
55
checkpoints
66
dist
7-
log
7+
log*
8+
test*
9+
tmp
10+
train*
811
venv
9-
yolov4.egg-info
12+
yolov4.egg-info
13+
*.zip

.vscode/c_cpp_properties.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "pybind11",
5+
"includePath": ["${workspaceFolder}/**"],
6+
"cStandard": "c11",
7+
"cppStandard": "c++14",
8+
"browse": {
9+
"path": [
10+
"${workspaceFolder}/c_src",
11+
"${workspaceFolder}/venv/lib/python3.7/site-packages/pybind11/include",
12+
"${workspaceFolder}/venv/lib/python3.8/site-packages/pybind11/include"
13+
],
14+
"limitSymbolsToIncludedHeaders": true
15+
}
16+
}
17+
],
18+
"version": 4
19+
}

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MIT License
22

33
Copyright (c) 2020 Việt Hùng
4-
Copyright (c) 2020 Hyeonki Hong <hhk7734@gmail.com>
4+
Copyright (c) 2020-2021 Hyeonki Hong <hhk7734@gmail.com>
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal

MANIFEST.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
include LICENSE.txt
22
include README.md
3-
include CHANGELOG
3+
include CHANGELOG
4+
include c_src/*

c_src/box.cpp

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2021 Hyeonki Hong <hhk7734@gmail.com>
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
#include "box.h"
25+
26+
#include <math.h>
27+
28+
float get_diou(const xywh &a,
29+
const xywh &b,
30+
const lrtb &a_lrtb,
31+
const lrtb &b_lrtb,
32+
const float beta1) {
33+
lrtb in_lrtb, out_lrtb;
34+
get_in_out_lrtb(a_lrtb, b_lrtb, in_lrtb, out_lrtb);
35+
float in_w = in_lrtb.r - in_lrtb.l;
36+
float in_h = in_lrtb.b - in_lrtb.t;
37+
float out_w = out_lrtb.r - out_lrtb.l;
38+
float out_h = out_lrtb.b - out_lrtb.t;
39+
40+
float iou;
41+
if(in_w <= 0 or in_h <= 0) {
42+
iou = 0;
43+
if(out_w == 0 and out_h == 0) { return 0; }
44+
} else {
45+
float in = in_w * in_h;
46+
float uni = a.w * a.h + b.w * b.h - in;
47+
iou = in / uni;
48+
}
49+
50+
float c = out_w * out_w + out_h * out_h;
51+
float d = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
52+
float rdiou = pow(d / c, beta1);
53+
return iou - rdiou;
54+
}
55+
56+
void get_in_out_lrtb(const lrtb &a, const lrtb &b, lrtb &in, lrtb &out) {
57+
if(a.l > b.l) {
58+
in.l = a.l;
59+
out.l = b.l;
60+
} else {
61+
in.l = b.l;
62+
out.l = a.l;
63+
}
64+
if(a.r < b.r) {
65+
in.r = a.r;
66+
out.r = b.r;
67+
} else {
68+
in.r = b.r;
69+
out.r = a.r;
70+
}
71+
if(a.t > b.t) {
72+
in.t = a.t;
73+
out.t = b.t;
74+
} else {
75+
in.t = b.t;
76+
out.t = a.t;
77+
}
78+
if(a.b < b.b) {
79+
in.b = a.b;
80+
out.b = b.b;
81+
} else {
82+
in.b = b.b;
83+
out.b = a.b;
84+
}
85+
}
86+
87+
float get_iou(const xywh &a, const xywh &b) {
88+
lrtb a_lrtb = get_lrtb(a);
89+
lrtb b_lrtb = get_lrtb(b);
90+
lrtb in_lrtb;
91+
92+
in_lrtb.l = a_lrtb.l > b_lrtb.l ? a_lrtb.l : b_lrtb.l;
93+
in_lrtb.r = a_lrtb.r < b_lrtb.r ? a_lrtb.r : b_lrtb.r;
94+
float in_w = in_lrtb.r - in_lrtb.l;
95+
if(in_w <= 0) { return 0; }
96+
97+
in_lrtb.t = a_lrtb.t > b_lrtb.t ? a_lrtb.t : b_lrtb.t;
98+
in_lrtb.b = a_lrtb.b < b_lrtb.b ? a_lrtb.b : b_lrtb.b;
99+
float in_h = in_lrtb.b - in_lrtb.t;
100+
if(in_h <= 0) { return 0; }
101+
102+
float in = in_w * in_h;
103+
float uni = a.w * a.h + b.w * b.h - in;
104+
return in / uni;
105+
}
106+
107+
lrtb get_lrtb(const xywh &a) {
108+
float w_2 = a.w / 2;
109+
float h_2 = a.h / 2;
110+
return lrtb {
111+
.l = a.x - w_2,
112+
.r = a.x + w_2,
113+
.t = a.y - h_2,
114+
.b = a.y + h_2,
115+
};
116+
}

c_src/box.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2021 Hyeonki Hong <hhk7734@gmail.com>
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
#pragma once
25+
26+
typedef struct xywh {
27+
// center x, center y, width, height
28+
float x, y, w, h;
29+
} xywh;
30+
31+
typedef struct lrtb {
32+
// top, left, bottom, right
33+
float l, r, t, b;
34+
} lrtb;
35+
36+
typedef struct pred_xywh {
37+
// center x, center y, width, height, obj, cls_id0, prob0, cls_id1, prob1
38+
float x, y, w, h, o, id0, p0, id1, p1;
39+
} pred_xywh;
40+
41+
float get_diou(const xywh &a_xywh,
42+
const xywh &b_xywh,
43+
const lrtb &a_lrtb,
44+
const lrtb &b_lrtb,
45+
const float beta1);
46+
47+
void get_in_out_lrtb(const lrtb &a, const lrtb &b, lrtb &in, lrtb &out);
48+
49+
float get_iou(const xywh &a, const xywh &b);
50+
51+
lrtb get_lrtb(const xywh &a);

0 commit comments

Comments
 (0)