4
4
import tensorflow as tf
5
5
from .common import *
6
6
7
+
7
8
def darknet53 (input_data ):
8
9
9
- input_data = convolutional (input_data , (3 , 3 , 3 , 32 ))
10
- input_data = convolutional (input_data , (3 , 3 , 32 , 64 ), downsample = True )
10
+ input_data = convolutional (input_data , (3 , 3 , 3 , 32 ))
11
+ input_data = convolutional (input_data , (3 , 3 , 32 , 64 ), downsample = True )
11
12
12
13
for i in range (1 ):
13
- input_data = residual_block (input_data , 64 , 32 , 64 )
14
+ input_data = residual_block (input_data , 64 , 32 , 64 )
14
15
15
- input_data = convolutional (input_data , (3 , 3 , 64 , 128 ), downsample = True )
16
+ input_data = convolutional (input_data , (3 , 3 , 64 , 128 ), downsample = True )
16
17
17
18
for i in range (2 ):
18
- input_data = residual_block (input_data , 128 , 64 , 128 )
19
+ input_data = residual_block (input_data , 128 , 64 , 128 )
19
20
20
21
input_data = convolutional (input_data , (3 , 3 , 128 , 256 ), downsample = True )
21
22
@@ -36,74 +37,118 @@ def darknet53(input_data):
36
37
37
38
return route_1 , route_2 , input_data
38
39
40
+
39
41
def cspdarknet53 (input_data ):
40
42
41
- input_data = convolutional (input_data , (3 , 3 , 3 , 32 ), activate_type = "mish" )
42
- input_data = convolutional (input_data , (3 , 3 , 32 , 64 ), downsample = True , activate_type = "mish" )
43
+ input_data = convolutional (input_data , (3 , 3 , 3 , 32 ), activate_type = "mish" )
44
+ input_data = convolutional (
45
+ input_data , (3 , 3 , 32 , 64 ), downsample = True , activate_type = "mish" )
43
46
44
47
route = input_data
45
48
route = convolutional (route , (1 , 1 , 64 , 64 ), activate_type = "mish" )
46
- input_data = convolutional (input_data , (1 , 1 , 64 , 64 ), activate_type = "mish" )
49
+ input_data = convolutional (
50
+ input_data , (1 , 1 , 64 , 64 ), activate_type = "mish" )
47
51
for i in range (1 ):
48
- input_data = residual_block (input_data , 64 , 32 , 64 , activate_type = "mish" )
49
- input_data = convolutional (input_data , (1 , 1 , 64 , 64 ), activate_type = "mish" )
52
+ input_data = residual_block (
53
+ input_data , 64 , 32 , 64 , activate_type = "mish" )
54
+ input_data = convolutional (
55
+ input_data , (1 , 1 , 64 , 64 ), activate_type = "mish" )
50
56
51
57
input_data = tf .concat ([input_data , route ], axis = - 1 )
52
- input_data = convolutional (input_data , (1 , 1 , 128 , 64 ), activate_type = "mish" )
53
- input_data = convolutional (input_data , (3 , 3 , 64 , 128 ), downsample = True , activate_type = "mish" )
58
+ input_data = convolutional (
59
+ input_data , (1 , 1 , 128 , 64 ), activate_type = "mish" )
60
+ input_data = convolutional (
61
+ input_data , (3 , 3 , 64 , 128 ), downsample = True , activate_type = "mish" )
54
62
route = input_data
55
63
route = convolutional (route , (1 , 1 , 128 , 64 ), activate_type = "mish" )
56
- input_data = convolutional (input_data , (1 , 1 , 128 , 64 ), activate_type = "mish" )
64
+ input_data = convolutional (
65
+ input_data , (1 , 1 , 128 , 64 ), activate_type = "mish" )
57
66
for i in range (2 ):
58
- input_data = residual_block (input_data , 64 , 64 , 64 , activate_type = "mish" )
59
- input_data = convolutional (input_data , (1 , 1 , 64 , 64 ), activate_type = "mish" )
67
+ input_data = residual_block (
68
+ input_data , 64 , 64 , 64 , activate_type = "mish" )
69
+ input_data = convolutional (
70
+ input_data , (1 , 1 , 64 , 64 ), activate_type = "mish" )
60
71
input_data = tf .concat ([input_data , route ], axis = - 1 )
61
72
62
- input_data = convolutional (input_data , (1 , 1 , 128 , 128 ), activate_type = "mish" )
63
- input_data = convolutional (input_data , (3 , 3 , 128 , 256 ), downsample = True , activate_type = "mish" )
73
+ input_data = convolutional (
74
+ input_data , (1 , 1 , 128 , 128 ), activate_type = "mish" )
75
+ input_data = convolutional (
76
+ input_data , (3 , 3 , 128 , 256 ), downsample = True , activate_type = "mish" )
64
77
route = input_data
65
78
route = convolutional (route , (1 , 1 , 256 , 128 ), activate_type = "mish" )
66
- input_data = convolutional (input_data , (1 , 1 , 256 , 128 ), activate_type = "mish" )
79
+ input_data = convolutional (
80
+ input_data , (1 , 1 , 256 , 128 ), activate_type = "mish" )
67
81
for i in range (8 ):
68
- input_data = residual_block (input_data , 128 , 128 , 128 , activate_type = "mish" )
69
- input_data = convolutional (input_data , (1 , 1 , 128 , 128 ), activate_type = "mish" )
82
+ input_data = residual_block (
83
+ input_data , 128 , 128 , 128 , activate_type = "mish" )
84
+ input_data = convolutional (
85
+ input_data , (1 , 1 , 128 , 128 ), activate_type = "mish" )
70
86
input_data = tf .concat ([input_data , route ], axis = - 1 )
71
87
72
- input_data = convolutional (input_data , (1 , 1 , 256 , 256 ), activate_type = "mish" )
88
+ input_data = convolutional (
89
+ input_data , (1 , 1 , 256 , 256 ), activate_type = "mish" )
73
90
route_1 = input_data
74
- input_data = convolutional (input_data , (3 , 3 , 256 , 512 ), downsample = True , activate_type = "mish" )
91
+ input_data = convolutional (
92
+ input_data , (3 , 3 , 256 , 512 ), downsample = True , activate_type = "mish" )
75
93
route = input_data
76
94
route = convolutional (route , (1 , 1 , 512 , 256 ), activate_type = "mish" )
77
- input_data = convolutional (input_data , (1 , 1 , 512 , 256 ), activate_type = "mish" )
95
+ input_data = convolutional (
96
+ input_data , (1 , 1 , 512 , 256 ), activate_type = "mish" )
78
97
for i in range (8 ):
79
- input_data = residual_block (input_data , 256 , 256 , 256 , activate_type = "mish" )
80
- input_data = convolutional (input_data , (1 , 1 , 256 , 256 ), activate_type = "mish" )
98
+ input_data = residual_block (
99
+ input_data , 256 , 256 , 256 , activate_type = "mish" )
100
+ input_data = convolutional (
101
+ input_data , (1 , 1 , 256 , 256 ), activate_type = "mish" )
81
102
input_data = tf .concat ([input_data , route ], axis = - 1 )
82
103
83
- input_data = convolutional (input_data , (1 , 1 , 512 , 512 ), activate_type = "mish" )
104
+ input_data = convolutional (
105
+ input_data , (1 , 1 , 512 , 512 ), activate_type = "mish" )
84
106
route_2 = input_data
85
- input_data = convolutional (input_data , (3 , 3 , 512 , 1024 ), downsample = True , activate_type = "mish" )
107
+ input_data = convolutional (
108
+ input_data , (3 , 3 , 512 , 1024 ), downsample = True , activate_type = "mish" )
86
109
route = input_data
87
110
route = convolutional (route , (1 , 1 , 1024 , 512 ), activate_type = "mish" )
88
- input_data = convolutional (input_data , (1 , 1 , 1024 , 512 ), activate_type = "mish" )
111
+ input_data = convolutional (
112
+ input_data , (1 , 1 , 1024 , 512 ), activate_type = "mish" )
89
113
for i in range (4 ):
90
- input_data = residual_block (input_data , 512 , 512 , 512 , activate_type = "mish" )
91
- input_data = convolutional (input_data , (1 , 1 , 512 , 512 ), activate_type = "mish" )
114
+ input_data = residual_block (
115
+ input_data , 512 , 512 , 512 , activate_type = "mish" )
116
+ input_data = convolutional (
117
+ input_data , (1 , 1 , 512 , 512 ), activate_type = "mish" )
92
118
input_data = tf .concat ([input_data , route ], axis = - 1 )
93
119
94
- input_data = convolutional (input_data , (1 , 1 , 1024 , 1024 ), activate_type = "mish" )
120
+ input_data = convolutional (
121
+ input_data , (1 , 1 , 1024 , 1024 ), activate_type = "mish" )
95
122
input_data = convolutional (input_data , (1 , 1 , 1024 , 512 ))
96
123
input_data = convolutional (input_data , (3 , 3 , 512 , 1024 ))
97
124
input_data = convolutional (input_data , (1 , 1 , 1024 , 512 ))
98
125
99
- input_data = tf .concat ([tf .nn .max_pool (input_data , ksize = 13 , padding = 'SAME' , strides = 1 ), tf .nn .max_pool (input_data , ksize = 9 , padding = 'SAME' , strides = 1 )
100
- , tf .nn .max_pool (input_data , ksize = 5 , padding = 'SAME' , strides = 1 ), input_data ], axis = - 1 )
126
+ input_data = tf .concat (
127
+ [
128
+ tf .nn .max_pool (
129
+ input_data ,
130
+ ksize = 13 ,
131
+ padding = 'SAME' ,
132
+ strides = 1 ),
133
+ tf .nn .max_pool (
134
+ input_data ,
135
+ ksize = 9 ,
136
+ padding = 'SAME' ,
137
+ strides = 1 ),
138
+ tf .nn .max_pool (
139
+ input_data ,
140
+ ksize = 5 ,
141
+ padding = 'SAME' ,
142
+ strides = 1 ),
143
+ input_data ],
144
+ axis = - 1 )
101
145
input_data = convolutional (input_data , (1 , 1 , 2048 , 512 ))
102
146
input_data = convolutional (input_data , (3 , 3 , 512 , 1024 ))
103
147
input_data = convolutional (input_data , (1 , 1 , 1024 , 512 ))
104
148
105
149
return route_1 , route_2 , input_data
106
150
151
+
107
152
def cspdarknet53_tiny (input_data ):
108
153
input_data = convolutional (input_data , (3 , 3 , 3 , 32 ), downsample = True )
109
154
input_data = convolutional (input_data , (3 , 3 , 32 , 64 ), downsample = True )
@@ -146,6 +191,7 @@ def cspdarknet53_tiny(input_data):
146
191
147
192
return route_1 , input_data
148
193
194
+
149
195
def darknet53_tiny (input_data ):
150
196
input_data = convolutional (input_data , (3 , 3 , 3 , 16 ))
151
197
input_data = tf .keras .layers .MaxPool2D (2 , 2 , 'same' )(input_data )
@@ -163,5 +209,3 @@ def darknet53_tiny(input_data):
163
209
input_data = convolutional (input_data , (3 , 3 , 512 , 1024 ))
164
210
165
211
return route_1 , input_data
166
-
167
-
0 commit comments