MCPcopy Create free account
hub / github.com/ICTMCG/FakeSV / TikTecDataset

Class TikTecDataset

code/utils/dataloader.py:357–426  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

355
356
357class TikTecDataset(Dataset):
358
359 def __init__(self, path_vid):
360 self.data_complete = pd.read_json('./data/data.json',orient='records',dtype=False,lines=True)
361
362 self.vid = []
363 with open(f'./data/vids/{path_vid}', "r") as fr:
364 for line in fr.readlines():
365 self.vid.append(line.strip())
366 self.data = self.data_complete[self.data_complete['video_id'].isin(self.vid)]
367
368 def __len__(self):
369 return self.data.shape[0]
370
371 def __getitem__(self, idx):
372 item = self.data.iloc[idx]
373 vid = item['video_id']
374
375 label = 1 if item['label']=='假' else 0
376 label = torch.tensor(label)
377
378 max_K = 200 # max num of frames
379 max_N = 500 # max num of ASR words
380
381 # get caption feature
382 with open('./data/caption_w2v_pad%s.pkl' % vid, 'rb') as f:
383 caption_feature = pickle.load(f) # (num_frame, 100, 300)
384 if max_K / caption_feature.shape[0] >= 2:
385 times = math.floor(max_K / caption_feature.shape[0])
386 caption_feature = caption_feature.repeat_interleave(times, dim=0)
387 elif caption_feature.shape[0] > max_K:
388 times = math.ceil(caption_feature.shape[0] / max_K)
389 caption_feature = caption_feature[::times][:max_K]
390 actual_K = caption_feature.shape[0]
391 caption_feature = torch.cat([caption_feature, torch.zeros((max_K - caption_feature.shape[0], 100, 300))], dim=0)
392
393 # get visual feature
394 with open( './data/vgg19_result%s.pkl' % vid, 'rb') as f:
395 visual_feature = pickle.load(f) # (num_frame, 45, 1000)
396 if max_K / visual_feature.shape[0] >= 2:
397 times = math.floor(max_K / visual_feature.shape[0])
398 visual_feature = visual_feature.repeat_interleave(times, dim=0)
399 elif visual_feature.shape[0] > max_K:
400 times = math.ceil(visual_feature.shape[0] / max_K)
401 visual_feature = visual_feature[::times][:max_K]
402 visual_feature = torch.cat([visual_feature, torch.zeros((max_K - visual_feature.shape[0], 45, 1000))], dim=0)
403
404 # get ASR feature
405 with open('./data/asr_w2v+mfcc%s.pkl' % vid, 'rb') as f:
406 asr_feature = pickle.load(f) # (num_word, 300+650)
407 asr_feature = asr_feature[:max_N]
408 actual_N = asr_feature.shape[0]
409 asr_feature = torch.cat([asr_feature, torch.zeros((max_N - asr_feature.shape[0], 300+650))], dim=0)
410
411 # get frames mask & ASR words mask
412 mask_K = torch.zeros(max_K, dtype=torch.int)
413 mask_K[:actual_K] = 1
414 mask_N = torch.zeros(max_N, dtype=torch.int)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected