-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpredict.py
61 lines (51 loc) · 1.95 KB
/
predict.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
audio => pose
(block,26,64) => (block,192,64)
"""
#!/usr/bin/python
# -*- coding: utf-8 -*-
# import torch module
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.data as data_utils
import torch.nn as nn
import torch.optim as optim
# import python module
import time
import os
import argparse
import datetime
from pathlib import Path
from distutils.util import strtobool
# import modules
import numpy as np
from model import get_model
def main():
parser = argparse.ArgumentParser(description='speech to gesture by PyTorch')
parser.add_argument('--modelpath', type=str, default="./out/20200404-182816/generator_20200404-182816_weights.pth", help='model path') # Please fix modelpath
parser.add_argument('--inputpath', type=str, default="./test_inputs/", help='input path')
parser.add_argument('--outpath', type=str, default="./predict/", help='out path')
args = parser.parse_args()
os.makedirs(args.outpath, exist_ok=True)
GPU = False
device = torch.device("cuda" if GPU else "cpu")
# g_net = g_model(26, 256, args.batch_size, device)
g_model = get_model("unet_decoder")
model = g_model(26, 256, 256, device)
model.eval()
# args.path = './model/train9e200n/generator_20191212-183801_weights.pth'
model.load_state_dict(torch.load(args.modelpath,map_location=device))
for num in range(1093,1183):
PATH = args.inputpath + "X_test_gesture"+str(num)+"_posegan.npy"
if os.path.exists(PATH):
testnpdata = np.load(PATH)
testdata = torch.tensor(testnpdata, dtype=torch.float).to(device)
predict_tensor = model(testdata)
print(predict_tensor.shape)
predict_np = predict_tensor.detach().numpy()
filename = (args.modelpath.split("/")[-1])
np.save(args.outpath+"/gesture"+str(num)+"-{}".format(filename.replace(".pth",".npy")),predict_np)
if __name__ == '__main__':
main()
print("--complete--")