-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
64 lines (47 loc) · 2.08 KB
/
demo.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
62
63
64
import argparse
import time
from common.helper import *
def parse_arguments():
model_types = ['pcn_cd', 'pcn_emd', 'folding', 'fc']
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--device',
type=int, default=0, help='device id (-1 for cpu, non-zero value for gpu)')
parser.add_argument('-i', '--input-file',
type=str, default='demo_data/chair.pcd', help='input (partial) point cloud file')
parser.add_argument('-m', '--model-type',
type=str, default='pcn_emd', choices=model_types, help='model type')
parser.add_argument('-c', '--checkpoint',
type=str, default='data/trained_models/pcn_emd', help='checkpoint file')
parser.add_argument('-p', '--num-gt-points',
type=int, default=16384, help='number of ground-truth points')
parser.add_argument('-o', '--onnx-model-file',
type=str, default='model_tf.onnx', help='weights file for the exported TF->ONNX model')
args = parser.parse_args()
return args
if __name__ == '__main__':
args = parse_arguments()
if args.device == -1:
device = torch.device('cpu')
else:
device = torch.device('cuda:' + str(args.device))
if args.model_type == 'pcn_cd':
from pytorch_models.pcn_cd import Model
elif args.model_type == 'pcn_emd':
from pytorch_models.pcn_emd import Model
print('Model type:', args.model_type)
model = Model()
if args.device >= 0:
model.to(device)
if args.onnx_model_file:
model = convert_model_onnx_to_torch(model, args.onnx_model_file)
partial = read_cloud_points(args.input_file)
inputs = torch.Tensor(partial)
inputs = inputs.transpose(1, 0)[None, :]
inputs = inputs.to(device)
time_beg = time.time()
coarse, fine = model(inputs)
time_end = time.time()
print('Inference took {} seconds.'.format(time_end - time_beg))
fine = fine.detach().cpu().numpy()[0]
# coarse = coarse.detach().cpu().numpy()[0]
plot_side_by_side(partial, fine)