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

Function SVFEND_collate_fn

code/run.py:81–149  ·  view source on GitHub ↗
(batch)

Source from the content-addressed store, hash-verified

79 np.random.seed(2022)
80
81def SVFEND_collate_fn(batch):
82 num_comments = 23
83 num_frames = 83
84 num_audioframes = 50
85
86 intro_inputid = [item['intro_inputid'] for item in batch]
87 intro_mask = [item['intro_mask'] for item in batch]
88
89 title_inputid = [item['title_inputid'] for item in batch]
90 title_mask = [item['title_mask'] for item in batch]
91
92 comments_like = [item['comments_like'] for item in batch]
93 comments_inputid = [item['comments_inputid'] for item in batch]
94 comments_mask = [item['comments_mask'] for item in batch]
95
96 comments_inputid_resorted = []
97 comments_mask_resorted = []
98 comments_like_resorted = []
99
100 for idx in range(len(comments_like)):
101 comments_like_one = comments_like[idx]
102 comments_inputid_one = comments_inputid[idx]
103 comments_mask_one = comments_mask[idx]
104 if comments_like_one.shape != torch.Size([0]):
105 comments_inputid_one, comments_mask_one, comments_like_one = (list(t) for t in zip(*sorted(zip(comments_inputid_one, comments_mask_one, comments_like_one), key=lambda s: s[2], reverse=True)))
106 comments_inputid_resorted.append(comments_inputid_one)
107 comments_mask_resorted.append(comments_mask_one)
108 comments_like_resorted.append(comments_like_one)
109
110 comments_inputid = pad_sequence(num_comments,comments_inputid_resorted,250)
111 comments_mask = pad_sequence(num_comments,comments_mask_resorted,250)
112 comments_like=[]
113 for idx in range(len(comments_like_resorted)):
114 comments_like_resorted_one = comments_like_resorted[idx]
115 if len(comments_like_resorted_one)>=num_comments:
116 comments_like.append(torch.tensor(comments_like_resorted_one[:num_comments]))
117 else:
118 if isinstance(comments_like_resorted_one, list):
119 comments_like.append(torch.tensor(comments_like_resorted_one+[0]*(num_comments-len(comments_like_resorted_one))))
120 else:
121 comments_like.append(torch.tensor(comments_like_resorted_one.tolist()+[0]*(num_comments-len(comments_like_resorted_one))))
122
123 frames = [item['frames'] for item in batch]
124 frames, frames_masks = pad_frame_sequence(num_frames, frames)
125
126 audioframes = [item['audioframes'] for item in batch]
127 audioframes, audioframes_masks = pad_frame_sequence(num_audioframes, audioframes)
128
129 c3d = [item['c3d'] for item in batch]
130 c3d, c3d_masks = pad_frame_sequence(num_frames, c3d)
131
132 label = [item['label'] for item in batch]
133
134 return {
135 'label': torch.stack(label),
136 'intro_inputid': torch.stack(intro_inputid),
137 'intro_mask': torch.stack(intro_mask),
138 'title_inputid': torch.stack(title_inputid),

Callers

nothing calls this directly

Calls 2

pad_sequenceFunction · 0.85
pad_frame_sequenceFunction · 0.85

Tested by

no test coverage detected