Data structure for point-level annotations or predictions. All data items in ``data_fields`` of ``PointData`` meet the following requirements: - They are all one dimension. - They should have the same length. `PointData` is used to save point-level semantic and instance mask,
| 41 | |
| 42 | |
| 43 | class PointData(BaseDataElement): |
| 44 | """Data structure for point-level annotations or predictions. |
| 45 | |
| 46 | All data items in ``data_fields`` of ``PointData`` meet the following |
| 47 | requirements: |
| 48 | |
| 49 | - They are all one dimension. |
| 50 | - They should have the same length. |
| 51 | |
| 52 | `PointData` is used to save point-level semantic and instance mask, |
| 53 | it also can save `instances_labels` and `instances_scores` temporarily. |
| 54 | In the future, we would consider to move the instance-level info into |
| 55 | `gt_instances_3d` and `pred_instances_3d`. |
| 56 | |
| 57 | Examples: |
| 58 | >>> metainfo = dict( |
| 59 | ... sample_idx=random.randint(0, 100)) |
| 60 | >>> points = np.random.randint(0, 255, (100, 3)) |
| 61 | >>> point_data = PointData(metainfo=metainfo, |
| 62 | ... points=points) |
| 63 | >>> print(len(point_data)) |
| 64 | 100 |
| 65 | |
| 66 | >>> # slice |
| 67 | >>> slice_data = point_data[10:60] |
| 68 | >>> assert len(slice_data) == 50 |
| 69 | |
| 70 | >>> # set |
| 71 | >>> point_data.pts_semantic_mask = torch.randint(0, 255, (100,)) |
| 72 | >>> point_data.pts_instance_mask = torch.randint(0, 255, (100,)) |
| 73 | >>> assert tuple(point_data.pts_semantic_mask.shape) == (100,) |
| 74 | >>> assert tuple(point_data.pts_instance_mask.shape) == (100,) |
| 75 | """ |
| 76 | |
| 77 | def __setattr__(self, name: str, value: Sized) -> None: |
| 78 | """setattr is only used to set data. |
| 79 | |
| 80 | The value must have the attribute of `__len__` and have the same length |
| 81 | of `PointData`. |
| 82 | """ |
| 83 | if name in ('_metainfo_fields', '_data_fields'): |
| 84 | if not hasattr(self, name): |
| 85 | super().__setattr__(name, value) |
| 86 | else: |
| 87 | raise AttributeError(f'{name} has been used as a ' |
| 88 | 'private attribute, which is immutable.') |
| 89 | |
| 90 | else: |
| 91 | assert isinstance(value, |
| 92 | Sized), 'value must contain `__len__` attribute' |
| 93 | # TODO: make sure the input value share the same length |
| 94 | super().__setattr__(name, value) |
| 95 | |
| 96 | __setitem__ = __setattr__ |
| 97 | |
| 98 | def __getitem__(self, item: IndexType) -> 'PointData': |
| 99 | """ |
| 100 | Args: |