learning3d 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. learning3d/__init__.py +2 -0
  2. learning3d/data_utils/__init__.py +4 -0
  3. learning3d/data_utils/dataloaders.py +454 -0
  4. learning3d/data_utils/user_data.py +119 -0
  5. learning3d/examples/test_dcp.py +139 -0
  6. learning3d/examples/test_deepgmr.py +144 -0
  7. learning3d/examples/test_flownet.py +113 -0
  8. learning3d/examples/test_masknet.py +159 -0
  9. learning3d/examples/test_masknet2.py +162 -0
  10. learning3d/examples/test_pcn.py +118 -0
  11. learning3d/examples/test_pcrnet.py +120 -0
  12. learning3d/examples/test_pnlk.py +121 -0
  13. learning3d/examples/test_pointconv.py +126 -0
  14. learning3d/examples/test_pointnet.py +121 -0
  15. learning3d/examples/test_prnet.py +126 -0
  16. learning3d/examples/test_rpmnet.py +120 -0
  17. learning3d/examples/train_PointNetLK.py +240 -0
  18. learning3d/examples/train_dcp.py +249 -0
  19. learning3d/examples/train_deepgmr.py +244 -0
  20. learning3d/examples/train_flownet.py +259 -0
  21. learning3d/examples/train_masknet.py +239 -0
  22. learning3d/examples/train_pcn.py +216 -0
  23. learning3d/examples/train_pcrnet.py +228 -0
  24. learning3d/examples/train_pointconv.py +245 -0
  25. learning3d/examples/train_pointnet.py +244 -0
  26. learning3d/examples/train_prnet.py +229 -0
  27. learning3d/examples/train_rpmnet.py +228 -0
  28. learning3d/losses/__init__.py +12 -0
  29. learning3d/losses/chamfer_distance.py +51 -0
  30. learning3d/losses/classification.py +14 -0
  31. learning3d/losses/correspondence_loss.py +10 -0
  32. learning3d/losses/cuda/chamfer_distance/__init__.py +1 -0
  33. learning3d/losses/cuda/chamfer_distance/chamfer_distance.cpp +185 -0
  34. learning3d/losses/cuda/chamfer_distance/chamfer_distance.cu +209 -0
  35. learning3d/losses/cuda/chamfer_distance/chamfer_distance.py +66 -0
  36. learning3d/losses/cuda/emd_torch/pkg/emd_loss_layer.py +41 -0
  37. learning3d/losses/cuda/emd_torch/pkg/include/cuda/emd.cuh +347 -0
  38. learning3d/losses/cuda/emd_torch/pkg/include/cuda_helper.h +18 -0
  39. learning3d/losses/cuda/emd_torch/pkg/include/emd.h +54 -0
  40. learning3d/losses/cuda/emd_torch/pkg/layer/__init__.py +1 -0
  41. learning3d/losses/cuda/emd_torch/pkg/layer/emd_loss_layer.py +40 -0
  42. learning3d/losses/cuda/emd_torch/pkg/src/cuda/emd.cu +70 -0
  43. learning3d/losses/cuda/emd_torch/pkg/src/emd.cpp +1 -0
  44. learning3d/losses/cuda/emd_torch/setup.py +29 -0
  45. learning3d/losses/emd.py +16 -0
  46. learning3d/losses/frobenius_norm.py +21 -0
  47. learning3d/losses/rmse_features.py +16 -0
  48. learning3d/models/__init__.py +23 -0
  49. learning3d/models/classifier.py +41 -0
  50. learning3d/models/dcp.py +92 -0
  51. learning3d/models/deepgmr.py +165 -0
  52. learning3d/models/dgcnn.py +92 -0
  53. learning3d/models/flownet3d.py +446 -0
  54. learning3d/models/masknet.py +84 -0
  55. learning3d/models/masknet2.py +264 -0
  56. learning3d/models/pcn.py +164 -0
  57. learning3d/models/pcrnet.py +74 -0
  58. learning3d/models/pointconv.py +108 -0
  59. learning3d/models/pointnet.py +108 -0
  60. learning3d/models/pointnetlk.py +173 -0
  61. learning3d/models/pooling.py +15 -0
  62. learning3d/models/ppfnet.py +102 -0
  63. learning3d/models/prnet.py +431 -0
  64. learning3d/models/rpmnet.py +359 -0
  65. learning3d/models/segmentation.py +38 -0
  66. learning3d/ops/__init__.py +0 -0
  67. learning3d/ops/data_utils.py +45 -0
  68. learning3d/ops/invmat.py +134 -0
  69. learning3d/ops/quaternion.py +218 -0
  70. learning3d/ops/se3.py +157 -0
  71. learning3d/ops/sinc.py +229 -0
  72. learning3d/ops/so3.py +213 -0
  73. learning3d/ops/transform_functions.py +342 -0
  74. learning3d/utils/__init__.py +9 -0
  75. learning3d/utils/lib/build/lib.linux-x86_64-3.5/pointnet2_cuda.cpython-35m-x86_64-linux-gnu.so +0 -0
  76. learning3d/utils/lib/build/temp.linux-x86_64-3.5/src/ball_query.o +0 -0
  77. learning3d/utils/lib/build/temp.linux-x86_64-3.5/src/ball_query_gpu.o +0 -0
  78. learning3d/utils/lib/build/temp.linux-x86_64-3.5/src/group_points.o +0 -0
  79. learning3d/utils/lib/build/temp.linux-x86_64-3.5/src/group_points_gpu.o +0 -0
  80. learning3d/utils/lib/build/temp.linux-x86_64-3.5/src/interpolate.o +0 -0
  81. learning3d/utils/lib/build/temp.linux-x86_64-3.5/src/interpolate_gpu.o +0 -0
  82. learning3d/utils/lib/build/temp.linux-x86_64-3.5/src/pointnet2_api.o +0 -0
  83. learning3d/utils/lib/build/temp.linux-x86_64-3.5/src/sampling.o +0 -0
  84. learning3d/utils/lib/build/temp.linux-x86_64-3.5/src/sampling_gpu.o +0 -0
  85. learning3d/utils/lib/dist/pointnet2-0.0.0-py3.5-linux-x86_64.egg +0 -0
  86. learning3d/utils/lib/pointnet2.egg-info/SOURCES.txt +14 -0
  87. learning3d/utils/lib/pointnet2.egg-info/dependency_links.txt +1 -0
  88. learning3d/utils/lib/pointnet2.egg-info/top_level.txt +1 -0
  89. learning3d/utils/lib/pointnet2_modules.py +160 -0
  90. learning3d/utils/lib/pointnet2_utils.py +318 -0
  91. learning3d/utils/lib/pytorch_utils.py +236 -0
  92. learning3d/utils/lib/setup.py +23 -0
  93. learning3d/utils/lib/src/ball_query.cpp +25 -0
  94. learning3d/utils/lib/src/ball_query_gpu.cu +67 -0
  95. learning3d/utils/lib/src/ball_query_gpu.h +15 -0
  96. learning3d/utils/lib/src/cuda_utils.h +15 -0
  97. learning3d/utils/lib/src/group_points.cpp +36 -0
  98. learning3d/utils/lib/src/group_points_gpu.cu +86 -0
  99. learning3d/utils/lib/src/group_points_gpu.h +22 -0
  100. learning3d/utils/lib/src/interpolate.cpp +65 -0
  101. learning3d/utils/lib/src/interpolate_gpu.cu +233 -0
  102. learning3d/utils/lib/src/interpolate_gpu.h +36 -0
  103. learning3d/utils/lib/src/pointnet2_api.cpp +25 -0
  104. learning3d/utils/lib/src/sampling.cpp +46 -0
  105. learning3d/utils/lib/src/sampling_gpu.cu +253 -0
  106. learning3d/utils/lib/src/sampling_gpu.h +29 -0
  107. learning3d/utils/pointconv_util.py +382 -0
  108. learning3d/utils/ppfnet_util.py +244 -0
  109. learning3d/utils/svd.py +59 -0
  110. learning3d/utils/transformer.py +243 -0
  111. learning3d-0.0.1.dist-info/LICENSE +21 -0
  112. learning3d-0.0.1.dist-info/METADATA +271 -0
  113. learning3d-0.0.1.dist-info/RECORD +115 -0
  114. learning3d-0.0.1.dist-info/WHEEL +5 -0
  115. learning3d-0.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,162 @@
