Closed jingyi-zhang closed 3 years ago
This is a part code in 'getitem' function of DataSet
coords = lidar_camera[:,0:2]
#print(coords.shape[0])
features = lidar_camera[:,2:4]
labels = object_list
coords /= self.quantization_size
#print(coords.shape)
mapping = ME.utils.sparse_quantize(coords=coords,
return_index=True)
#print(len(mapping))
return coords[mapping], features[mapping], labels`
this my test code
train_set = SparseKittiDataset(classes=FLAGS.classes, split='training', augment=False, cfg=cfg)
train_loader = DataLoader(dataset=train_set, batch_size=FLAGS.batch_size, num_workers=FLAGS.workers,\
shuffle=True, drop_last=True,collate_fn=ME.utils.batch_sparse_collate)
for batch_idx, data_label in enumerate(train_loader):
coords, features, label = data_label
#print(features.shape)
#print(coords.shape)
input = ME.SparseTensor(features, coords, force_creation=True)
print(input)
break
It happens when you have duplicate coordinates.
The standard way to fix this error would be sampling one point per voxel. This process is known as the voxel down-sampling. In addition, a sparse tensor requires a list of integers to represent a coordinate, so you need to floor a coordinate to a quantized indices.
The engine supports such down-sampling and quantization. Please refer to sparse_quantize.
In most cases, a training pipeline consists of
However, for classification like tasks where you can safely ignore duplicate coordinates, you can use force_creation=True
. This should not be used for segmentation like tasks.
Please let me know if you have further questions.
In your example, you missed batched_coordinates
which was in the training collation function.
This results in 2D sparse tensor. Coordinates must have size N x 4, not N x 3 to create a 3D sparse tensor.
Thanks for your patience! You are so nice~
Took your advice, I used 'batched_coordinates' instead of 'batch_sparse_collate' to load data, then, the error has been solved.
But actually, I am still confused about the difference between 'batch_sparse_collate', 'SparseCollation' and 'batched_coordinates', I checked their definition in 'collation.py', seems like they have same function.
Thanks for your good code! but I got an error occasionally when use function 'SparseTensor' I dont know what caused this error ca