jchenghu / ExpansionNet_v2

Implementation code of the work "Exploiting Multiple Sequence Lengths in Fast End to End Training for Image Captioning"
https://arxiv.org/abs/2208.06551
MIT License
85 stars 25 forks source link

Hello, can you provide a code for measuring the number of model parameters? #11

Closed PanYuQi66666666 closed 4 months ago

PanYuQi66666666 commented 4 months ago

Hello, can you provide a code for measuring the number of model parameters?

PanYuQi66666666 commented 4 months ago

More importantly, I would like to ask why I found 139.45 when loading your rf_model on Google Cloud Drive on the offline test set for single model Cider 140.4 mentioned in the paper. Is there any problem with me?

jchenghu commented 4 months ago

Hi,

Regarding the parameters, adding these lines after the model creation in train.py / test.py / demo.py should do the trick:

def count_parameters(model):
    return sum(p.numel() for p in model.parameters() if p.requires_grad)
print("The model has " + str(count_parameters(model)) + " parameters")

About the second question, there is no problem with your implementation. During the creation of this repository, I found a strange practice with other popular works at that time, of not uploading the checkpoint that appears in the single model configuration. I never quite figured out why and, at that time, I had decided to follow the same practice until I discovered the reason.

However, since it's been a lot and I still have not figured it out, I will just upload also that one to the drive :-) Check the online drive, it is called rf_model_140.4.pth

PanYuQi66666666 commented 4 months ago

Hello, about the parameter test, the result I measured is The model has 233803076 parameters, rf_model, this result looks inconsistent with the paper, is there something wrong with me? @jchenghu

jchenghu commented 4 months ago

No, your implementation should be fine, they are expected to be different because the paper reports the number of parameters without the backbone, whereas the checkpoint contains the full model.

The following code should give you a closer result:

def count_parameters(model):
    return sum(p.numel() for p in model.parameters() if p.requires_grad)
print("The model w/o backbone has " + str(count_parameters(model) - count_parameters(model.swin_transf)) + " parameters")
jchenghu commented 4 months ago

Hi I'm closing since the initial issue was solved, feel free to open a new one in the future

Best, JIa