@@ -107,6 +107,20 @@ def load_file(file_name):
107
107
return coords , colors , pcd
108
108
109
109
110
+ def normalize_color (color : torch .Tensor , is_color_in_range_0_255 : bool = False ) -> torch .Tensor :
111
+ r"""
112
+ Convert color in range [0, 1] to [-0.5, 0.5]. If the color is in range [0,
113
+ 255], use the argument `is_color_in_range_0_255=True`.
114
+
115
+ `color` (torch.Tensor): Nx3 color feature matrix
116
+ `is_color_in_range_0_255` (bool): If the color is in range [0, 255] not [0, 1], normalize the color to [0, 1].
117
+ """
118
+ if is_color_in_range_0_255 :
119
+ color /= 255
120
+ color -= 0.5
121
+ return color .float ()
122
+
123
+
110
124
if __name__ == '__main__' :
111
125
config = parser .parse_args ()
112
126
device = torch .device ('cuda' if (
@@ -124,7 +138,7 @@ def load_file(file_name):
124
138
voxel_size = 0.02
125
139
# Feed-forward pass and get the prediction
126
140
in_field = ME .TensorField (
127
- features = torch .from_numpy (colors ). float ( ),
141
+ features = normalize_color ( torch .from_numpy (colors )),
128
142
coordinates = ME .utils .batched_coordinates ([coords / voxel_size ], dtype = torch .float32 ),
129
143
quantization_mode = ME .SparseTensorQuantizationMode .UNWEIGHTED_AVERAGE ,
130
144
minkowski_algorithm = ME .MinkowskiAlgorithm .SPEED_OPTIMIZED ,
0 commit comments