1
+ import open3d as o3d
2
+ import argparse
3
+ import os
4
+ import sys
5
+ import numpy
6
+ import numpy as np
7
+ import torch
8
+ import torch.utils.data
9
+ from torch.utils.data import DataLoader
10
+ from tqdm import tqdm
11
+
12
+ # Only if the files are in example folder.
13
+ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
14
+ if BASE_DIR[-8:] == 'examples':
15
+ sys.path.append(os.path.join(BASE_DIR, os.pardir))
16
+ os.chdir(os.path.join(BASE_DIR, os.pardir))
17
+
18
+ from learning3d.models import MaskNet2
19
+ from learning3d.data_utils import RegistrationData, ModelNet40Data
20
+
21
+ def pc2open3d(data):
22
+ if torch.is_tensor(data): data = data.detach().cpu().numpy()
23
+ if len(data.shape) == 2:
24
+ pc = o3d.geometry.PointCloud()
25
+ pc.points = o3d.utility.Vector3dVector(data)
26
+ return pc
27
+ else:
28
+ print("Error in the shape of data given to Open3D!, Shape is ", data.shape)
29
+
30
+ def display_results(template, source, masked_template, masked_source):
31
+ template = pc2open3d(template)
32
+ source = pc2open3d(source)
33
+ masked_template = pc2open3d(masked_template)
34
+ masked_source = pc2open3d(masked_source)
35
+
36
+ template.paint_uniform_color([1, 0, 0])
37
+ source.paint_uniform_color([0, 1, 0])
38
+ # masked_template.paint_uniform_color([0, 0, 1])
39
+ masked_template.paint_uniform_color([1, 0, 0])
40
+ masked_source.paint_uniform_color([0, 1, 0])
41
+
42
+ o3d.visualization.draw_geometries([template, source])
43
+ o3d.visualization.draw_geometries([masked_template, masked_source])
44
+
45
+ def evaluate_metrics(TP, FP, FN, TN, gt_mask):
46
+ # TP, FP, FN, TN: True +ve, False +ve, False -ve, True -ve
47
+ # gt_mask: Ground Truth mask [Nt, 1]
48
+
49
+ accuracy = (TP + TN)/gt_mask.shape[1]
50
+ misclassification_rate = (FN + FP)/gt_mask.shape[1]
51
+ # Precision: (What portion of positive identifications are actually correct?)
52
+ precision = TP / (TP + FP)
53
+ # Recall: (What portion of actual positives are identified correctly?)
54
+ recall = TP / (TP + FN)
55
+
56
+ fscore = (2*precision*recall) / (precision + recall)
57
+ return accuracy, precision, recall, fscore
58
+
59
+ # Function used to evaluate the predicted mask with ground truth mask.
60
+ def evaluate_mask(gt_mask, predicted_mask, predicted_mask_idx):
61
+ # gt_mask: Ground Truth Mask [Nt, 1]
62
+ # predicted_mask: Mask predicted by network [Nt, 1]
63
+ # predicted_mask_idx: Point indices chosen by network [Ns, 1]
64
+
65
+ if torch.is_tensor(gt_mask): gt_mask = gt_mask.detach().cpu().numpy()
66
+ if torch.is_tensor(gt_mask): predicted_mask = predicted_mask.detach().cpu().numpy()
67
+ if torch.is_tensor(predicted_mask_idx): predicted_mask_idx = predicted_mask_idx.detach().cpu().numpy()
68
+ gt_mask, predicted_mask, predicted_mask_idx = gt_mask.reshape(1,-1), predicted_mask.reshape(1,-1), predicted_mask_idx.reshape(1,-1)
69
+
70
+ gt_idx = np.where(gt_mask == 1)[1].reshape(1,-1) # Find indices of points which are actually in source.
71
+
72
+ # TP + FP = number of source points.
73
+ TP = np.intersect1d(predicted_mask_idx[0], gt_idx[0]).shape[0] # is inliner and predicted as inlier (True Positive) (Find common indices in predicted_mask_idx, gt_idx)
74
+ FP = len([x for x in predicted_mask_idx[0] if x not in gt_idx]) # isn't inlier but predicted as inlier (False Positive)
75
+ FN = FP # is inlier but predicted as outlier (False Negative) (due to binary classification)
76
+ TN = gt_mask.shape[1] - gt_idx.shape[1] - FN # is outlier and predicted as outlier (True Negative)
77
+ return evaluate_metrics(TP, FP, FN, TN, gt_mask)
78
+
79
+ def test_one_epoch(args, model, test_loader):
80
+ model.eval()
81
+ test_loss = 0.0
82
+ pred = 0.0
83
+ count = 0
84
+
85
+ for i, data in enumerate(tqdm(test_loader)):
86
+ template, source, igt, gt_template_mask, gt_source_mask = data
87
+
88
+ template = template.to(args.device)
89
+ source = source.to(args.device)
90
+ igt = igt.to(args.device) # [source] = [igt]*[template]
91
+ gt_template_mask = gt_template_mask.to(args.device)
92
+ gt_source_mask = gt_source_mask.to(args.device)
93
+
94
+ masked_template, masked_source, template_mask, source_mask = model(template, source)
95
+
96
+ # TODO: Implement evaluation strategy.
97
+ '''
98
+ Evaluate mask based on classification metrics.
99
+ accuracy, precision, recall, fscore = evaluate_mask(gt_template_mask, template_mask, predicted_mask_idx = model.mask_idx)
100
+ precision_list.append(precision)
101
+ '''
102
+
103
+ # Different ways to visualize results.
104
+ display_results(template.detach().cpu().numpy()[0], source.detach().cpu().numpy()[0], masked_template.detach().cpu().numpy()[0], masked_source.detach().cpu().numpy()[0])
105
+
106
+ def test(args, model, test_loader):
107
+ test_one_epoch(args, model, test_loader)
108
+
109
+ def options():
110
+ parser = argparse.ArgumentParser(description='MaskNet: A Fully-Convolutional Network For Inlier Estimation (Testing)')
111
+
112
+ # settings for input data
113
+ parser.add_argument('--num_points', default=1024, type=int,
114
+ metavar='N', help='points in point-cloud (default: 1024)')
115
+ parser.add_argument('--partial_source', default=True, type=bool,
116
+ help='create partial source point cloud in dataset.')
117
+ parser.add_argument('--partial_template', default=True, type=bool,
118
+ help='create partial source point cloud in dataset.')
119
+ parser.add_argument('--noise', default=False, type=bool,
120
+ help='Add noise in source point clouds.')
121
+ parser.add_argument('--outliers', default=False, type=bool,
122
+ help='Add outliers to template point cloud.')
123
+
124
+ # settings for on testing
125
+ parser.add_argument('-j', '--workers', default=1, type=int,
126
+ metavar='N', help='number of data loading workers (default: 4)')
127
+ parser.add_argument('-b', '--test_batch_size', default=1, type=int,
128
+ metavar='N', help='test-mini-batch size (default: 1)')
129
+ parser.add_argument('--pretrained', default='learning3d/pretrained/exp_masknet2/models/best_model_0.7.t7', type=str,
130
+ metavar='PATH', help='path to pretrained model file (default: null (no-use))')
131
+ parser.add_argument('--device', default='cuda:0', type=str,
132
+ metavar='DEVICE', help='use CUDA if available')
133
+ parser.add_argument('--unseen', default=False, type=bool,
134
+ help='Use first 20 categories for training and last 20 for testing')
135
+
136
+ args = parser.parse_args()
137
+ return args
138
+
139
+ def main():
140
+ args = options()
141
+ torch.backends.cudnn.deterministic = True
142
+
143
+ testset = RegistrationData('PointNetLK', ModelNet40Data(train=False, num_points=args.num_points),
144
+ partial_template=args.partial_template, partial_source=args.partial_source,
145
+ noise=args.noise, additional_params={'use_masknet': True, 'partial_point_cloud_method': 'planar_crop'})
146
+ test_loader = DataLoader(testset, batch_size=args.test_batch_size, shuffle=False, drop_last=False, num_workers=args.workers)
147
+
148
+ if not torch.cuda.is_available():
149
+ args.device = 'cpu'
150
+ args.device = torch.device(args.device)
151
+
152
+ # Load Pretrained MaskNet.
153
+ model = MaskNet2()
154
+ if args.pretrained:
155
+ assert os.path.isfile(args.pretrained)
156
+ model.load_state_dict(torch.load(args.pretrained, map_location='cpu'))
157
+ model = model.to(args.device)
158
+
159
+ test(args, model, test_loader)
160
+
161
+ if __name__ == '__main__':
162
+ main()
@@ -0,0 +1,118 @@
1
+ # author: Vinit Sarode (vinitsarode5@gmail.com) 03/23/2020
2
+
3
+ import open3d as o3d
4
+ import argparse
5
+ import os
6
+ import sys
7
+ import logging
8
+ import numpy
9
+ import numpy as np
10
+ import torch
11
+ import torch.utils.data
12
+ import torchvision
13
+ from torch.utils.data import DataLoader
14
+ from tensorboardX import SummaryWriter
15
+ from tqdm import tqdm
16
+
17
+ # Only if the files are in example folder.
18
+ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
19
+ if BASE_DIR[-8:] == 'examples':
20
+ sys.path.append(os.path.join(BASE_DIR, os.pardir))
21
+ os.chdir(os.path.join(BASE_DIR, os.pardir))
22
+
23
+ from learning3d.models import PCN
24
+ from learning3d.data_utils import ModelNet40Data, ClassificationData
25
+ from learning3d.losses import ChamferDistanceLoss
26
+
27
+ def display_open3d(input_pc, output):
28
+ input_pc_ = o3d.geometry.PointCloud()
29
+ output_ = o3d.geometry.PointCloud()
30
+ input_pc_.points = o3d.utility.Vector3dVector(input_pc)
31
+ output_.points = o3d.utility.Vector3dVector(output + np.array([1,0,0]))
32
+ input_pc_.paint_uniform_color([1, 0, 0])
33
+ output_.paint_uniform_color([0, 1, 0])
34
+ o3d.visualization.draw_geometries([input_pc_, output_])
35
+
36
+ def test_one_epoch(device, model, test_loader):
37
+ model.eval()
38
+ test_loss = 0.0
39
+ pred = 0.0
40
+ count = 0
41
+ for i, data in enumerate(tqdm(test_loader)):
42
+ points, _ = data
43
+
44
+ points = points.to(device)
45
+
46
+ output = model(points)
47
+ loss_val = ChamferDistanceLoss()(points, output['coarse_output'])
48
+ print("Loss Val: ", loss_val)
49
+ display_open3d(points[0].detach().cpu().numpy(), output['coarse_output'][0].detach().cpu().numpy())
50
+
51
+ test_loss += loss_val.item()
52
+ count += 1
53
+
54
+ test_loss = float(test_loss)/count
55
+ return test_loss
56
+
57
+ def test(args, model, test_loader):
58
+ test_loss = test_one_epoch(args.device, model, test_loader)
59
+
60
+ def options():
61
+ parser = argparse.ArgumentParser(description='Point Completion Network')
62
+ parser.add_argument('--exp_name', type=str, default='exp_pcn', metavar='N',
63
+ help='Name of the experiment')
64
+ parser.add_argument('--dataset_path', type=str, default='ModelNet40',
65
+ metavar='PATH', help='path to the input dataset') # like '/path/to/ModelNet40'
66
+ parser.add_argument('--eval', type=bool, default=False, help='Train or Evaluate the network.')
67
+
68
+ # settings for input data
69
+ parser.add_argument('--dataset_type', default='modelnet', choices=['modelnet', 'shapenet2'],
70
+ metavar='DATASET', help='dataset type (default: modelnet)')
71
+ parser.add_argument('--num_points', default=1024, type=int,
72
+ metavar='N', help='points in point-cloud (default: 1024)')
73
+
74
+ # settings for PCN
75
+ parser.add_argument('--emb_dims', default=1024, type=int,
76
+ metavar='K', help='dim. of the feature vector (default: 1024)')
77
+ parser.add_argument('--detailed_output', default=False, type=bool,
78
+ help='Coarse + Fine Output')
79
+
80
+ # settings for on training
81
+ parser.add_argument('--seed', type=int, default=1234)
82
+ parser.add_argument('-j', '--workers', default=4, type=int,
83
+ metavar='N', help='number of data loading workers (default: 4)')
84
+ parser.add_argument('-b', '--batch_size', default=32, type=int,
85
+ metavar='N', help='mini-batch size (default: 32)')
86
+ parser.add_argument('--pretrained', default='learning3d/pretrained/exp_pcn/models/best_model.t7', type=str,
87
+ metavar='PATH', help='path to pretrained model file (default: null (no-use))')
88
+ parser.add_argument('--device', default='cuda:0', type=str,
89
+ metavar='DEVICE', help='use CUDA if available')
90
+
91
+ args = parser.parse_args()
92
+ return args
93
+
94
+ def main():
95
+ args = options()
96
+ args.dataset_path = os.path.join(os.getcwd(), os.pardir, os.pardir, 'ModelNet40', 'ModelNet40')
97
+
98
+ trainset = ClassificationData(ModelNet40Data(train=True))
99
+ testset = ClassificationData(ModelNet40Data(train=False))
100
+ train_loader = DataLoader(trainset, batch_size=args.batch_size, shuffle=True, drop_last=True, num_workers=args.workers)
101
+ test_loader = DataLoader(testset, batch_size=args.batch_size, shuffle=False, drop_last=False, num_workers=args.workers)
102
+
103
+ if not torch.cuda.is_available():
104
+ args.device = 'cpu'
105
+ args.device = torch.device(args.device)
106
+
107
+ # Create PointNet Model.
108
+ model = PCN(emb_dims=args.emb_dims, detailed_output=args.detailed_output)
109
+
110
+ if args.pretrained:
111
+ assert os.path.isfile(args.pretrained)
112
+ model.load_state_dict(torch.load(args.pretrained, map_location='cpu'))
113
+ model.to(args.device)
114
+
115
+ test(args, model, test_loader)
116
+
117
+ if __name__ == '__main__':
118
+ main()
@@ -0,0 +1,120 @@
1
+ import open3d as o3d
2
+ import argparse
3
+ import os
4
+ import sys
5
+ import logging
6
+ import numpy
7
+ import numpy as np
8
+ import torch
9
+ import torch.utils.data
10
+ import torchvision
11
+ from torch.utils.data import DataLoader
12
+ from tensorboardX import SummaryWriter
13
+ from tqdm import tqdm
14
+
15
+ # Only if the files are in example folder.
16
+ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
17
+ if BASE_DIR[-8:] == 'examples':
18
+ sys.path.append(os.path.join(BASE_DIR, os.pardir))
19
+ os.chdir(os.path.join(BASE_DIR, os.pardir))
20
+
21
+ from learning3d.models import PointNet, iPCRNet
22
+ from learning3d.losses import ChamferDistanceLoss
23
+ from learning3d.data_utils import RegistrationData, ModelNet40Data
24
+
25
+
26
+ def display_open3d(template, source, transformed_source):
27
+ template_ = o3d.geometry.PointCloud()
28
+ source_ = o3d.geometry.PointCloud()
29
+ transformed_source_ = o3d.geometry.PointCloud()
30
+ template_.points = o3d.utility.Vector3dVector(template)
31
+ source_.points = o3d.utility.Vector3dVector(source + np.array([0,0,0]))
32
+ transformed_source_.points = o3d.utility.Vector3dVector(transformed_source)
33
+ template_.paint_uniform_color([1, 0, 0])
34
+ source_.paint_uniform_color([0, 1, 0])
35
+ transformed_source_.paint_uniform_color([0, 0, 1])
36
+ o3d.visualization.draw_geometries([template_, source_, transformed_source_])
37
+
38
+ def test_one_epoch(device, model, test_loader):
39
+ model.eval()
40
+ test_loss = 0.0
41
+ pred = 0.0
42
+ count = 0
43
+ for i, data in enumerate(tqdm(test_loader)):
44
+ template, source, igt = data
45
+
46
+ template = template.to(device)
47
+ source = source.to(device)
48
+ igt = igt.to(device)
49
+
50
+ output = model(template, source)
51
+ display_open3d(template.detach().cpu().numpy()[0], source.detach().cpu().numpy()[0], output['transformed_source'].detach().cpu().numpy()[0])
52
+ loss_val = ChamferDistanceLoss()(template, output['transformed_source'])
53
+
54
+ test_loss += loss_val.item()
55
+ count += 1
56
+
57
+ test_loss = float(test_loss)/count
58
+ return test_loss
59
+
60
+ def test(args, model, test_loader):
61
+ test_loss, test_accuracy = test_one_epoch(args.device, model, test_loader)
62
+
63
+
64
+ def options():
65
+ parser = argparse.ArgumentParser(description='Point Cloud Registration')
66
+ parser.add_argument('--exp_name', type=str, default='exp_ipcrnet', metavar='N',
67
+ help='Name of the experiment')
68
+ parser.add_argument('--dataset_path', type=str, default='ModelNet40',
69
+ metavar='PATH', help='path to the input dataset') # like '/path/to/ModelNet40'
70
+ parser.add_argument('--eval', type=bool, default=False, help='Train or Evaluate the network.')
71
+
72
+ # settings for input data
73
+ parser.add_argument('--dataset_type', default='modelnet', choices=['modelnet', 'shapenet2'],
74
+ metavar='DATASET', help='dataset type (default: modelnet)')
75
+ parser.add_argument('--num_points', default=1024, type=int,
76
+ metavar='N', help='points in point-cloud (default: 1024)')
77
+
78
+ # settings for PointNet
79
+ parser.add_argument('--emb_dims', default=1024, type=int,
80
+ metavar='K', help='dim. of the feature vector (default: 1024)')
81
+ parser.add_argument('--symfn', default='max', choices=['max', 'avg'],
82
+ help='symmetric function (default: max)')
83
+
84
+ # settings for on training
85
+ parser.add_argument('-j', '--workers', default=4, type=int,
86
+ metavar='N', help='number of data loading workers (default: 4)')
87
+ parser.add_argument('-b', '--batch_size', default=20, type=int,
88
+ metavar='N', help='mini-batch size (default: 32)')
89
+ parser.add_argument('--pretrained', default='learning3d/pretrained/exp_ipcrnet/models/best_model.t7', type=str,
90
+ metavar='PATH', help='path to pretrained model file (default: null (no-use))')
91
+ parser.add_argument('--device', default='cuda:0', type=str,
92
+ metavar='DEVICE', help='use CUDA if available')
93
+
94
+ args = parser.parse_args()
95
+ return args
96
+
97
+ def main():
98
+ args = options()
99
+
100
+ testset = RegistrationData('PCRNet', ModelNet40Data(train=False))
101
+ test_loader = DataLoader(testset, batch_size=args.batch_size, shuffle=False, drop_last=False, num_workers=args.workers)
102
+
103
+ if not torch.cuda.is_available():
104
+ args.device = 'cpu'
105
+ args.device = torch.device(args.device)
106
+
107
+ # Create PointNet Model.
108
+ ptnet = PointNet(emb_dims=args.emb_dims)
109
+ model = iPCRNet(feature_model=ptnet)
110
+ model = model.to(args.device)
111
+
112
+ if args.pretrained:
113
+ assert os.path.isfile(args.pretrained)
114
+ model.load_state_dict(torch.load(args.pretrained, map_location='cpu'))
115
+ model.to(args.device)
116
+
117
+ test(args, model, test_loader)
118
+
119
+ if __name__ == '__main__':
120
+ main()
@@ -0,0 +1,121 @@
1
+ import open3d as o3d
2
+ import argparse
3
+ import os
4
+ import sys
5
+ import logging
6
+ import numpy
7
+ import numpy as np
8
+ import torch
9
+ import torch.utils.data
10
+ import torchvision
11
+ from torch.utils.data import DataLoader
12
+ from tensorboardX import SummaryWriter
13
+ from tqdm import tqdm
14
+
15
+ # Only if the files are in example folder.
16
+ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
17
+ if BASE_DIR[-8:] == 'examples':
18
+ sys.path.append(os.path.join(BASE_DIR, os.pardir))
19
+ os.chdir(os.path.join(BASE_DIR, os.pardir))
20
+
21
+ from learning3d.models import PointNet, PointNetLK
22
+ from learning3d.losses import FrobeniusNormLoss, RMSEFeaturesLoss
23
+ from learning3d.data_utils import RegistrationData, ModelNet40Data
24
+
25
+ def display_open3d(template, source, transformed_source):
26
+ template_ = o3d.geometry.PointCloud()
27
+ source_ = o3d.geometry.PointCloud()
28
+ transformed_source_ = o3d.geometry.PointCloud()
29
+ template_.points = o3d.utility.Vector3dVector(template)
30
+ source_.points = o3d.utility.Vector3dVector(source + np.array([0,0,0]))
31
+ transformed_source_.points = o3d.utility.Vector3dVector(transformed_source)
32
+ template_.paint_uniform_color([1, 0, 0])
33
+ source_.paint_uniform_color([0, 1, 0])
34
+ transformed_source_.paint_uniform_color([0, 0, 1])
35
+ o3d.visualization.draw_geometries([template_, source_, transformed_source_])
36
+
37
+ def test_one_epoch(device, model, test_loader):
38
+ model.eval()
39
+ test_loss = 0.0
40
+ pred = 0.0
41
+ count = 0
42
+ for i, data in enumerate(tqdm(test_loader)):
43
+ template, source, igt = data
44
+
45
+ template = template.to(device)
46
+ source = source.to(device)
47
+ igt = igt.to(device)
48
+
49
+ output = model(template, source)
50
+
51
+ display_open3d(template.detach().cpu().numpy()[0], source.detach().cpu().numpy()[0], output['transformed_source'].detach().cpu().numpy()[0])
52
+ loss_val = FrobeniusNormLoss()(output['est_T'], igt) + RMSEFeaturesLoss()(output['r'])
53
+
54
+ test_loss += loss_val.item()
55
+ count += 1
56
+
57
+ test_loss = float(test_loss)/count
58
+ return test_loss
59
+
60
+ def test(args, model, test_loader):
61
+ test_loss, test_accuracy = test_one_epoch(args.device, model, test_loader)
62
+
63
+
64
+ def options():
65
+ parser = argparse.ArgumentParser(description='Point Cloud Registration')
66
+ parser.add_argument('--exp_name', type=str, default='exp_pnlk_v1', metavar='N',
67
+ help='Name of the experiment')
68
+ parser.add_argument('--dataset_path', type=str, default='ModelNet40',
69
+ metavar='PATH', help='path to the input dataset') # like '/path/to/ModelNet40'
70
+ parser.add_argument('--eval', type=bool, default=False, help='Train or Evaluate the network.')
71
+
72
+ # settings for input data
73
+ parser.add_argument('--dataset_type', default='modelnet', choices=['modelnet', 'shapenet2'],
74
+ metavar='DATASET', help='dataset type (default: modelnet)')
75
+ parser.add_argument('--num_points', default=1024, type=int,
76
+ metavar='N', help='points in point-cloud (default: 1024)')
77
+
78
+ # settings for PointNet
79
+ parser.add_argument('--emb_dims', default=1024, type=int,
80
+ metavar='K', help='dim. of the feature vector (default: 1024)')
81
+ parser.add_argument('--symfn', default='max', choices=['max', 'avg'],
82
+ help='symmetric function (default: max)')
83
+
84
+ # settings for on training
85
+ parser.add_argument('--seed', type=int, default=1234)
86
+ parser.add_argument('-j', '--workers', default=4, type=int,
87
+ metavar='N', help='number of data loading workers (default: 4)')
88
+ parser.add_argument('-b', '--batch_size', default=10, type=int,
89
+ metavar='N', help='mini-batch size (default: 32)')
90
+ parser.add_argument('--pretrained', default='learning3d/pretrained/exp_pnlk/models/best_model.t7', type=str,
91
+ metavar='PATH', help='path to pretrained model file (default: null (no-use))')
92
+ parser.add_argument('--device', default='cuda:0', type=str,
93
+ metavar='DEVICE', help='use CUDA if available')
94
+
95
+ args = parser.parse_args()
96
+ return args
97
+
98
+ def main():
99
+ args = options()
100
+
101
+ testset = RegistrationData('PointNetLK', ModelNet40Data(train=False))
102
+ test_loader = DataLoader(testset, batch_size=8, shuffle=False, drop_last=False, num_workers=args.workers)
103
+
104
+ if not torch.cuda.is_available():
105
+ args.device = 'cpu'
106
+ args.device = torch.device(args.device)
107
+
108
+ # Create PointNet Model.
109
+ ptnet = PointNet(emb_dims=args.emb_dims, use_bn=True)
110
+ model = PointNetLK(feature_model=ptnet)
111
+ model = model.to(args.device)
112
+
113
+ if args.pretrained:
114
+ assert os.path.isfile(args.pretrained)
115
+ model.load_state_dict(torch.load(args.pretrained, map_location='cpu'))
116
+ model.to(args.device)
117
+
118
+ test(args, model, test_loader)
119
+
120
+ if __name__ == '__main__':
121
+ main()
@@ -0,0 +1,126 @@
1
+ import open3d as o3d
2
+ import argparse
3
+ import os
4
+ import sys
5
+ import logging
6
+ import numpy
7
+ import numpy as np
8
+ import torch
9
+ import torch.utils.data
10
+ import torchvision
11
+ from torch.utils.data import DataLoader
12
+ from tensorboardX import SummaryWriter
13
+ from tqdm import tqdm
14
+
15
+ # Only if the files are in example folder.
16
+ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
17
+ if BASE_DIR[-8:] == 'examples':
18
+ sys.path.append(os.path.join(BASE_DIR, os.pardir))
19
+ os.chdir(os.path.join(BASE_DIR, os.pardir))
20
+
21
+ from learning3d.models import create_pointconv
22
+ from learning3d.models import Classifier
23
+ from learning3d.data_utils import ClassificationData, ModelNet40Data
24
+
25
+ def display_open3d(template):
26
+ template_ = o3d.geometry.PointCloud()
27
+ template_.points = o3d.utility.Vector3dVector(template)
28
+ # template_.paint_uniform_color([1, 0, 0])
29
+ o3d.visualization.draw_geometries([template_])
30
+
31
+ def test_one_epoch(device, model, test_loader, testset):
32
+ model.eval()
33
+ test_loss = 0.0
34
+ pred = 0.0
35
+ count = 0
36
+ for i, data in enumerate(tqdm(test_loader)):
37
+ points, target = data
38
+ target = target[:,0]
39
+
40
+ points = points.to(device)
41
+ target = target.to(device)
42
+
43
+ output = model(points)
44
+ loss_val = torch.nn.functional.nll_loss(
45
+ torch.nn.functional.log_softmax(output, dim=1), target, size_average=False)
46
+ print("Ground Truth Label: ", testset.get_shape(target[0].item()))
47
+ print("Predicted Label: ", testset.get_shape(torch.argmax(output[0]).item()))
48
+ display_open3d(points.detach().cpu().numpy()[0])
49
+
50
+ test_loss += loss_val.item()
51
+ count += output.size(0)
52
+
53
+ _, pred1 = output.max(dim=1)
54
+ ag = (pred1 == target)
55
+ am = ag.sum()
56
+ pred += am.item()
57
+
58
+ test_loss = float(test_loss)/count
59
+ accuracy = float(pred)/count
60
+ return test_loss, accuracy
61
+
62
+ def test(args, model, test_loader, testset):
63
+ test_loss, test_accuracy = test_one_epoch(args.device, model, test_loader, testset)
64
+
65
+ def options():
66
+ parser = argparse.ArgumentParser(description='Point Cloud Registration')
67
+ parser.add_argument('--dataset_path', type=str, default='ModelNet40',
68
+ metavar='PATH', help='path to the input dataset') # like '/path/to/ModelNet40'
69
+ parser.add_argument('--eval', type=bool, default=False, help='Train or Evaluate the network.')
70
+
71
+ # settings for input data
72
+ parser.add_argument('--dataset_type', default='modelnet', choices=['modelnet', 'shapenet2'],
73
+ metavar='DATASET', help='dataset type (default: modelnet)')
74
+ parser.add_argument('--num_points', default=1024, type=int,
75
+ metavar='N', help='points in point-cloud (default: 1024)')
76
+
77
+ # settings for PointNet
78
+ parser.add_argument('--pointnet', default='tune', type=str, choices=['fixed', 'tune'],
79
+ help='train pointnet (default: tune)')
80
+ parser.add_argument('-j', '--workers', default=4, type=int,
81
+ metavar='N', help='number of data loading workers (default: 4)')
82
+ parser.add_argument('-b', '--batch_size', default=32, type=int,
83
+ metavar='N', help='mini-batch size (default: 32)')
84
+ parser.add_argument('--emb_dims', default=1024, type=int,
85
+ metavar='K', help='dim. of the feature vector (default: 1024)')
86
+ parser.add_argument('--symfn', default='max', choices=['max', 'avg'],
87
+ help='symmetric function (default: max)')
88
+
89
+ # settings for on training
90
+ parser.add_argument('--pretrained', default='learning3d/pretrained/exp_classifier/models/best_model.t7', type=str,
91
+ metavar='PATH', help='path to pretrained model file (default: null (no-use))')
92
+ parser.add_argument('--device', default='cuda:0', type=str,
93
+ metavar='DEVICE', help='use CUDA if available')
94
+
95
+ args = parser.parse_args()
96
+ return args
97
+
98
+ def main():
99
+ args = options()
100
+ args.dataset_path = os.path.join(os.getcwd(), os.pardir, os.pardir, 'ModelNet40', 'ModelNet40')
101
+
102
+ testset = ClassificationData(ModelNet40Data(train=False))
103
+ test_loader = DataLoader(testset, batch_size=args.batch_size, shuffle=False, drop_last=False, num_workers=args.workers)
104
+
105
+ if not torch.cuda.is_available():
106
+ args.device = 'cpu'
107
+ args.device = torch.device(args.device)
108
+
109
+ # To use pretrained model provided by authors.
110
+ # PointConv = create_pointconv(classifier=True, pretrained='path of pretrained model.')
111
+ # model = PointConv(emb_dims=args.emb_dims, classifier=True, pretrained='path of pretrained model.')
112
+
113
+ # To use your own pretrained model.
114
+ PointConv = create_pointconv(classifier=False, pretrained=None)
115
+ ptconv = PointConv(emb_dims=args.emb_dims, classifier=True, pretrained=None)
116
+ model = Classifier(feature_model=ptconv)
117
+
118
+ if args.pretrained:
119
+ assert os.path.isfile(args.pretrained)
120
+ model.load_state_dict(torch.load(args.pretrained, map_location='cpu'))
121
+ model.to(args.device)
122
+
123
+ test(args, model, test_loader, testset)
124
+
125
+ if __name__ == '__main__':
126
+ main()