### Install Open3D-ML with ML support Source: https://context7.com/isl-org/open3d-ml/llms.txt Installs Open3D with ML support and compatible PyTorch or TensorFlow requirements. Verifies installation. ```bash pip install --upgrade pip pip install open3d # Install compatible PyTorch pip install -r requirements-torch.txt # Or compatible TensorFlow pip install -r requirements-tensorflow.txt # Verify torch installation python -c "import open3d.ml.torch as ml3d; print('OK')" # Verify tf installation python -c "import open3d.ml.tf as ml3d; print('OK')" ``` -------------------------------- ### Install Open3D Source: https://github.com/isl-org/open3d-ml/blob/main/README.md Installs the latest version of pip and then installs Open3D. Ensure you have the latest pip version before proceeding. ```bash pip install --upgrade pip pip install open3d ``` -------------------------------- ### Setup Imports and Geometry for PyTorch Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tensorboard.md Import necessary Open3D and TensorBoard modules, and create sample geometry (cube and cylinder) for visualization. This setup is for PyTorch integration. ```python import open3d as o3d # Monkey-patch torch.utils.tensorboard.SummaryWriter from open3d.visualization.tensorboard_plugin import summary # Utility function to convert Open3D geometry to a dictionary format from open3d.visualization.tensorboard_plugin.util import to_dict_batch from torch.utils.tensorboard import SummaryWriter cube = o3d.geometry.TriangleMesh.create_box(1, 2, 4) cube.compute_vertex_normals() cylinder = o3d.geometry.TriangleMesh.create_cylinder(radius=1.0, height=2.0, resolution=20, split=4) cylinder.compute_vertex_normals() colors = [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)] ``` -------------------------------- ### Start TensorBoard from Command Line Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tensorboard.md Use this command to launch TensorBoard and visualize the logged data. The `--logdir` flag specifies the directory where the summary files are stored. ```sh tensorboard --logdir demo_logs/pytorch ``` -------------------------------- ### Install OpenVINO Requirements Source: https://github.com/isl-org/open3d-ml/blob/main/docs/openvino.md Install the necessary OpenVINO dependencies using the provided requirements file. ```sh pip install -r requirements-openvino.txt ``` -------------------------------- ### Get Help for run_pipeline.py Source: https://github.com/isl-org/open3d-ml/blob/main/scripts/README.md Run this command to display the help message and understand all available arguments and options for the run_pipeline.py script. ```shell python scripts/run_pipeline.py --help ``` -------------------------------- ### Install PyTorch with CUDA support Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tutorial/notebook/train_ss_model_using_pytorch.rst Install a compatible version of PyTorch using the provided requirements file. Ensure you have CUDA installed for GPU acceleration. ```bash pip install -r requirements-torch-cuda.txt ``` -------------------------------- ### Test Open3D-ML Installation Source: https://github.com/isl-org/open3d-ml/blob/main/README.md Verifies the installation of Open3D-ML by importing the PyTorch or TensorFlow module. This confirms that the ML framework integration is working correctly. ```python import open3d.ml.torch as ml3d ``` ```python import open3d.ml.tf as ml3d ``` -------------------------------- ### Train Model with TensorFlow using Config File Source: https://github.com/isl-org/open3d-ml/blob/main/scripts/README.md This example shows how to train a model using TensorFlow by providing a configuration file. It also demonstrates overriding pipeline batch size via command line arguments. ```shell # Use a config file to train this model with tensorflow python scripts/run_pipeline.py tf -c ml3d/configs/kpconv_semantickitti.yml \ --dataset_path ../--pipeline.batch_size 2 ``` -------------------------------- ### Load Configuration and Get Modules Source: https://github.com/isl-org/open3d-ml/blob/main/README.md Loads a configuration file and fetches pipeline, model, and dataset modules based on the configuration. This is useful for setting up training or inference pipelines. ```python import open3d.ml as _ml3d import open3d.ml.torch as ml3d # or open3d.ml.tf as ml3d framework = "torch" # or tf cfg_file = "ml3d/configs/randlanet_semantickitti.yml" cfg = _ml3d.utils.Config.load_from_file(cfg_file) # fetch the classes by the name Pipeline = _ml3d.utils.get_module("pipeline", cfg.pipeline.name, framework) Model = _ml3d.utils.get_module("model", cfg.model.name, framework) Dataset = _ml3d.utils.get_module("dataset", cfg.dataset.name) ``` -------------------------------- ### Setup Imports for TensorFlow Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tensorboard.md Import necessary Open3D and TensorFlow modules for TensorBoard integration. This setup is for TensorFlow users. ```python import open3d as o3d from open3d.visualization.tensorboard_plugin import summary # Utility function to convert Open3D geometry to a dictionary format from open3d.visualization.tensorboard_plugin.util import to_dict_batch import tensorflow as tf ``` -------------------------------- ### Start TensorBoard in Jupyter Notebook Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tensorboard.md For users working within a Jupyter notebook environment, these magic commands can be used to load the TensorBoard extension and specify the log directory for visualization. ```python %load_ext tensorboard %tensorboard --logdir demo_logs/pytorch ``` -------------------------------- ### Run TensorBoard Visualization Script Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tensorboard.md This command shows how to execute the Python script that generates TensorBoard logs for the small-scale example. This is typically run from the command line. ```sh python examples/python/gui/tensorboard_pytorch.py small_scale ``` -------------------------------- ### Install ML Framework Requirements Source: https://github.com/isl-org/open3d-ml/blob/main/README.md Installs compatible versions of TensorFlow or PyTorch using provided requirements files. Use the appropriate file for your chosen framework or for PyTorch with CUDA support on Linux. ```bash pip install -r requirements-tensorflow.txt ``` ```bash pip install -r requirements-torch.txt ``` ```bash pip install -r requirements-torch-cuda.txt ``` -------------------------------- ### Run Optimized Geometry Logging Example Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tensorboard.md This command executes the Python script that utilizes property referencing for optimized TensorBoard logging. This is useful for reducing log file sizes when geometry properties remain consistent across steps. ```sh python examples/python/gui/tensorboard_pytorch.py property_reference ``` -------------------------------- ### Install TensorFlow Requirements Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tutorial/notebook/train_ss_model_using_tensorflow.rst Installs TensorFlow and its dependencies using a requirements file. Ensure this is run before proceeding with TensorFlow-specific operations. ```bash pip install -r requirements-tensorflow.txt ``` -------------------------------- ### Read and visualize custom dataset Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tutorial/notebook/add_own_dataset.rst Import Open3D ML, instantiate a Custom3DSplit dataset, and get the training split. Visualize the first 100 frames of the training split. ```python import open3d.ml.torch as ml3d dataset = ml3d.datasets.Custom3DSplit(dataset_path='../datasets/custom_dataset', cache_dir='./logs/cache',training_split=['00', '01', '02', '03', '04', '05', '06', '07', '09', '10']) train_split = dataset.get_split('training') MyVis = ml3d.vis.Visualizer() vis.visualize_dataset(dataset, 'training',indices=range(100)) ``` -------------------------------- ### Train PointPillars on KITTI with Torch Source: https://github.com/isl-org/open3d-ml/blob/main/scripts/README.md Example demonstrating training of the PointPillars model on the KITTI dataset using PyTorch. It includes specifying the configuration file, dataset path, pipeline type, and split. ```shell # Training on PointPillars and KITTI with torch. python scripts/run_pipeline.py torch -c ml3d/configs/pointpillars_kitti.yml --split test --dataset.dataset_path --pipeline ObjectDetection --dataset.use_cache True ``` -------------------------------- ### Run Pipeline with Single Config File Source: https://github.com/isl-org/open3d-ml/blob/main/scripts/README.md Execute the pipeline using a single configuration file that encompasses dataset, model, and pipeline settings. This simplifies setup for standardized training runs. ```shell python scripts/run_pipeline.py {tf|torch} -c CONFIG_FILE [optional arguments] ``` -------------------------------- ### Train RandLANet on SemanticKITTI with Torch Source: https://github.com/isl-org/open3d-ml/blob/main/scripts/README.md Example of training the RandLANet model on the SemanticKITTI dataset using PyTorch. It specifies the configuration file, dataset path, pipeline type, and enables caching. ```shell # Training on RandLANet and SemanticKITTI with torch. python scripts/run_pipeline.py torch -c ml3d/configs/randlanet_semantickitti.yml --dataset.dataset_path --pipeline SemanticSegmentation --dataset.use_cache True ``` -------------------------------- ### Set Open3D-ML Root Environment Variable Source: https://github.com/isl-org/open3d-ml/blob/main/docs/howtos.md Source a script to set the OPEN3D_ML_ROOT environment variable. This allows the '_ml_' namespace to point to the local repository, enabling testing with an installed Open3D package. ```bash source /path/to/Open3D-ML/set_open3d_ml_root.sh ``` -------------------------------- ### Log Basic 3D Geometry to TensorBoard Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tensorboard.md This snippet demonstrates how to create a TensorBoard summary writer and log basic 3D geometries like cubes and cylinders with changing colors at different steps. Ensure you have TensorFlow installed and configured for TensorBoard logging. ```python logdir = "demo_logs/tf/small_scale" writer = tf.summary.create_file_writer(logdir) with writer.as_default(): for step in range(3): cube.paint_uniform_color(colors[step]) summary.add_3d('cube', to_dict_batch([cube]), step=step, logdir=logdir) cylinder.paint_uniform_color(colors[step]) summary.add_3d('cylinder', to_dict_batch([cylinder]), step=step, logdir=logdir) ``` -------------------------------- ### Load Config and Construct Instances Source: https://github.com/isl-org/open3d-ml/blob/main/README.md Loads configuration from a file and constructs dataset, model, and pipeline instances. ```python cfg.dataset['dataset_path'] = "/path/to/your/dataset" dataset = Dataset(cfg.dataset.pop('dataset_path', None), **cfg.dataset) model = Model(**cfg.model) pipeline = Pipeline(model, dataset, **cfg.pipeline) ``` -------------------------------- ### Initialize Dataset with Config File Source: https://github.com/isl-org/open3d-ml/blob/main/scripts/README.md This command initializes a dataset using a configuration file. This is useful when dataset configurations are complex or pre-defined. Replace placeholders accordingly. ```shell python scripts/run_pipeline.py {tf|torch} -p PIPELINE_NAME -m MODEL_NAME \ -d DATASET_NAME --cfg_dataset DATASET_CONFIG_FILE [optional arguments] ``` -------------------------------- ### Initialize Visualizer and LabelLUT for SemanticKITTI Source: https://github.com/isl-org/open3d-ml/blob/main/docs/howtos.md Initializes the Visualizer and LabelLUT for visualizing SemanticKITTI dataset labels. Ensure LabelLUT is set up with correct label names and values. ```python import os from os import path from os.path import exists from ml3d.vis import Visualizer, LabelLUT from ml3d.datasets import SemanticKITTI kitti_labels = SemanticKITTI.get_label_to_names() v = Visualizer() lut = LabelLUT() for val in sorted(kitti_labels.keys()): lut.add_label(kitti_labels[val], val) v.set_lut("labels", lut) v.set_lut("pred", lut) ``` -------------------------------- ### Run Training with `run_pipeline.py` Script (Torch) Source: https://github.com/isl-org/open3d-ml/blob/main/README.md Launches training for the RandLANet model on the SemanticKITTI dataset using PyTorch. Ensure to replace `` with the actual dataset path and set `dataset.use_cache` appropriately. ```bash python scripts/run_pipeline.py torch -c ml3d/configs/randlanet_semantickitti.yml --dataset.dataset_path --pipeline SemanticSegmentation --dataset.use_cache True ``` -------------------------------- ### Get Pipeline and Model Modules Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tutorial/notebook/train_ss_model_using_tensorflow.rst Retrieves pipeline and model modules for TensorFlow. This is a utility function used to dynamically load components for inference or further training. ```python #Training Semantic Segmentation Model using TensorFlow #Import tensorflow and the model to use for training import open3d.ml.tf as ml3d from open3d.ml.tf.models import RandLANet from open3d.ml.tf.pipelines import SemanticSegmentation #Get pipeline, model, and dataset. Pipeline = get_module("pipeline", "SemanticSegmentation", "tf") Model = get_module("model", "RandLANet", "tf") ``` -------------------------------- ### Visualize Custom Point Cloud Data with Attributes Source: https://context7.com/isl-org/open3d-ml/llms.txt Demonstrates how to use the `Visualizer` and `LabelLUT` to display custom point cloud data with associated attributes and colors. Ensure `open3d.ml.torch` is imported. ```python import numpy as np import open3d.ml.torch as ml3d # --- Visualize custom data with attributes --- num_points = 100_000 points = np.random.rand(num_points, 3).astype(np.float32) data = [{ 'name': 'my_cloud', 'points': points, # (N, 3) required 'random_colors': np.random.rand(*points.shape).astype(np.float32), 'int_attr': (points[:, 0] * 5).astype(np.int32), }] vis = ml3d.vis.Visualizer() vis.visualize(data) # --- Use a custom LabelLUT --- lut = ml3d.vis.LabelLUT() lut.add_label('unlabeled', 0) lut.add_label('car', 1, [1, 0, 0]) # red lut.add_label('road', 2, [0.5, 0.5, 0]) # olive vis.set_lut("int_attr", lut) vis.visualize(data) ``` -------------------------------- ### Initialize Dataset with Path Source: https://github.com/isl-org/open3d-ml/blob/main/scripts/README.md Use this command to initialize a dataset by providing its direct path. Ensure you replace placeholders like {tf|torch}, PIPELINE_NAME, MODEL_NAME, DATASET_NAME, and DATASET_PATH with your specific values. ```shell python scripts/run_pipeline.py {tf|torch} -p PIPELINE_NAME -m MODEL_NAME \ -d DATASET_NAME --dataset_path DATASET_PATH [optional arguments] ``` -------------------------------- ### Train a Model with a Custom Dataset Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tutorial/notebook/add_own_dataset.rst Initialize a model and a training pipeline, then run training using your custom dataset. ```python import open3d.ml.torch as ml3d from open3d.ml.torch.models import RandLANet from open3d.ml.torch.pipelines import SemanticSegmentation dataset = ml3d.datasets.custom_dataset(dataset_path='../datasets/custom_dataset', cache_dir='./logs/cache',training_split=['00', '01', '02', '03', '04', '05', '06', '07', '09', '10']) model = RandLANet(dim_input=3) pipeline = SemanticSegmentation(model=model, dataset=dataset, max_epoch=100) pipeline.run_train() ``` -------------------------------- ### Load Models and Prepare Data for Visualization Source: https://github.com/isl-org/open3d-ml/blob/main/docs/howtos.md Loads pre-trained RandLANet and KPFCNN models, sets up semantic segmentation pipelines, and prepares point cloud data for visualization. Downloads weights if not found locally. ```python from ml3d.torch.pipelines import SemanticSegmentation from ml3d.torch.models import RandLANet, KPFCNN kpconv_url = "https://storage.googleapis.com/open3d-releases/model-zoo/kpconv_semantickitti_202009090354utc.pth" randlanet_url = "https://storage.googleapis.com/open3d-releases/model-zoo/randlanet_semantickitti_202201071330utc.pth" ckpt_path = "./logs/vis_weights_{}.pth".format('RandLANet') if not exists(ckpt_path): cmd = "wget {} -O {}".format(randlanet_url, ckpt_path) os.system(cmd) model = RandLANet(ckpt_path=ckpt_path) pipeline_r = SemanticSegmentation(model) pipeline_r.load_ckpt(model.cfg.ckpt_path) ckpt_path = "./logs/vis_weights_{}.pth".format('KPFCNN') if not exists(ckpt_path): cmd = "wget {} -O {}".format(kpconv_url, ckpt_path) print(cmd) os.system(cmd) model = KPFCNN(ckpt_path=ckpt_path, in_radius=10) pipeline_k = SemanticSegmentation(model) pipeline_k.load_ckpt(model.cfg.ckpt_path) data_path = ensure_demo_data() # from examples/util.py, downloads demo data pc_names = ["000700", "000750"] # see this function in examples/vis_pred.py, # or it can be your customized dataloader, # or you can use the existing get_data() methods in ml3d/datasets pcs = get_custom_data(pc_names, data_path) ``` -------------------------------- ### Instantiate Model and Dataset Source: https://github.com/isl-org/open3d-ml/blob/main/docs/howtos.md Import the Open3D-ML library and instantiate a custom model and dataset. This assumes the OPEN3D_ML_ROOT environment variable is set. ```python import open3d.ml.torch as ml3d # prints "Using external Open3D-ML in /path/to/Open3D-ML" model = ml3d.models.MyModel() dataset = ml3d.datasets.MyDataset() ``` -------------------------------- ### Train PointPillars on KITTI (Torch) Source: https://context7.com/isl-org/open3d-ml/llms.txt Command-line execution for training a PointPillars model on the KITTI dataset using PyTorch. Requires a configuration file and dataset path. ```bash python scripts/run_pipeline.py torch \ -c ml3d/configs/pointpillars_kitti.yml \ --dataset.dataset_path /data/KITTI \ --pipeline ObjectDetection \ --dataset.use_cache True ``` -------------------------------- ### Train Semantic Segmentation Model using TensorFlow Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tutorial/notebook/train_ss_model_using_tensorflow.rst This code block shows the setup for training a semantic segmentation model with TensorFlow. It imports necessary modules, loads the RandLANet model and SemanticKITTI dataset, and configures the pipeline for training. ```python #Training Semantic Segmentation Model using TensorFlow #Import tensorflow and the model to use for training import open3d.ml.tf as ml3d from open3d.ml.tf.models import RandLANet from open3d.ml.tf.pipelines import SemanticSegmentation #Get pipeline, model, and dataset. Pipeline = get_module("pipeline", "SemanticSegmentation", "tf") Model = get_module("model", "RandLANet", "tf") Dataset = get_module("dataset", "SemanticKITTI") #Create a checkpoint RandLANet = Model(ckpt_path=args.path_ckpt_randlanet) SemanticKITTI = Dataset(args.path_semantickitti, use_cache=False) pipeline = Pipeline(model=RandLANet, 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) ``` -------------------------------- ### Load and use configuration with Open3D-ML Source: https://context7.com/isl-org/open3d-ml/llms.txt Loads a YAML configuration, dynamically retrieves modules (Pipeline, Model, Dataset), and constructs instances. Allows runtime overrides for dataset paths. ```python import open3d.ml as _ml3d import open3d.ml.torch as ml3d # Load a YAML config cfg = _ml3d.utils.Config.load_from_file("ml3d/configs/randlanet_semantickitti.yml") # Dynamic module lookup using config names Pipeline = _ml3d.utils.get_module("pipeline", cfg.pipeline.name, "torch") Model = _ml3d.utils.get_module("model", cfg.model.name, "torch") Dataset = _ml3d.utils.get_module("dataset", cfg.dataset.name) # Override dataset path then construct instances cfg.dataset['dataset_path'] = "/data/SemanticKITTI" dataset = Dataset(cfg.dataset.pop('dataset_path'), **cfg.dataset) model = Model(**cfg.model) pipeline = Pipeline(model, dataset, **cfg.pipeline) # Or construct directly from classes from ml3d.torch.models import RandLANet from ml3d.torch.pipelines import SemanticSegmentation from ml3d.datasets import SemanticKITTI dataset = SemanticKITTI(dataset_path="/data/SemanticKITTI", use_cache=True) model = RandLANet(num_classes=19, num_points=45056) pipeline = SemanticSegmentation(model, dataset, batch_size=4, max_epoch=100, learning_rate=1e-3, main_log_dir="./logs") ``` -------------------------------- ### Create Checkpoint and Initialize Pipeline Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tutorial/notebook/train_ss_model_using_pytorch.rst Loads a pre-trained RandLANet model from a checkpoint and initializes the Semantic Segmentation pipeline with the model and the SemanticKITTI dataset. ```python #Create a checkpoint RandLANet = Model(ckpt_path=args.path_ckpt_randlanet) SemanticKITTI = Dataset(args.path_semantickitti, use_cache=False) pipeline = Pipeline(model=RandLANet, dataset=SemanticKITTI) ``` -------------------------------- ### Build Open3D with TensorFlow Support on Linux Source: https://github.com/isl-org/open3d-ml/blob/main/README.md Builds Open3D wheels with TensorFlow support on Linux using Docker. This is necessary for Linux users who need to use Open3D with TensorFlow, as native PyPI wheels may have incompatibilities. ```bash cd docker export BUILD_PYTORCH_OPS=OFF BUILD_TENSORFLOW_OPS=ON ./docker_build.sh cuda_wheel_py310 ``` -------------------------------- ### Run Object Detection Pipeline (PyTorch) Source: https://context7.com/isl-org/open3d-ml/llms.txt Execute the object detection pipeline using PyTorch backend for testing. ```bash python scripts/run_pipeline.py torch \ -c ml3d/configs/pointpillars_kitti.yml \ --dataset.dataset_path /data/KITTI \ --pipeline ObjectDetection \ --split test ``` -------------------------------- ### Preprocess custom dataset Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tutorial/notebook/add_own_dataset.rst Convert labels to pointcloud data. Ensure you are in the dataset directory before running. ```bash cd dataset/custom_dataset python preprocess.py ``` -------------------------------- ### Initialize Dataset and Model for Training Source: https://github.com/isl-org/open3d-ml/blob/main/README.md Loads the KITTI dataset with caching enabled and initializes a PointPillars model. This is a prerequisite for setting up a training pipeline. ```python 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() ``` -------------------------------- ### Load KITTI 3D object detection dataset Source: https://context7.com/isl-org/open3d-ml/llms.txt Initializes the KITTI dataset for 3D object detection. Provides access to point cloud data and bounding box annotations. ```python from ml3d.datasets import KITTI dataset = KITTI( dataset_path="/data/KITTI", cache_dir="./logs/cache", use_cache=True, ) test_split = dataset.get_split("test") data = test_split.get_data(0) # data keys: 'point' (N,4 — x,y,z,intensity), 'bounding_boxes' (list of BEVBox3D) print("Points:", data['point'].shape) print("Boxes: ", len(data['bounding_boxes'])) ``` -------------------------------- ### Load and iterate SemanticKITTI dataset Source: https://context7.com/isl-org/open3d-ml/llms.txt Initializes the SemanticKITTI dataset, allowing iteration over splits and inspection of individual samples. Includes label mapping. ```python from ml3d.datasets import SemanticKITTI dataset = SemanticKITTI( dataset_path="/data/SemanticKITTI", cache_dir="./logs/cache", use_cache=True, ignored_label_inds=[0], ) # Iterate over a split train_split = dataset.get_split("training") # or 'validation', 'test', 'all' print(f"Training samples: {len(train_split)}") # Inspect a single sample attr = train_split.get_attr(0) # {'name': ..., 'path': ..., 'split': 'training'} data = train_split.get_data(0) # {'point': ndarray(N,3), 'feat': ..., 'label': ndarray(N,)} print(attr) print("Point cloud shape:", data['point'].shape) print("Label shape: ", data['label'].shape) # Label mapping label_to_names = SemanticKITTI.get_label_to_names() # {0: 'unlabeled', 1: 'car', 2: 'bicycle', ...} print(label_to_names) ``` -------------------------------- ### Visualize Entire Dataset Split Source: https://context7.com/isl-org/open3d-ml/llms.txt Shows how to visualize a specified number of frames from a dataset split using the `Visualizer`. Requires the dataset to be initialized with its path. ```python from ml3d.datasets import SemanticKITTI # ... (previous visualization code) ... # --- Visualize an entire dataset split --- dataset = SemanticKITTI(dataset_path="/data/SemanticKITTI") vis.visualize_dataset(dataset, split='training', indices=range(50)) ``` -------------------------------- ### Checkpoint Management: Load and Save Source: https://context7.com/isl-org/open3d-ml/llms.txt Provides methods to load and save model checkpoints, including optimizer and scheduler states. `is_resume=True` is used when resuming training. ```python # Load a specific checkpoint pipeline.load_ckpt(ckpt_path="./logs/checkpoint/ckpt_00050.pth", is_resume=True) # Save checkpoint at a given epoch pipeline.save_ckpt(epoch=50) # Saves to ./logs/__torch/checkpoint/ckpt_00050.pth ``` -------------------------------- ### Run Pretrained 3D Object Detection Model Source: https://github.com/isl-org/open3d-ml/blob/main/README.md Instantiates a pipeline with a pretrained PointPillars model for 3D object detection and runs inference on a point cloud. Downloads weights if not present. ```python import os import open3d.ml as _ml3d import open3d.ml.torch as ml3d cfg_file = "ml3d/configs/pointpillars_kitti.yml" cfg = _ml3d.utils.Config.load_from_file(cfg_file) model = ml3d.models.PointPillars(**cfg.model) cfg.dataset['dataset_path'] = "/path/to/your/dataset" dataset = ml3d.datasets.KITTI(cfg.dataset.pop('dataset_path', None), **cfg.dataset) pipeline = ml3d.pipelines.ObjectDetection(model, dataset=dataset, device="gpu", **cfg.pipeline) # download the weights. ckpt_folder = "./logs/" os.makedirs(ckpt_folder, exist_ok=True) ckpt_path = ckpt_folder + "pointpillars_kitti_202012221652utc.pth" pointpillar_url = "https://storage.googleapis.com/open3d-releases/model-zoo/pointpillars_kitti_202012221652utc.pth" if not os.path.exists(ckpt_path): cmd = "wget {} -O {}".format(pointpillar_url, ckpt_path) os.system(cmd) # load the parameters. pipeline.load_ckpt(ckpt_path=ckpt_path) test_split = dataset.get_split("test") data = test_split.get_data(0) # run inference on a single example. # returns dict with 'predict_labels' and 'predict_scores'. result = pipeline.run_inference(data) # evaluate performance on the test set; this will write logs to './logs'. pipeline.run_test() ``` -------------------------------- ### Load and Visualize SemanticKITTI Dataset Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tutorial/notebook/train_ss_model_using_pytorch.rst Load the SemanticKITTI dataset and visualize a subset of its frames using ml3d.datasets.SemanticKITTI and ml3d.vis.Visualizer. Specify dataset path, cache directory, and training splits. ```python #Training Semantic Segmentation Model using PyTorch #import torch import open3d.ml.torch as ml3d #Read a dataset by specifying the path. We are also providing the cache directory and training split. dataset = ml3d.datasets.SemanticKITTI(dataset_path='../datasets/', cache_dir='./logs/cache',training_split=['00', '01', '02', '03', '04', '05', '06', '07', '09', '10']) #Split the dataset for 'training'. You can get the other splits by passing 'validation' or 'test' train_split = dataset.get_split('training') #view the first 1000 frames using the visualizer MyVis = ml3d.vis.Visualizer() vis.visualize_dataset(dataset, 'training',indices=range(100)) ``` -------------------------------- ### Initialize PointPillars for 3D Object Detection Source: https://context7.com/isl-org/open3d-ml/llms.txt Configure and initialize the `PointPillars` model for fast 3D object detection. This model voxelizes point clouds into pillars and uses a 2D convolutional detection head. Key parameters include the point cloud range and voxel size. A checkpoint path can be provided. ```python from ml3d.torch.models import PointPillars model = PointPillars( name='PointPillars', point_cloud_range=[0, -40, -3, 70.4, 40, 1], voxel_size=[0.16, 0.16, 4], ckpt_path="./logs/pointpillars_kitti.pth", ) ``` -------------------------------- ### Create RandLANet configuration for custom dataset Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tutorial/notebook/add_own_dataset.rst Define dataset, model, and pipeline parameters for training a RandLANet model on a custom dataset. Save this as a .yml file. ```yaml dataset: name: CUSTOM dataset_path: # dataset/custom_dataset cache_dir: ./logs/cache class_weights: [3370714, 2856755, 4919229, 318158, 375640, 478001, 974733, 650464, 791496, 88727, 1284130, 229758, 2272837] ignored_label_inds: [] num_points: 40960 test_area_idx: 3 test_result_folder: ./test use_cache: False model: name: RandLANet batcher: DefaultBatcher ckpt_path: # path/to/your/checkpoint dim_feature: 8 dim_input: 6 dim_output: - 16 - 64 - 128 - 256 - 512 grid_size: 0.04 ignored_label_inds: [] k_n: 16 num_classes: 13 num_layers: 5 num_points: 40960 sub_sampling_ratio: - 4 - 4 - 4 - 4 - 2 t_normalize: method: linear normalize_points: False feat_bias: 0 feat_scale: 1 pipeline: name: SemanticSegmentation adam_lr: 0.01 batch_size: 2 learning_rate: 0.01 main_log_dir: ./logs max_epoch: 100 save_ckpt_freq: 20 scheduler_gamma: 0.95 test_batch_size: 3 train_sum_dir: train_log val_batch_size: 2 ``` -------------------------------- ### Multi-GPU Distributed Training (PyTorch) Source: https://context7.com/isl-org/open3d-ml/llms.txt Configure and run multi-GPU distributed training for object detection across multiple nodes. ```bash python scripts/run_pipeline.py torch \ -c ml3d/configs/pointpillars_waymo.yml \ --dataset.dataset_path /data/Waymo \ --pipeline ObjectDetection \ --device_ids 0 1 2 3 \ --nodes 2 --node_rank 0 ``` -------------------------------- ### Log Rich 3D Models with PBR Materials to TensorBoard Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tensorboard.md This snippet shows how to log rich 3D models with PBR (Physically Based Rendering) material properties to TensorBoard. It involves loading a mesh, preparing a dictionary with geometry and material properties, and then logging it. ```python model_dir = "examples/test_data/monkey" logdir = "demo_logs/pytorch/monkey" model = o3d.t.geometry.TriangleMesh.from_legacy( o3d.io.read_triangle_mesh(os.path.join(model_dir, "monkey.obj"))) # Create geometry dict 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" } # translate material property names (from texture map file names) to Open3D ``` -------------------------------- ### Import and Initialize PyTorch Components for Semantic Segmentation Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tutorial/notebook/train_ss_model_using_pytorch.rst Imports PyTorch, the RandLANet model, and the Semantic Segmentation pipeline. It then retrieves module components for the pipeline, model, and dataset. ```python #Training Semantic Segmentation Model using PyTorch #Import torch and the model to use for training import open3d.ml.torch as ml3d from open3d.ml.torch.models import RandLANet from open3d.ml.torch.pipelines import SemanticSegmentation #Get pipeline, model, and dataset. Pipeline = get_module("pipeline", "SemanticSegmentation", "torch") Model = get_module("model", "RandLANet", "torch") Dataset = get_module("dataset", "SemanticKITTI") ``` -------------------------------- ### Wrap Model with OpenVINOModel Source: https://github.com/isl-org/open3d-ml/blob/main/docs/openvino.md Wrap an existing Open3D-ML model with the OpenVINOModel class to enable OpenVINO inference. ```python net = ml3d.models.PointPillars(**cfg.model, device='cpu') net = ml3d.models.OpenVINOModel(net) ``` -------------------------------- ### Test RandLANet on SemanticKITTI (Torch) Source: https://context7.com/isl-org/open3d-ml/llms.txt Command-line execution for testing a trained RandLANet model on a held-out split of the SemanticKITTI dataset. Requires the model checkpoint path. ```bash python scripts/run_pipeline.py torch \ -c ml3d/configs/randlanet_semantickitti.yml \ --dataset.dataset_path /data/SemanticKITTI \ --pipeline SemanticSegmentation \ --split test \ --model.ckpt_path ./logs/checkpoint/ckpt_00100.pth ``` -------------------------------- ### Optimize 3D Geometry Logging with Property References Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tensorboard.md This code snippet demonstrates an optimization technique for logging 3D geometries to TensorBoard. By referencing properties from previous steps (e.g., 'vertex_positions', 'vertex_normals'), redundant data is avoided, reducing the summary folder size. ```python 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) ``` -------------------------------- ### Initialize SparseConvUnet for Indoor Scene Segmentation Source: https://context7.com/isl-org/open3d-ml/llms.txt Configure and initialize the `SparseConvUnet` model, which uses sparse convolutions for semantic segmentation tasks in indoor scenes. The `voxel_size` parameter determines the resolution of the voxel grid. ```python from ml3d.torch.models import SparseConvUnet model = SparseConvUnet( name='SparseConvUnet', num_classes=20, voxel_size=0.05, ) ``` -------------------------------- ### Run Pretrained Semantic Segmentation Model Source: https://github.com/isl-org/open3d-ml/blob/main/README.md Instantiates a pipeline with a pretrained RandLANet model for semantic segmentation and runs inference on a point cloud. Downloads weights if not present. ```python import os import open3d.ml as _ml3d import open3d.ml.torch as ml3d cfg_file = "ml3d/configs/randlanet_semantickitti.yml" cfg = _ml3d.utils.Config.load_from_file(cfg_file) model = ml3d.models.RandLANet(**cfg.model) cfg.dataset['dataset_path'] = "/path/to/your/dataset" dataset = ml3d.datasets.SemanticKITTI(cfg.dataset.pop('dataset_path', None), **cfg.dataset) pipeline = ml3d.pipelines.SemanticSegmentation(model, dataset=dataset, device="gpu", **cfg.pipeline) # download the weights. ckpt_folder = "./logs/" os.makedirs(ckpt_folder, exist_ok=True) ckpt_path = ckpt_folder + "randlanet_semantickitti_202201071330utc.pth" randlanet_url = "https://storage.googleapis.com/open3d-releases/model-zoo/randlanet_semantickitti_202201071330utc.pth" if not os.path.exists(ckpt_path): cmd = "wget {} -O {}".format(randlanet_url, ckpt_path) os.system(cmd) # load the parameters. pipeline.load_ckpt(ckpt_path=ckpt_path) test_split = dataset.get_split("test") data = test_split.get_data(0) # run inference on a single example. # returns dict with 'predict_labels' and 'predict_scores'. result = pipeline.run_inference(data) # evaluate performance on the test set; this will write logs to './logs'. pipeline.run_test() ``` -------------------------------- ### Run Testing with `run_pipeline.py` Script (Torch) Source: https://github.com/isl-org/open3d-ml/blob/main/README.md Executes testing for the PointPillars model on the KITTI dataset using PyTorch. Specify the test split, dataset path, and pipeline. Caching can be enabled via `--dataset.use_cache True`. ```bash python scripts/run_pipeline.py torch -c ml3d/configs/pointpillars_kitti.yml --split test --dataset.dataset_path --pipeline ObjectDetection --dataset.use_cache True ``` -------------------------------- ### Run Inference with RandLANet on SemanticKITTI Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tutorial/notebook/train_ss_model_using_tensorflow.rst This snippet demonstrates how to perform inference using a pre-trained RandLANet model on the SemanticKITTI dataset. It covers loading the dataset, model, and pipeline, then running inference on a specific data sample. ```python Dataset = get_module("dataset", "SemanticKITTI") #Create a checkpoint RandLANet = Model(ckpt_path=args.path_ckpt_randlanet) SemanticKITTI = Dataset(args.path_semantickitti, use_cache=False) pipeline = Pipeline(model=RandLANet, 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 the results print(results) ``` -------------------------------- ### Switch OpenVINO Inference Device Source: https://github.com/isl-org/open3d-ml/blob/main/docs/openvino.md Switch the inference device for the OpenVINO model between CPU, GPU, and VPU. ```python net.to("cpu") net.to("gpu") net.to("myriad") ``` -------------------------------- ### Load SemanticKITTI Dataset with TensorFlow Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tutorial/notebook/train_ss_model_using_tensorflow.rst Loads the SemanticKITTI dataset for training. Specifies the dataset path, cache directory, and training splits. Visualizes the first 100 frames of the training split. ```python #Training Semantic Segmentation Model using TensorFlow #import tensorflow import open3d.ml.tf as ml3d #Read a dataset by specifying the path. We are also providing the cache directory and training split. dataset = ml3d.datasets.SemanticKITTI(dataset_path='../datasets/', cache_dir='./logs/cache',training_split=['00', '01', '02', '03', '04', '05', '06', '07', '09', '10']) #Split the dataset for 'training'. You can get the other splits by passing 'validation' or 'test' train_split = dataset.get_split('training') #view the first 1000 frames using the visualizer MyVis = ml3d.vis.Visualizer() vis.visualize_dataset(dataset, 'training',indices=range(100)) ``` -------------------------------- ### Train Semantic Segmentation Model Source: https://github.com/isl-org/open3d-ml/blob/main/README.md Sets up a SemanticKITTI dataset and a RandLANet model for training a semantic segmentation pipeline. Uses caching for preprocessing results. ```python # use a cache for storing the results of the preprocessing (default path is './logs/cache') dataset = ml3d.datasets.SemanticKITTI(dataset_path='/path/to/SemanticKITTI/', use_cache=True) # create the model with random initialization. model = RandLANet() pipeline = SemanticSegmentation(model=model, dataset=dataset, max_epoch=100) # prints training progress in the console. pipeline.run_train() ``` -------------------------------- ### Create Custom 3D Dataset with Custom3D Source: https://context7.com/isl-org/open3d-ml/llms.txt Use `Custom3D` to create a dataset from `.npy` files. Ensure files are organized in `train/`, `val/`, and `test/` subdirectories under `dataset_path`. Configuration options include cache usage, number of points, ignored labels, and test result folder. ```python from ml3d.datasets import Custom3D dataset = Custom3D( dataset_path="/data/my_pointclouds", name="MyDataset", use_cache=False, num_points=65536, ignored_label_inds=[], test_result_folder="./test_results", ) split = dataset.get_split("training") data = split.get_data(0) # data = {'point': ndarray(N,3), 'feat': ndarray(N,F) or None, 'label': ndarray(N,)} ``` -------------------------------- ### Initialize RandLANet for Semantic Segmentation Source: https://context7.com/isl-org/open3d-ml/llms.txt Configure and initialize the RandLANet model for large-scale point cloud semantic segmentation. Key parameters include the number of neighbors, layers, points per cloud, classes, and feature dimensions. A checkpoint path can be provided for pre-trained weights. ```python from ml3d.torch.models import RandLANet model = RandLANet( name='RandLANet', num_neighbors=16, num_layers=4, num_points=45056, # points per cloud during training num_classes=19, ignored_label_inds=[0], sub_sampling_ratio=[4, 4, 4, 4], in_channels=3, # 3 for xyz only; increase for additional features dim_features=8, dim_output=[16, 64, 128, 256], grid_size=0.06, ckpt_path="./logs/randlanet_semantickitti.pth", augment={'recenter': {'dim': [0, 1]}}, ) # Forward pass (called by pipeline internally) # results = model(batch_data) -> Tensor(B, N, num_classes) ``` -------------------------------- ### Configure Tensorboard Summary Recording Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tensorboard.md This configuration controls when and how summary data is recorded for 3D data visualization in TensorBoard. It allows specifying stages, subsampling points, and limiting outputs per batch. ```yaml summary: # Record summary in these stages (from train, valid, test) record_for: ['valid'] # Subsample point cloud if n_pts exceeds this value. Empty => save all # points in the summary. max_pts: 10000 # Only write input point cloud in the first epoch. In other epochs, use # reference to the first step. Do not use if each epoch has a different # order of minibatches. Do not use for RandLaNet or KPConv. use_reference: false # Write at most this many samples in each batch max_outputs: 1 ``` -------------------------------- ### Train RandLANet Model with Semantic Segmentation Pipeline Source: https://github.com/isl-org/open3d-ml/blob/main/docs/tutorial/notebook/train_ss_model_using_pytorch.rst Initialize and train the RandLANet model for semantic segmentation using the SemanticKITTI dataset. This involves setting up the model, pipeline, and running the training process. ```python #Training Semantic Segmentation Model using PyTorch #Import torch and the model to use for training import open3d.ml.torch as ml3d from open3d.ml.torch.models import RandLANet from open3d.ml.torch.pipelines import SemanticSegmentation #Read a dataset by specifying the path. We are also providing the cache directory and training split. dataset = ml3d.datasets.SemanticKITTI(dataset_path='../datasets/', cache_dir='./logs/cache',training_split=['00', '01', '02', '03', '04', '05', '06', '07', '09', '10']) #Initialize the RandLANet model with three layers. model = RandLANet(dim_input=3) pipeline = SemanticSegmentation(model=model, dataset=dataset, max_epoch=100) #Run the training pipeline.run_train() ``` -------------------------------- ### Initialize PointRCNN for RPN and RCNN modes Source: https://context7.com/isl-org/open3d-ml/llms.txt Instantiate the PointRCNN model for either the Region Proposal Network (RPN) or the RCNN stage. For RCNN, a trained RPN checkpoint is required. ```python model = PointRCNN( name='PointRCNN', mode='RPN', ckpt_path=None, ) model_rcnn = PointRCNN( name='PointRCNN', mode='RCNN', ckpt_path='./logs/checkpoint/ckpt_00100.pth', ) ``` -------------------------------- ### Read and Visualize SemanticKITTI Dataset Source: https://github.com/isl-org/open3d-ml/blob/main/README.md Constructs a SemanticKITTI dataset object, retrieves a specific split, and prints attributes and data shapes. It also visualizes the first 100 frames of the dataset. ```python import open3d.ml.torch as ml3d # or open3d.ml.tf as ml3d # construct a dataset by specifying dataset_path dataset = ml3d.datasets.SemanticKITTI(dataset_path='/path/to/SemanticKITTI/') # get the 'all' split that combines training, validation and test set all_split = dataset.get_split('all') # print the attributes of the first datum print(all_split.get_attr(0)) # print the shape of the first point cloud print(all_split.get_data(0)['point'].shape) # show the first 100 frames using the visualizer vis = ml3d.vis.Visualizer() vis.visualize_dataset(dataset, 'all', indices=range(100)) ``` -------------------------------- ### Visualize Model Predictions Side-by-Side Source: https://context7.com/isl-org/open3d-ml/llms.txt Combines pipeline inference results with the visualizer to compare ground truth and predictions. Requires a trained model checkpoint and dataset. ```python import os import numpy as np from ml3d.vis import Visualizer, LabelLUT from ml3d.datasets import SemanticKITTI from ml3d.torch.models import RandLANet from ml3d.torch.pipelines import SemanticSegmentation kitti_labels = SemanticKITTI.get_label_to_names() v = Visualizer() lut = LabelLUT() for val in sorted(kitti_labels): lut.add_label(kitti_labels[val], val) v.set_lut("labels", lut) v.set_lut("pred", lut) ckpt_path = "./logs/randlanet_semantickitti.pth" model = RandLANet(ckpt_path=ckpt_path) pipeline = SemanticSegmentation(model) pipeline.load_ckpt(ckpt_path) dataset = SemanticKITTI(dataset_path="/data/SemanticKITTI") test_split = dataset.get_split("test") data = test_split.get_data(0) result = pipeline.run_inference(data) pred_labels = (result['predict_labels'] + 1).astype(np.int32) vis_data = [{ "name": "frame_0", "points": data['point'], # (N, 3) "labels": data['label'], # ground truth "pred": pred_labels, # model prediction }] v.visualize(vis_data) ``` -------------------------------- ### Semantic Segmentation CLI (TensorFlow) Source: https://context7.com/isl-org/open3d-ml/llms.txt Command-line interface equivalent for running the semantic segmentation pipeline with TensorFlow backend. ```bash # python scripts/run_pipeline.py tf \ # -c ml3d/configs/randlanet_semantickitti.yml \ # --dataset.dataset_path /data/SemanticKITTI \ # --pipeline SemanticSegmentation ```