@@ -22,6 +22,7 @@ namespace tk { namespace dnn {
22
22
int classes = 20 ;
23
23
int num = 1 ;
24
24
int pad = 0 ;
25
+ int coords = 4 ;
25
26
float scale_xy = 1 ;
26
27
std::vector<int > layers;
27
28
std::string activation = " linear" ;
@@ -102,9 +103,11 @@ namespace tk { namespace dnn {
102
103
fields.classes = std::stoi (value);
103
104
else if (name.find (" num" ) != std::string::npos)
104
105
fields.num = std::stoi (value);
106
+ else if (name.find (" coords" ) != std::string::npos)
107
+ fields.coords = std::stoi (value);
105
108
else if (name.find (" groups" ) != std::string::npos)
106
109
fields.groups = std::stoi (value);
107
- else if (name.find (" scale_xy " ) != std::string::npos)
110
+ else if (name.find (" scale_x_y " ) != std::string::npos)
108
111
fields.scale_xy = std::stof (value);
109
112
else if (name.find (" from" ) != std::string::npos)
110
113
fields.layers .push_back (std::stof (value));
@@ -135,23 +138,25 @@ namespace tk { namespace dnn {
135
138
if (f.pad == 1 ) {
136
139
f.padding_x = f.padding_y = f.size_x /2 ;
137
140
}
138
-
139
141
std::cout<<" Add layer: " <<f.type <<" \n " ;
140
142
if (f.type == " convolutional" ) {
141
143
std::string wgs = wgs_path + " /c" + std::to_string (netLayers.size ()) + " .bin" ;
142
144
printf (" %d (%d,%d) (%d,%d) (%d,%d) %s %d %d\n " , f.filters , f.size_x , f.size_y , f.stride_x , f.stride_y , f.padding_x , f.padding_y , wgs.c_str (), f.batch_normalize , f.groups );
143
145
tk::dnn::Conv2d *l= new tk::dnn::Conv2d (net, f.filters , f.size_x , f.size_y , f.stride_x ,
144
146
f.stride_y , f.padding_x , f.padding_y , wgs, f.batch_normalize , false , f.groups );
145
- if (f.activation != " linear" ) {
146
- tkdnnActivationMode_t act;
147
- if (f.activation == " relu" ) act = tkdnnActivationMode_t (CUDNN_ACTIVATION_RELU);
148
- else if (f.activation == " leaky" ) act = tk::dnn::ACTIVATION_LEAKY;
149
- else if (f.activation == " mish" ) act = tk::dnn::ACTIVATION_MISH;
150
- else { FatalError (" activation not supported: " + f.activation ); }
151
- netLayers.push_back (new tk::dnn::Activation (net, act));
152
- } else {
153
- netLayers.push_back (l);
154
- }
147
+ netLayers.push_back (l);
148
+ } else if (f.type == " maxpool" ) {
149
+ if (f.stride_x == 1 && f.stride_y == 1 )
150
+ netLayers.push_back (new tk::dnn::Pooling (net, f.size_x , f.size_y , f.stride_x , f.stride_y ,
151
+ f.padding_x , f.padding_y , tk::dnn::POOLING_MAX_FIXEDSIZE));
152
+ else
153
+ netLayers.push_back (new tk::dnn::Pooling (net, f.size_x , f.size_y , f.stride_x , f.stride_y ,
154
+ f.padding_x , f.padding_y , tk::dnn::POOLING_MAX));
155
+
156
+ } else if (f.type == " avgpool" ) {
157
+ netLayers.push_back (new tk::dnn::Pooling (net, f.size_x , f.size_y , f.stride_x , f.stride_y ,
158
+ f.padding_x , f.padding_y , tk::dnn::POOLING_AVERAGE));
159
+
155
160
} else if (f.type == " shortcut" ) {
156
161
if (f.layers .size () != 1 ) FatalError (" no layers to shortcut\n " );
157
162
int layerIdx = f.layers [0 ];
@@ -177,6 +182,12 @@ namespace tk { namespace dnn {
177
182
}
178
183
netLayers.push_back (new tk::dnn::Route (net, layers.data (), layers.size ()));
179
184
185
+ } else if (f.type == " reorg" ) {
186
+ netLayers.push_back (new tk::dnn::Reorg (net, f.stride_x ));
187
+
188
+ } else if (f.type == " region" ) {
189
+ netLayers.push_back (new tk::dnn::Region (net, f.classes , f.coords , f.num ));
190
+
180
191
} else if (f.type == " yolo" ) {
181
192
std::string wgs = wgs_path + " /g" + std::to_string (netLayers.size ()) + " .bin" ;
182
193
printf (" %d %d %s %d %f\n " , f.classes , f.num /f.n_mask , wgs.c_str (), f.n_mask , f.scale_xy );
@@ -189,6 +200,16 @@ namespace tk { namespace dnn {
189
200
} else {
190
201
FatalError (" layer not supported: " + f.type );
191
202
}
203
+
204
+ // add activation
205
+ if (netLayers.size () > 0 && f.activation != " linear" ) {
206
+ tkdnnActivationMode_t act;
207
+ if (f.activation == " relu" ) act = tkdnnActivationMode_t (CUDNN_ACTIVATION_RELU);
208
+ else if (f.activation == " leaky" ) act = tk::dnn::ACTIVATION_LEAKY;
209
+ else if (f.activation == " mish" ) act = tk::dnn::ACTIVATION_MISH;
210
+ else { FatalError (" activation not supported: " + f.activation ); }
211
+ netLayers[netLayers.size ()-1 ] = new tk::dnn::Activation (net, act);
212
+ };
192
213
}
193
214
194
215
std::vector<std::string> darknetReadNames (const std::string& names_file){
@@ -244,7 +265,7 @@ namespace tk { namespace dnn {
244
265
245
266
// new type
246
267
// std::cout<<"type: "<<type<<"\n";
247
- fields = darknetFields_t ();
268
+ fields = darknetFields_t (); // reset to default
248
269
fields.type = type;
249
270
continue ;
250
271
}
0 commit comments