MCPcopy Create free account
hub / github.com/Colin97/DeepMetaHandles / _handle_pointcloud_input

Function _handle_pointcloud_input

src/losses.py:61–97  ·  view source on GitHub ↗

If points is an instance of Pointclouds, retrieve the padded points tensor along with the number of points per batch and the padded normals. Otherwise, return the input points (and normals) with the number of points per cloud set to the size of the second dimension of `points`.

(
    points: Union[torch.Tensor, Pointclouds],
    lengths: Union[torch.Tensor, None],
    normals: Union[torch.Tensor, None],
)

Source from the content-addressed store, hash-verified

59 raise ValueError('point_reduction must be one of ["mean", "sum"]')
60
61def _handle_pointcloud_input(
62 points: Union[torch.Tensor, Pointclouds],
63 lengths: Union[torch.Tensor, None],
64 normals: Union[torch.Tensor, None],
65):
66 """
67 If points is an instance of Pointclouds, retrieve the padded points tensor
68 along with the number of points per batch and the padded normals.
69 Otherwise, return the input points (and normals) with the number of points per cloud
70 set to the size of the second dimension of `points`.
71 """
72 if isinstance(points, Pointclouds):
73 X = points.points_padded()
74 lengths = points.num_points_per_cloud()
75 normals = points.normals_padded() # either a tensor or None
76 elif torch.is_tensor(points):
77 # pyre-fixme[16]: `Tensor` has no attribute `ndim`.
78 if points.ndim != 3:
79 raise ValueError("Expected points to be of shape (N, P, D)")
80 X = points
81 if lengths is not None and (
82 lengths.ndim != 1 or lengths.shape[0] != X.shape[0]
83 ):
84 raise ValueError("Expected lengths to be of shape (N,)")
85 if lengths is None:
86 lengths = torch.full(
87 (X.shape[0],), X.shape[1], dtype=torch.int64, device=points.device
88 )
89 if normals is not None and normals.ndim != 3:
90 raise ValueError("Expected normals to be of shape (N, P, 3")
91 else:
92 raise ValueError(
93 "The input pointclouds should be either "
94 + "Pointclouds objects or torch.Tensor of shape "
95 + "(minibatch, num_points, 3)."
96 )
97 return X, lengths, normals
98
99def chamfer_distance(
100 x,

Callers 1

chamfer_distanceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected