Replace EmptyLayer with nn.Sequential (#420)
* Replace EmptyLayer with nn.Sequential * Update models.py * Update models.py
This commit is contained in:
parent
267b4301e2
commit
333cf92bb2
15
models.py
15
models.py
|
@ -51,14 +51,13 @@ def create_modules(module_defs):
|
||||||
elif module_def['type'] == 'route':
|
elif module_def['type'] == 'route':
|
||||||
layers = [int(x) for x in module_def['layers'].split(',')]
|
layers = [int(x) for x in module_def['layers'].split(',')]
|
||||||
filters = sum([output_filters[i + 1 if i > 0 else i] for i in layers])
|
filters = sum([output_filters[i + 1 if i > 0 else i] for i in layers])
|
||||||
modules.add_module('route_%d' % i, EmptyLayer())
|
modules.add_module('route_%d' % i, nn.Sequential()) # Placeholder for 'route' layer
|
||||||
# if module_defs[i+1]['type'] == 'reorg3d':
|
# if module_defs[i+1]['type'] == 'reorg3d':
|
||||||
# upsample = nn.Upsample(scale_factor=1/float(module_defs[i+1]['stride']), mode='nearest')
|
# upsample = nn.Upsample(scale_factor=1/float(module_defs[i+1]['stride']), mode='nearest')
|
||||||
# modules.add_module('reorg3d_%d' % i, upsample)
|
# modules.add_module('reorg3d_%d' % i, upsample)
|
||||||
|
|
||||||
elif module_def['type'] == 'shortcut':
|
elif module_def['type'] == 'shortcut':
|
||||||
filters = output_filters[int(module_def['from'])]
|
filters = output_filters[int(module_def['from'])]
|
||||||
modules.add_module('shortcut_%d' % i, EmptyLayer())
|
modules.add_module('shortcut_%d' % i, nn.Sequential()) # Placeholder for 'shortcut' layer
|
||||||
|
|
||||||
elif module_def['type'] == 'reorg3d':
|
elif module_def['type'] == 'reorg3d':
|
||||||
# torch.Size([16, 128, 104, 104])
|
# torch.Size([16, 128, 104, 104])
|
||||||
|
@ -86,16 +85,6 @@ def create_modules(module_defs):
|
||||||
return hyperparams, module_list
|
return hyperparams, module_list
|
||||||
|
|
||||||
|
|
||||||
class EmptyLayer(nn.Module):
|
|
||||||
"""Placeholder for 'route' and 'shortcut' layers"""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super(EmptyLayer, self).__init__()
|
|
||||||
|
|
||||||
def forward(self, x):
|
|
||||||
return x
|
|
||||||
|
|
||||||
|
|
||||||
class YOLOLayer(nn.Module):
|
class YOLOLayer(nn.Module):
|
||||||
def __init__(self, anchors, nc, img_size, yolo_index):
|
def __init__(self, anchors, nc, img_size, yolo_index):
|
||||||
super(YOLOLayer, self).__init__()
|
super(YOLOLayer, self).__init__()
|
||||||
|
|
Loading…
Reference in New Issue