99from mGPT .models .build_model import build_model
1010from mGPT .utils .load_checkpoint import load_pretrained , load_pretrained_vae
1111
12+
1213def main ():
1314
1415 # parse options
1516 cfg = parse_args (phase = "test" ) # parse config file
1617 cfg .TRAIN .STAGE = "token"
1718 cfg .TRAIN .BATCH_SIZE = 1
18-
19+
1920 model_name = cfg .model .target .split ('.' )[- 2 ].lower ()
20- output_dir = Path (os .path .join (cfg .FOLDER , model_name , cfg .NAME , "tokens_visual_" + cfg .TIME ))
21+ output_dir = Path (
22+ os .path .join (cfg .FOLDER , model_name , cfg .NAME ,
23+ "tokens_visual_" + cfg .TIME ))
2124
2225 # set seed
2326 pl .seed_everything (cfg .SEED_VALUE )
@@ -44,39 +47,38 @@ def main():
4447 # loading state dict
4548 if cfg .TEST .CHECKPOINTS :
4649 load_pretrained (cfg , model , phase = "test" )
47-
50+
4851 if cfg .ACCELERATOR == "gpu" :
4952 model = model .cuda ()
50-
53+
5154 model .eval ()
5255 codes = cfg .model .params .codebook_size
5356 with torch .no_grad ():
5457 for i in tqdm (range (codes )):
55-
58+
5659 # Generate motion from token
5760 m_token = torch .LongTensor (1 , 1 ).fill_ (i ).to (model .device )
5861 # vq_latent = model.vae.quantizer.dequantize(m_token)
5962 gen_motion = model .vae .decode (m_token )
6063 gen_motion = model .feats2joints (gen_motion ).to ('cpu' ).numpy ()
61-
64+
6265 # Generate translation from token
63- texts = [f'Generate text: <motion_id_{ codes } ><motion_id_{ i } ><motion_id_{ codes + 1 } >' ]
66+ texts = [
67+ f'Generate text: <motion_id_{ codes } ><motion_id_{ i } ><motion_id_{ codes + 1 } >'
68+ ]
6469 # texts = [f'Use only one word to describe: <motion_id_{codes}><motion_id_{i}><motion_id_{codes +1}>']
65- batch = {
66- "text" : texts ,
67- "length" : [0 ]
68- }
69-
70- out_text = model (batch )['texts' ]
71- print (out_text )
72- out_text_path = os .path .join (output_dir , f'{ i } .txt' )
73- Path (out_text_path ).parent .mkdir (parents = True , exist_ok = True )
74- with open (out_text_path , 'w' ) as f :
75- f .write (out_text [0 ])
76-
70+ batch = {"text" : texts , "length" : [0 ]}
71+
72+ # out_text = model(batch)['texts']
73+ # print(out_text)
74+ # out_text_path = os.path.join(output_dir, f'{i}.txt')
75+ # Path(out_text_path).parent.mkdir(parents=True, exist_ok=True)
76+ # with open(out_text_path, 'w') as f:
77+ # f.write(out_text[0])
78+
7779 target_path = os .path .join (output_dir , f'{ i } .npy' )
7880 Path (target_path ).parent .mkdir (parents = True , exist_ok = True )
79-
81+
8082 np .save (target_path , gen_motion )
8183
8284 print (
0 commit comments