def __init__(self, cfg, size, num_classes, batch_norm=False): super(SSD_VGG, self).__init__() self.config = cfg self.num_classes = num_classes self.size = size self.enable_batchmorm = batch_norm base_layers, base_outs, base_feats = build_vgg_ssd_layers( BASE_NUM_OUTPUTS[size], BASE_OUTPUT_INDICES[size], batch_norm=batch_norm ) extra_layers, extra_outs, extra_feats = build_vgg_ssd_extra( EXTRAS_NUM_OUTPUTS[size], EXTRA_OUTPUT_INDICES[size], batch_norm=batch_norm ) self.basenet = MultiOutputSequential(base_outs, base_layers) self.extras = MultiOutputSequential(extra_outs, extra_layers) self.detection_head = SSDDetectionOutput(base_feats + extra_feats, num_classes, cfg) self.L2Norm = L2Norm(512, 20, 1e-10)
def extra_layers(start_input_channels): return MultiOutputSequential([1, 3, 5, 7], [ conv_bn(start_input_channels, 256, 1, 1, 0), conv_bn(256, 512, 3, 2, 1), conv_bn(512, 128, 1, 1, 0), conv_bn(128, 256, 3, 2, 1), conv_bn(256, 128, 1, 1, 0), conv_bn(128, 256, 3, 2, 1), conv_bn(256, 64, 1, 1, 0), conv_bn(64, 128, 3, 2, 1) ])
def mobilenet(start_input_channels=3): model = MultiOutputSequential([11, 13], [ conv_bn(start_input_channels, 32, 3, 2, 1), conv_dw(32, 64, 1), conv_dw(64, 128, 2), conv_dw(128, 128, 1), conv_dw(128, 256, 2), conv_dw(256, 256, 1), conv_dw(256, 512, 2), conv_dw(512, 512, 1), conv_dw(512, 512, 1), conv_dw(512, 512, 1), conv_dw(512, 512, 1), conv_dw(512, 512, 1), conv_dw(512, 1024, 2), conv_dw(1024, 1024, 1) ]) return model