ImageCaptioning.pytorch icon indicating copy to clipboard operation
ImageCaptioning.pytorch copied to clipboard

Model predicts 10 captions even when there is only 1 image in the folder

Open KahHwa opened this issue 6 years ago • 3 comments

Why does the model do 10 predictions even when there is only 1 image in the folder. How do i change this? Which script do I need to refer to.

KahHwa avatar Jan 12 '19 06:01 KahHwa

Same here, anyone has the solution please

blueclowd avatar Aug 28 '19 07:08 blueclowd

Hard to tell without seeing your code, but if they all are similar, it's probably because you are getting the 10 results of beam search with beam size 10. You can pick the first one or specify that you only want one result when calling your model:

caption = model.decode_sequence(model(feats_mean, feats, mode='sample',
                                           opt={'beam_size': 10,
                                                'sample_method': 'beam_search',
                                                'sample_n': 1})

Note that sample_n can only be equal to 1 or beam_size You can also reduce beam size to 1 or change it to anything else to increase inference speed (at the cost of possibly worst result)

jerome-labonte-udem avatar Jul 14 '20 19:07 jerome-labonte-udem

Another reason maybe the default batch size is 10? The dataloader in this repo will automatically cycle the dataset to reach the desired batch size. Change batch size to 1 may solve this issue.

ruotianluo avatar Jul 14 '20 19:07 ruotianluo