qfgaohao / pytorch-ssd

MobileNetV1, MobileNetV2, VGG based SSD/SSD-lite implementation in Pytorch 1.0 / Pytorch 0.4. Out-of-box support for retraining on Open Images dataset. ONNX and Caffe2 support. Experiment Ideas like CoordConv.
https://medium.com/@smallfishbigsea/understand-ssd-and-implement-your-own-caa3232cd6ad
MIT License
1.4k stars 531 forks source link

Fixed model output size #114

Closed tmralmeida closed 4 years ago

tmralmeida commented 4 years ago

The original priors specs are: specs = [ SSDSpec(38, 8, SSDBoxSizes(30, 60), [2]), SSDSpec(19, 16, SSDBoxSizes(60, 111), [2, 3]), SSDSpec(10, 32, SSDBoxSizes(111, 162), [2, 3]), SSDSpec(5, 64, SSDBoxSizes(162, 213), [2, 3]), SSDSpec(3, 100, SSDBoxSizes(213, 264), [2]), SSDSpec(1, 300, SSDBoxSizes(264, 315), [2]) ] But you do not use them. When I change to these priors, the number of priors are right: 8732 (generate_priors function is ok).

However, your regression_headers and classification_header sizes are fixed due to the hard coded "6 *" in the out_channels argument of each convolution layer. So, as you are doing the number of model's outputs will be always 3000. I'm trying to fix this with no success until now.

tmralmeida commented 4 years ago

There was a bug in my code. Nevertheless, I changed the definitions of regression_headers and classification_headers to:

regression_headers = ModuleList([])
classification_headers = ModuleList([])
n_channels = [512, 1024, 512, 256, 256, 256]
for i in range(len(config.specs)):
    ar = config.specs[i].aspect_ratios
    if len(ar) == 1:
        n = 4
    else:
        n = 6
    regression_headers.append(Conv2d(n_channels[i], n * 4, kernel_size = 3, padding = 1))
    classification_headers.append(Conv2d(n_channels[i], n * num_classes, kernel_size = 3, padding = 1))

This is less verbose and allows to use input sizes of 512*512.

mjack3 commented 3 years ago

Hello! i would like train SSD 512 but I don't know where should i make that changes. Could you help me?