Open3D-ML

repository·main·Indexed 25 days ago

https://github.com/isl-org/open3d-ml

An extension of the Open3D library for 3D machine learning tasks, including semantic point cloud segmentation and 3D object detection. It provides pretrained models, training pipelines, and data processing tools compatible with PyTorch and TensorFlow. Supported models include RandLA-Net, KPConv, PointPillars, and PointRCNN, with integration for datasets such as SemanticKITTI, KITTI, Waymo, and ScanNet.

Tokens
17.5K
Snippets
36
Records
57
Agent score
80%

What's inside Open3D-ML

  1. Supported datasets in Open3D-ML

    main

    Open3D-ML provides built-in dataset reader classes for several major 3D datasets. To use these, you must first download the data from the respective official project pages. You can find helper scripts for downloading these datasets in the scripts/download_datasets directory of the repository.

    Supported datasets include:

    • SemanticKITTI
    • Toronto 3D
    • Semantic 3D
    • S3DIS
    • Paris-Lille 3D
    • Argoverse
    • KITTI
    • Lyft
    • nuScenes
    • Waymo
    • ScanNet
    • Pandaset
    • TUM-FAÇADE
  2. Visualize 3D data in TensorBoard with Open3D

    main

    Open3D allows interactive 3D visualization within TensorBoard. You can save geometry sequences (point clouds, meshes) along with properties like colors, semantic labels, and PBR materials. Data is saved as .msgpack files in a plugins/Open3D sub-folder within your event files.

    Key Features:

    • Geometry Sequences: Watch 3D data update over training steps.
    • PBR Materials: Support for high-quality materials (albedo, normal, roughness, etc.).
    • Task-Specific Visualization: Dedicated support for 3D semantic segmentation and object detection (including bounding boxes).
    • Comparison Tools: Synchronized time steps and viewpoints to compare different algorithm runs.

    Note: Summary writing works on all platforms, but running the TensorBoard process itself is not currently supported on macOS.

  3. Configure PBR materials for 3D models in TensorBoard

    main

    You can visualize rich 3D models using Physically Based Rendering (PBR) materials. Material properties are categorized into three types:

    • scalar: Uniform values (e.g., material_scalar_metallic).
    • vector: Uniform 4-element vectors (e.g., material_vector_base_color).
    • texture_map: Spatially varying properties using images (e.g., material_texture_map_albedo).

    Requirements:

    • To use texture maps, you must provide UV coordinates via vertex_texture_uvs or triangle_texture_uvs.
    • For metallic texture maps, you must also provide a base material_scalar_metallic value.
    • Specify the shader via the material_name key.

    Example dictionary structure:

    summary_3d = {
        "vertex_positions": model.vertex["positions"],
        "vertex_normals": model.vertex["normals"],
        "triangle_texture_uvs": model.triangle["texture_uvs"],
        "triangle_indices": model.triangle["indices"],
        "material_name": "defaultLit",
        "material_texture_map_albedo": albedo_image,
        "material_texture_map_normal": normal_image,
        "material_scalar_metallic": 1.0
    }
  4. Implement a custom Dataset class

    main

    To integrate a completely new dataset type into the library, you can implement a custom class in ml3d/datasets.

    1. BaseDataset: Inherit from BaseDataset and implement __init__, get_split, is_tested, and save_test_result.
    2. DatasetSplit: Implement a split class (e.g., MyDatasetSplit) that handles the actual data retrieval. It must implement __len__ and get_data(idx), where get_data returns a dictionary containing {'point': points, 'feat': features, 'label': labels}.
    from .base_dataset import BaseDataset
    
    class MyDataset(BaseDataset):
        def __init__(self, name="MyDataset"):
            super().__init__(name=name)
            # read file lists.
    
        def get_split(self, split):
            return MyDatasetSplit(self, split=split)
    
        def is_tested(self, attr):
            # checks whether attr['name'] is already tested.
    
        def save_test_result(self, results, attr):
            # save results['predict_labels'] to file.
    
    
    class MyDatasetSplit():
        def __init__(self, dataset, split='train'):
            self.split = split
            self.path_list = []
            # collect list of files relevant to split.
    
        def __len__(self):
            return len(self.path_list)
    
        def get_data(self, idx):
            path = self.path_list[idx]
            points, features, labels = read_pc(path)
            return {'point': points, 'feat': features, 'label': labels}
    
        def get_attr(self, idx):
            path = self.path_list[idx]
            name = path.split('/')[-1]
            return {'name': name, 'path': path, 'split': self.split}
  5. Install Open3D-ML

    main

    Open3D-ML is integrated into the Open3D v0.11+ Python distribution. To install the base Open3D library, ensure your pip is up to date and then install open3d.

    Compatible ML framework versions:

    • PyTorch 2.0.*
    • TensorFlow 2.13.* (macOS)
    • CUDA 10.1, 11.* (Optional on GNU/Linux x86_64)
    # make sure you have the latest pip version
    pip install --upgrade pip
    # install open3d
    pip install open3d
  6. Run inference on a point cloud

    main

    Inference processes a point cloud and returns results based on a trained model. To perform inference:

    1. Load the model using a checkpoint path (ckpt_path).
    2. Initialize the pipeline with the model and dataset.
    3. Retrieve a specific data sample from a split using split.get_data(index).
    4. Call pipeline.run_inference(data).
    import open3d.ml.torch as ml3d
    from open3d.ml.torch.models import RandLANet
    from open3d.ml.torch.pipelines import SemanticSegmentation
    
    # Note: get_module and args are assumed to be defined in the environment
    Pipeline = get_module("pipeline", "SemanticSegmentation", "torch")
    Model = get_module("model", "RandLANet", "torch")
    Dataset = get_module("dataset", "SemanticKITTI")
    
    # Create a checkpoint from the model
    RandLANet_model = Model(ckpt_path=args.path_ckpt_randlanet)
    SemanticKITTI = Dataset(args.path_semantickitti, use_cache=False)
    pipeline = Pipeline(model=RandLANet_model, dataset=SemanticKITTI)
    
    # Get data from the SemanticKITTI dataset using the "train" split
    train_split = SemanticKITTI.get_split("train")
    data = train_split.get_data(0)
    
    # Run the inference
    results = pipeline.run_inference(data)
    print(results)
  7. Run a test on a dataset split

    main

    Testing is similar to inference but uses the run_test method. This is typically used to evaluate the model on a predefined test set or a specific data sample.

    1. Initialize the pipeline with a checkpointed model and dataset.
    2. Retrieve data from a split.
    3. Call pipeline.run_test(data).
    import open3d.ml.torch as ml3d
    from open3d.ml.torch.models import RandLANet
    from open3d.ml.torch.pipelines import SemanticSegmentation
    
    Pipeline = get_module("pipeline", "SemanticSegmentation", "torch")
    Model = get_module("model", "RandLANet", "torch")
    Dataset = get_module("dataset", "SemanticKITTI")
    
    # Create a checkpoint
    RandLANet_model = Model(ckpt_path=args.path_ckpt_randlanet)
    SemanticKITTI = Dataset(args.path_semantickitti, use_cache=False)
    pipeline = Pipeline(model=RandLANet_model, dataset=SemanticKITTI)
    
    # Get data from the SemanticKITTI dataset using the "train" split
    train_split = SemanticKITTI.get_split("train")
    data = train_split.get_data(0)
    
    # Run the test
    pipeline.run_test(data)
  8. Train a model for 3D Object Detection

    main

    To train a 3D object detection model, create an ObjectDetection pipeline. Use use_cache=True in the dataset constructor to speed up training by caching preprocessing results. Call pipeline.run_train() to begin training.

    # use a cache for storing the results of the preprocessing (default path is './logs/cache')
    dataset = ml3d.datasets.KITTI(dataset_path='/path/to/KITTI/', use_cache=True)
    
    model = PointPillars()
    
    pipeline = ObjectDetection(model=model, dataset=dataset, max_epoch=100)
    
    # prints training progress in the console.
    pipeline.run_train()
  9. Build Open3D with TensorFlow support on Linux

    main

    From v0.18 onwards on Linux, the PyPI Open3D wheel does not have native support for TensorFlow due to build incompatibilities between PyTorch and TensorFlow.

    To use Open3D with TensorFlow on Linux, you must build the Open3D wheel from source using Docker. This method supports TensorFlow but not PyTorch. The following steps build wheels for Python 3.10 with TensorFlow support.

    cd docker
    # Build open3d and open3d-cpu wheels for Python 3.10 with Tensorflow support
    export BUILD_PYTORCH_OPS=OFF BUILD_TENSORFLOW_OPS=ON
    ./docker_build.sh cuda_wheel_py310
  10. Optimize 3D summary file size using property references

    main

    To avoid writing redundant geometry data (like vertex positions or normals) when only colors or other properties change, you can pass an integer (the step reference) instead of the full tensor for those properties. This significantly reduces the size of the summary files.

    for step in range(3):
        cube.paint_uniform_color(colors[step])
        cube_summary = to_dict_batch([cube])
        if step > 0:
            # Use 0 to indicate reuse of geometry from the previous step
            cube_summary['vertex_positions'] = 0
            cube_summary['vertex_normals'] = 0
        writer.add_3d('cube', cube_summary, step=step)
    for step in range(3):
            cube.paint_uniform_color(colors[step])
            cube_summary = to_dict_batch([cube])
            if step > 0:
                cube_summary['vertex_positions'] = 0
                cube_summary['vertex_normals'] = 0
            writer.add_3d('cube', cube_summary, step=step)
            cylinder.paint_uniform_color(colors[step])
            cylinder_summary = to_dict_batch([cylinder])
            if step > 0:
                cylinder_summary['vertex_positions'] = 0
                cylinder_summary['vertex_normals'] = 0
            writer.add_3d('cylinder', cylinder_summary, step=step)
  11. Verify Open3D-ML installation

    main

    You can verify that the Open3D-ML modules are correctly installed by attempting to import them via the command line. Use the module corresponding to your chosen framework.

    • For PyTorch support: import open3d.ml.torch
    • For TensorFlow support: import open3d.ml.tf
    # with PyTorch
    $ python -c "import open3d.ml.torch as ml3d"
    # or with TensorFlow
    $ python -c "import open3d.ml.tf as ml3d"