| 62 | return self.data.shape[0] |
| 63 | |
| 64 | def __getitem__(self, idx): |
| 65 | item = self.data.iloc[idx] |
| 66 | vid = item['video_id'] |
| 67 | |
| 68 | # label |
| 69 | label = 0 if item['annotation']=='真' else 1 |
| 70 | label = torch.tensor(label) |
| 71 | |
| 72 | # text |
| 73 | if self.datamode == 'title+ocr': |
| 74 | title_tokens = self.tokenizer(item['description']+' '+item['ocr'], max_length=512, padding='max_length', truncation=True) |
| 75 | elif self.datamode == 'ocr': |
| 76 | title_tokens = self.tokenizer(item['ocr'], max_length=512, padding='max_length', truncation=True) |
| 77 | elif self.datamode == 'title': |
| 78 | title_tokens = self.tokenizer(item['description'], max_length=512, padding='max_length', truncation=True) |
| 79 | title_inputid = torch.LongTensor(title_tokens['input_ids']) |
| 80 | title_mask = torch.LongTensor(title_tokens['attention_mask']) |
| 81 | |
| 82 | # comments |
| 83 | comments_inputid = [] |
| 84 | comments_mask = [] |
| 85 | for comment in item['comments']: |
| 86 | comment_tokens = self.tokenizer(comment, max_length=250, padding='max_length', truncation=True) |
| 87 | comments_inputid.append(comment_tokens['input_ids']) |
| 88 | comments_mask.append(comment_tokens['attention_mask']) |
| 89 | comments_inputid = torch.LongTensor(np.array(comments_inputid)) |
| 90 | comments_mask = torch.LongTensor(np.array(comments_mask)) |
| 91 | |
| 92 | comments_like = [] |
| 93 | for num in item['comments_like']: |
| 94 | num_like = num.split(" ")[0] |
| 95 | comments_like.append(str2num(num_like)) |
| 96 | comments_like = torch.tensor(comments_like) |
| 97 | |
| 98 | # audio |
| 99 | audioframes = self.dict_vid_convfea[vid] |
| 100 | audioframes = torch.FloatTensor(audioframes) |
| 101 | |
| 102 | # frames |
| 103 | frames=pickle.load(open(os.path.join(self.framefeapath,vid+'.pkl'),'rb')) |
| 104 | frames=torch.FloatTensor(frames) |
| 105 | |
| 106 | # video |
| 107 | c3d = h5py.File(self.c3dfeapath+vid+".hdf5", "r")[vid]['c3d_features'] |
| 108 | c3d = torch.FloatTensor(c3d) |
| 109 | |
| 110 | # # user |
| 111 | try: |
| 112 | if item['is_official'] == 1: |
| 113 | intro = "个人认证" |
| 114 | elif item['is_official'] == 2: |
| 115 | intro = "机构认证" |
| 116 | elif item['is_official'] == 0: |
| 117 | intro = "未认证" |
| 118 | else: |
| 119 | intro = "认证状态未知" |
| 120 | except: |
| 121 | intro = "认证状态未知" |