(txt_path, task, model)
| 30 | |
| 31 | |
| 32 | def load_example_input(txt_path, task, model): |
| 33 | with open(txt_path, "r") as file: |
| 34 | Lines = file.readlines() |
| 35 | Lines = [line for line in Lines if line.strip()] |
| 36 | count = 0 |
| 37 | texts = [] |
| 38 | # Strips the newline character |
| 39 | motion_joints = [torch.zeros((1, 1, 22, 3))] * len(Lines) |
| 40 | motion_lengths = [0] * len(Lines) |
| 41 | motion_token_string = [''] |
| 42 | motion_head = [] |
| 43 | motion_heading = [] |
| 44 | motion_tailing = [] |
| 45 | motion_token = torch.zeros((1, 263)) |
| 46 | for i, line in enumerate(Lines): |
| 47 | count += 1 |
| 48 | if len(line.split('#')) == 1: |
| 49 | texts.append(line) |
| 50 | else: |
| 51 | feat_path = line.split('#')[1].replace('\n', '') |
| 52 | if os.path.exists(feat_path): |
| 53 | feats = torch.tensor(np.load(feat_path), device=model.device) |
| 54 | feats = model.datamodule.normalize(feats) |
| 55 | |
| 56 | motion_lengths[i] = feats.shape[0] |
| 57 | motion_token, _ = model.vae.encode(feats[None]) |
| 58 | |
| 59 | motion_token_string = motion_token_to_string( |
| 60 | motion_token, [motion_token.shape[1]])[0] |
| 61 | motion_token_length = motion_token.shape[1] |
| 62 | |
| 63 | motion_splited = motion_token_string.split('>') |
| 64 | |
| 65 | split = motion_token_length // 5 + 1 |
| 66 | split2 = motion_token_length // 4 + 1 |
| 67 | split3 = motion_token_length // 4 * 3 + 1 |
| 68 | |
| 69 | motion_head.append(motion_token[:, :motion_token.shape[1] // |
| 70 | 5][0]) |
| 71 | |
| 72 | motion_heading.append(feats[:feats.shape[0] // 4]) |
| 73 | |
| 74 | motion_tailing.append(feats[feats.shape[0] // 4 * 3:]) |
| 75 | |
| 76 | if '<Motion_Placeholder_s1>' in line: |
| 77 | motion_joints[i] = model.feats2joints( |
| 78 | feats)[:, :feats.shape[1] // 5] |
| 79 | else: |
| 80 | motion_joints[i] = model.feats2joints(feats) |
| 81 | |
| 82 | motion_split1 = '>'.join( |
| 83 | motion_splited[:split] |
| 84 | ) + f'><motion_id_{model.codebook_size+1}>' |
| 85 | motion_split2 = f'<motion_id_{model.codebook_size}>' + '>'.join( |
| 86 | motion_splited[split:]) |
| 87 | |
| 88 | motion_masked = '>'.join( |
| 89 | motion_splited[:split2] |
no test coverage detected