generated from dlibml/dlib-template-project
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathyolov7.h
113 lines (98 loc) · 4.46 KB
/
yolov7.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef yolov7_h_INCLUDED
#define yolov7_h_INCLUDED
#include <dlib/dnn.h>
namespace yolov7
{
using namespace dlib;
template <typename SUBNET> using ytag3 = add_tag_layer<4003, SUBNET>;
template <typename SUBNET> using ytag4 = add_tag_layer<4004, SUBNET>;
template <typename SUBNET> using ytag5 = add_tag_layer<4005, SUBNET>;
template <typename SUBNET> using ptag3 = add_tag_layer<7003, SUBNET>;
template <typename SUBNET> using ptag4 = add_tag_layer<7004, SUBNET>;
template <typename SUBNET> using ptag5 = add_tag_layer<7005, SUBNET>;
template <typename SUBNET> using ntag4 = add_tag_layer<5004, SUBNET>;
template <template <typename> class ACT, template <typename> class BN>
struct def
{
template <long NF, int KS, int S, typename SUBNET>
using conv = ACT<BN<add_layer<con_<NF, KS, KS, S, S, (KS-1)/2, (KS-1)/2>, SUBNET>>>;
template <long NF, typename SUBNET>
using transition = concat2<itag2, itag1,
itag2<conv<NF, 3, 2,
conv<NF, 1, 1, iskip<
itag1<conv<NF, 1, 1,
max_pool<2, 2, 2, 2,
itag0<SUBNET>>>>>>>>>;
template <long NF, typename SUBNET>
using e_elan = conv<NF * 4, 1, 1,
concat4<itag4, itag3, itag2, itag1,
itag4<conv<NF, 3, 1,
conv<NF, 3, 1,
itag3<conv<NF, 3, 1,
conv<NF, 3, 1,
itag2<conv<NF, 1, 1, iskip<
itag1<conv<NF, 1, 1,
itag0<SUBNET>>>>>>>>>>>>>>;
template <long NF, template<typename> class TAG, typename SUBNET>
using transition2 = concat3<itag2, itag1, TAG,
itag2<conv<NF, 3, 2,
conv<NF, 1, 1, iskip<
itag1<conv<NF, 1, 1,
max_pool<2, 2, 2, 2,
itag0<SUBNET>>>>>>>>>;
template <long NF, typename SUBNET>
using e_elan2 = conv<NF, 1, 1,
add_layer<concat_<tag1, tag2, tag3, tag4, tag5, tag6>,
tag1<conv<NF / 2, 3, 1,
tag2<conv<NF / 2, 3, 1,
tag3<conv<NF / 2, 3, 1,
tag4<conv<NF / 2, 3, 1,
tag5<conv<NF, 1, 1, iskip<
tag6<conv<NF, 1, 1,
itag0<SUBNET>>>>>>>>>>>>>>>>;
template <typename INPUT>
using backbone = ptag5<e_elan<256, transition<512,
ptag4<e_elan<256, transition<256,
ptag3<e_elan<128, transition<128,
e_elan<64, conv<128, 3, 2,
conv<64, 3, 1, conv<64, 3, 2,
conv<32, 3, 1, INPUT>>>>>>>>>>>>>>;
template <long NF, typename SUBNET>
using sppcspc = conv<NF, 1, 1,
concat2<tag1, tag2,
tag2<conv<NF, 1, 1, iskip<
tag1<conv<NF, 3, 1, conv<NF, 1, 1,
concat4<itag1, itag2, itag3, itag4,
itag4<max_pool<5, 5, 1, 1,
itag3<max_pool<5, 5, 1, 1,
itag2<max_pool<5, 5, 1, 1,
itag1<conv<NF, 1, 1, conv<NF, 3, 1, conv<NF, 1, 1,
itag0<SUBNET>>>>>>>>>>>>>>>>>>>>;
template <template <typename> class YTAG, typename SUBNET>
using yolo = YTAG<sig<con<255, 1, 1, 1, 1, SUBNET>>>;
template <typename SUBNET>
using head = yolo<ytag5,
e_elan2<512,
transition2<256, tag8, skip9<
yolo<ytag4,
tag9<e_elan2<256,
transition2<128, tag7, skip9<
yolo<ytag3,
tag9<e_elan2<128,
concat2<tag2, tag1,
tag2<conv<128, 1, 1, add_skip_layer<ptag3,
tag1<upsample<2,
conv<128, 1, 1,
tag7<e_elan2<256,
concat2<tag2, tag1,
tag2<conv<256, 1, 1, add_skip_layer<ptag4,
tag1<upsample<2,
conv<256, 1, 1,
tag8<sppcspc<512,
SUBNET>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
using net_type = loss_yolo<ytag3, ytag4, ytag5, head<backbone<input_rgb_image>>>;
};
using train_type = def<silu, bn_con>::net_type;
using infer_type = def<silu, affine>::net_type;
}
#endif // yolov7_h_INCLUDED