Cadene / vqa.pytorch

Visual Question Answering in Pytorch
716 stars 177 forks source link

Left padding when encoding questions #39

Open DenisDsh opened 6 years ago

DenisDsh commented 6 years ago

In vqa_processed.py, encode_question fails (index out of range) when the padding desired is 'left' and the question length is larger than the maximum length.

A possible fix is to replace the else branch :

else:   #['pad'] == 'left'
                    new_k = k + maxlength - len(ex['question_words_UNK'])
                    ex['question_wids'][new_k] = word_to_wid[w]
                ex['seq_length'] = len(ex['question_words_UNK'])

With

else:   # ['pad'] == 'left'
    if maxlength < len(ex['question_words_UNK']):
        ex['question_wids'][k] = word_to_id[w]
    else:
        new_k = k + maxlength - len(ex['question_words_UNK'])
        ex['question_wids'][new_k] = word_to_id[w]