@@ -62,9 +62,11 @@ def parse_cfg(cfgfile):
62
62
key ,value = line .split ("=" )
63
63
block [key .rstrip ()] = value .lstrip ()
64
64
blocks .append (block )
65
+
65
66
return blocks
66
67
# print('\n\n'.join([repr(x) for x in blocks]))
67
-
68
+
69
+ import pickle as pkl
68
70
69
71
class MaxPoolStride1 (nn .Module ):
70
72
def __init__ (self , kernel_size ):
@@ -73,9 +75,10 @@ def __init__(self, kernel_size):
73
75
self .pad = kernel_size - 1
74
76
75
77
def forward (self , x ):
76
- padded_x = F .pad (x , (0 , self .pad , 0 , self .pad ), mode = "replicate" )
77
- pooled_x = F . max_pool2d ( padded_x , self .kernel_size , padding = self .pad )
78
+ padded_x = F .pad (x , (0 ,self .pad ,0 , self .pad ), mode = "replicate" )
79
+ pooled_x = nn . MaxPool2d ( self .kernel_size , self .pad )( padded_x )
78
80
return pooled_x
81
+
79
82
80
83
class EmptyLayer (nn .Module ):
81
84
def __init__ (self ):
@@ -237,13 +240,24 @@ def create_modules(blocks):
237
240
238
241
239
242
#shortcut corresponds to skip connection
240
- if x ["type" ] == "shortcut" :
243
+ elif x ["type" ] == "shortcut" :
241
244
from_ = int (x ["from" ])
242
245
shortcut = EmptyLayer ()
243
246
module .add_module ("shortcut_{}" .format (index ), shortcut )
247
+
248
+
249
+ elif x ["type" ] == "maxpool" :
250
+ stride = int (x ["stride" ])
251
+ size = int (x ["size" ])
252
+ if stride != 1 :
253
+ maxpool = nn .MaxPool2d (size , stride )
254
+ else :
255
+ maxpool = MaxPoolStride1 (size )
256
+
257
+ module .add_module ("maxpool_{}" .format (index ), maxpool )
244
258
245
259
#Yolo is the detection layer
246
- if x ["type" ] == "yolo" :
260
+ elif x ["type" ] == "yolo" :
247
261
mask = x ["mask" ].split ("," )
248
262
mask = [int (x ) for x in mask ]
249
263
@@ -255,15 +269,19 @@ def create_modules(blocks):
255
269
256
270
detection = DetectionLayer (anchors )
257
271
module .add_module ("Detection_{}" .format (index ), detection )
272
+
258
273
259
274
260
-
275
+ else :
276
+ print ("Something I dunno" )
277
+ assert False
261
278
262
279
263
280
module_list .append (module )
264
281
prev_filters = filters
265
282
output_filters .append (filters )
266
283
index += 1
284
+
267
285
268
286
return (net_info , module_list )
269
287
@@ -295,9 +313,8 @@ def forward(self, x, CUDA):
295
313
write = 0
296
314
for i in range (len (modules )):
297
315
298
-
299
316
module_type = (modules [i ]["type" ])
300
- if module_type == "convolutional" or module_type == "upsample" :
317
+ if module_type == "convolutional" or module_type == "upsample" or module_type == "maxpool" :
301
318
302
319
x = self .module_list [i ](x )
303
320
outputs [i ] = x
@@ -320,13 +337,16 @@ def forward(self, x, CUDA):
320
337
map1 = outputs [i + layers [0 ]]
321
338
map2 = outputs [i + layers [1 ]]
322
339
340
+
323
341
x = torch .cat ((map1 , map2 ), 1 )
324
342
outputs [i ] = x
325
343
326
344
elif module_type == "shortcut" :
327
345
from_ = int (modules [i ]["from" ])
328
346
x = outputs [i - 1 ] + outputs [i + from_ ]
329
347
outputs [i ] = x
348
+
349
+
330
350
331
351
elif module_type == 'yolo' :
332
352
@@ -353,6 +373,7 @@ def forward(self, x, CUDA):
353
373
detections = torch .cat ((detections , x ), 1 )
354
374
355
375
outputs [i ] = outputs [i - 1 ]
376
+
356
377
357
378
358
379
try :
0 commit comments