ruotianluo / self-critical.pytorch

Unofficial pytorch implementation for Self-critical Sequence Training for Image Captioning. and others.
MIT License
991 stars 278 forks source link

A question about the collate_func in Dataset class #257

Closed HongkuanZhang closed 2 years ago

HongkuanZhang commented 3 years ago

I have a question about the code below, which is from the collate_func of the Dataset class.

I think it aims to sort the batch data by the att_feat length for later padding, but why use the lambda x:0 instead of lambda x: len(x[1]) as the key for sort?

https://github.com/ruotianluo/self-critical.pytorch/blob/be1a526b058707eb136ede9397b54d971374fb1f/captioning/data/dataloader.py#L228

ruotianluo commented 3 years ago

Because it is no longer necessary to have the samples to be sorted by att_feat length.

ruotianluo commented 3 years ago

Let key=lambda x: 0 basically make sorted work as a noop.

HongkuanZhang commented 3 years ago

Let key=lambda x: 0 basically make sorted work as a noop.

Got it! I just wonder why not remove this line if it does nothing :)