def func(batch): text, imgs, y = [], [], [] for (_text, _id), _y in batch: text.append([_text]) imgs.append(load_vgg(_id)) # _imgs: List[4096, 4096, 4096] y.append(_y) padded_text, lens, sents_num = padding_text_2d(text) # padding文本 imgs = torch.tensor(imgs) # 转为张量 y = torch.tensor(y) # return (padded_text, lens, sents_num, imgs), y
def func(batch): text, imgs, y = [], [], [] for (_text, _imgs), _y in batch: text.append(_text) imgs.append(mean.copy()) # 空白图片 imgs += _imgs # _imgs: List[4096, 4096, 4096] y.append(_y) padded_text, lens, sents_num = padding_text_2d(text) # padding文本 imgs = torch.tensor(imgs) # 转为张量 y = torch.tensor(y) # return (padded_text, lens, sents_num, imgs), y
def func(batch): text, imgs, y = [], [], [] for (_text, _imgs), _y in batch: text.append(_text) imgs += _imgs # _imgs: List[4096, 4096, 4096] y.append(_y) padded_text, lens, sents_num = padding_text_2d( text, config["max_tokens"], config["max_sents"]) # padding文本 imgs = torch.tensor(imgs) y = torch.tensor(y) return (padded_text, lens, sents_num, imgs), y
def func(batch): text, imgs, y = [], [], [] for (_text, _imgs), _y in batch: text.append(_text) imgs.append(mean.copy()) # 空白图片 for i in _imgs: feature = load_vgg_features(i) if feature is not None: imgs.append(feature) y.append(_y) padded_text, lens, sents_num = padding_text_2d(text) # padding文本 imgs = torch.tensor(imgs) # 转为张量 y = torch.tensor(y) # return (padded_text, lens, sents_num, imgs), y
def electra_vgg_collate_2d(batch): text, imgs, y = [], [], [] for (_text, _imgs), _y in batch: text.append(_text) imgs += _imgs # _imgs: List[4096, 4096, 4096] y.append(_y) padded_text, lens, sents_num = padding_text_2d( text, config["max_tokens"], config["max_sents"]) # padding文本 mask = torch.zeros(padded_text.shape, dtype=torch.float32) # for i, l in enumerate(lens): # mask mask[i][:l] = 1 token_type_ids = torch.zeros(padded_text.shape, dtype=torch.long) position_ids = torch.zeros(padded_text.shape, dtype=torch.long) imgs = torch.tensor(imgs) # 转为张量 y = torch.tensor(y) # return (padded_text, mask, token_type_ids, position_ids, sents_num, imgs), y