in iep/data.py [0:0]
def __getitem__(self, index):
question = self.all_questions[index]
image_idx = self.all_image_idxs[index]
answer = self.all_answers[index]
program_seq = None
if self.all_programs is not None:
program_seq = self.all_programs[index]
image = None
if self.image_h5 is not None:
image = self.image_h5['images'][image_idx]
image = torch.FloatTensor(np.asarray(image, dtype=np.float32))
feats = self.feature_h5['features'][image_idx]
feats = torch.FloatTensor(np.asarray(feats, dtype=np.float32))
program_json = None
if program_seq is not None:
program_json_seq = []
for fn_idx in program_seq:
fn_str = self.vocab['program_idx_to_token'][fn_idx]
if fn_str == '<START>' or fn_str == '<END>': continue
fn = iep.programs.str_to_function(fn_str)
program_json_seq.append(fn)
if self.mode == 'prefix':
program_json = iep.programs.prefix_to_list(program_json_seq)
elif self.mode == 'postfix':
program_json = iep.programs.postfix_to_list(program_json_seq)
return (question, image, feats, answer, program_seq, program_json)