### Run MinkowskiEngine Semantic Segmentation Example Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/quick_start.md Clones the MinkowskiEngine repository, navigates into it, and executes an example script for indoor semantic segmentation. This example downloads pretrained weights and visualizes 3D scene segmentation results. ```bash git clone https://github.com/NVIDIA/MinkowskiEngine.git cd MinkowskiEngine python -m examples.indoor ``` -------------------------------- ### Install MinkowskiEngine via pip Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/quick_start.md Installs the MinkowskiEngine Python package from PyPI using pip. This command updates the package if it's already installed. ```bash pip3 install -U MinkowskiEngine ``` -------------------------------- ### Install Latest MinkowskiEngine from Git Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/quick_start.md Installs the latest development version of MinkowskiEngine directly from its GitHub repository using pip. This command updates the package if it's already installed. ```bash pip3 install -U git+https://github.com/NVIDIA/MinkowskiEngine ``` -------------------------------- ### Install MKL and Compile MinkowskiEngine with MKL BLAS Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/quick_start.md Installs Intel MKL (Math Kernel Library) and its includes via conda, then compiles MinkowskiEngine to specifically use MKL as its BLAS (Basic Linear Algebra Subprograms) library. This optimizes performance on Intel CPUs. ```bash conda install -c intel mkl mkl-include python setup.py install --blas=mkl ``` -------------------------------- ### Compile MinkowskiEngine with Specific BLAS (OpenBLAS) Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/quick_start.md Navigates into the MinkowskiEngine directory and compiles the library, explicitly specifying OpenBLAS as the BLAS (Basic Linear Algebra Subprograms) implementation to use. This allows users to choose their preferred BLAS library. ```bash cd MinkowskiEngine python setup.py install --blas=openblas ``` -------------------------------- ### Compile MinkowskiEngine for CPU Only Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/quick_start.md Clones the MinkowskiEngine repository and compiles it specifically for CPU-only usage, bypassing CUDA requirements. This is useful for environments without a compatible GPU. ```bash git clone https://github.com/NVIDIA/MinkowskiEngine.git cd MinkowskiEngine python setup.py install --cpu_only ``` -------------------------------- ### Run MinkowskiEngine Indoor Segmentation Example Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/demo/segmentation.rst Provides the shell commands to navigate to the MinkowskiEngine project directory and execute the indoor semantic segmentation example script. ```shell cd /path/to/MinkowskiEngine python -m examples.indoor ``` -------------------------------- ### Compile MinkowskiEngine with Single-Threaded Make Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/issues.md Instructions to compile MinkowskiEngine using a single-threaded `make` command, followed by `python setup.py install`. This is useful for environments with limited memory to prevent Out-Of-Memory errors during compilation. ```bash cd /path/to/MinkowskiEngine make # single threaded compilation python setup.py install ``` -------------------------------- ### Install MinkowskiEngine for Testing Source: https://github.com/nvidia/minkowskiengine/blob/master/tests/cpp/README.md This command prepares the build environment by removing previous builds, sets the C++ compiler to g++, and then installs the MinkowskiEngine project. The optional '' argument can be used to target specific test configurations or dependencies during installation. ```bash rm -rf build; CXX=g++; python setup.py install ``` -------------------------------- ### Verify CUDA_HOME and CUDA Installation Paths Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/issues.md Commands to check the currently set CUDA_HOME environment variable and list the contents of the CUDA installation directory to identify potential path mismatches or incorrect symbolic links. ```bash $ echo $CUDA_HOME /usr/local/cuda $ ls -al $CUDA_HOME ..... /usr/local/cuda -> /usr/local/cuda-10.2 $ ls /usr/local/ bin cuda cuda-10.2 cuda-11.0 ... ``` -------------------------------- ### Full Conda Environment Setup and MinkowskiEngine Installation with Specific CUDA Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/issues.md Comprehensive steps to create a new Conda environment, install dependencies including PyTorch with a specified CUDA toolkit version, and then install MinkowskiEngine. This addresses CUDA version mismatch issues by ensuring all components use compatible CUDA versions. ```bash conda create -n py3-mink-2 python=3.7 anaconda conda activate py3-mink-2 conda install openblas numpy conda install pytorch torchvision cudatoolkit=10.1 -c pytorch # Make sure to use the correct cudatoolkit version cd /path/to/MinkowskiEngine conda activate py3-mink-2 make clean python setup.py install --force ``` -------------------------------- ### Run Completion Example (Minkowski Engine) Source: https://github.com/nvidia/minkowskiengine/blob/master/README.md Execute the 3D completion example provided with the Minkowski Engine. This command runs a Python module demonstrating 3D shape completion from partial input. ```shell python -m examples.completion ``` -------------------------------- ### System Python Installation for MinkowskiEngine Source: https://github.com/nvidia/minkowskiengine/blob/master/README.md Installs MinkowskiEngine using the system's Python environment. This involves installing necessary system packages, ensuring pip is available, installing PyTorch and other Python requirements, and then cloning and installing MinkowskiEngine, with an optional command to specify BLAS, CXX, and CUDA_HOME. ```bash # install system requirements sudo apt install build-essential python3-dev libopenblas-dev # Skip if you already have pip installed on your python3 curl https://bootstrap.pypa.io/get-pip.py | python3 # Get pip and install python requirements python3 -m pip install torch numpy ninja git clone https://github.com/NVIDIA/MinkowskiEngine.git cd MinkowskiEngine python setup.py install ``` ```bash # To specify blas, CXX, CUDA_HOME and force CUDA installation, use the following command export CXX=c++; export CUDA_HOME=/usr/local/cuda-11.1; python setup.py install --blas=openblas --force_cuda ``` -------------------------------- ### Run ScanNet Semantic Segmentation Example Source: https://github.com/nvidia/minkowskiengine/blob/master/examples/README.md Executes the indoor semantic segmentation example for the ScanNet dataset using the Minkowski Engine. This command initiates the process for training or evaluating the segmentation model. ```python python -m examples.indoor ``` -------------------------------- ### Install Sphinx Documentation Dependencies Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/README.md Installs the required Python packages for building Sphinx documentation, including `recommonmark` for Markdown support, `sphinx` itself, `sphinx_rtd_theme` for styling, and `sphinx_markdown_tables` for table rendering. ```Shell pip install -U recommonmark sphinx sphinx_rtd_theme sphinx_markdown_tables ``` -------------------------------- ### Verify MinkowskiEngine Docker Installation Source: https://github.com/nvidia/minkowskiengine/blob/master/README.md Runs the previously built 'minkowski_engine' Docker image and executes a Python command inside the container to import MinkowskiEngine and print its version, confirming successful installation and accessibility. ```bash docker run MinkowskiEngine python3 -c "import MinkowskiEngine; print(MinkowskiEngine.__version__)" ``` -------------------------------- ### Train 3D Reconstruction Network Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/demo/sparse_tensor_reconstruction.rst This command line snippet demonstrates how to initiate the training process for the 3D sparsity pattern reconstruction network. Executing this command from the Minkowski Engine root directory will start the training loop, utilizing the example script provided. ```bash python -m examples.reconstruction --train ``` -------------------------------- ### Install MinkowskiEngine in New Conda Environment Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/issues.md Follow-up steps to install MinkowskiEngine within a newly created and activated Conda environment, including cleaning previous builds and forcing reinstallation. This ensures a fresh build against the new environment's dependencies. ```bash cd /path/to/MinkowskiEngine conda activate py3-mink-2 make clean python setup.py install --force ``` -------------------------------- ### Run Reconstruction Example (Minkowski Engine) Source: https://github.com/nvidia/minkowskiengine/blob/master/README.md Execute the 3D reconstruction example provided with the Minkowski Engine. This command runs a Python module demonstrating 3D shape reconstruction from sparse input. ```shell python -m examples.reconstruction ``` -------------------------------- ### Run Semantic Segmentation Example (Minkowski Engine) Source: https://github.com/nvidia/minkowskiengine/blob/master/README.md Execute the semantic segmentation example provided with the Minkowski Engine. This command runs a Python module demonstrating 3D semantic segmentation, typically on indoor scenes. ```shell python -m examples.indoor ``` -------------------------------- ### Run ModelNet40 Classification Example in Python Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/demo/modelnet40_classification.rst This command demonstrates how to execute the ModelNet40 classification example provided with MinkowskiEngine. It specifies the batch size and statistics frequency for the training run, allowing users to quickly test the framework. ```bash python -m examples.modelnet40 --batch_size 128 --stat_freq 100 ``` -------------------------------- ### Set CUDA_HOME and Install MinkowskiEngine (Default Path) Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/issues.md Explicitly sets CUDA_HOME to the default `/usr/local/cuda` path before installing MinkowskiEngine. This is useful when `.bashrc` modifications or other environment settings cause issues with the default CUDA path. ```bash export CUDA_HOME=/usr/local/cuda; python setup.py install ``` -------------------------------- ### Example: Run Specific Coordinate Map Key Test Source: https://github.com/nvidia/minkowskiengine/blob/master/tests/cpp/README.md An illustrative example demonstrating how to run a particular unit test named 'coordinate_map_key_test' using the Python unittest framework. ```bash python -m unittest coordinate_map_key_test ``` -------------------------------- ### Install MinkowskiEngine via Pip with Options Source: https://github.com/nvidia/minkowskiengine/blob/master/README.md Installs MinkowskiEngine using pip directly from the GitHub repository. This command includes commented-out options for forcing CUDA installation, enabling CPU-only mode, or specifying a BLAS library like OpenBLAS. ```bash pip install -U git+https://github.com/NVIDIA/MinkowskiEngine -v --no-deps \ # \ # uncomment the following line if you want to force cuda installation # --install-option="--force_cuda" \ # \ # uncomment the following line if you want to force no cuda installation. force_cuda supercedes cpu_only # --install-option="--cpu_only" \ # \ # uncomment the following line to override to openblas, atlas, mkl, blas # --install-option="--blas=openblas" ``` -------------------------------- ### Set CUDA_HOME and Install MinkowskiEngine (Specific Version) Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/issues.md Sets the CUDA_HOME environment variable to a specific CUDA version (e.g., 10.2) before installing MinkowskiEngine using `setup.py`. This resolves compilation issues related to incorrect CUDA paths. ```bash export CUDA_HOME=/usr/local/cuda-10.2; python setup.py install ``` -------------------------------- ### Install Minkowski Engine with Pip Source: https://github.com/nvidia/minkowskiengine/blob/master/README.md This snippet provides the commands to install the Minkowski Engine using pip. It first installs essential build tools, Python development headers, and OpenBLAS, followed by PyTorch and Ninja, and finally the Minkowski Engine itself from PyPI, configured to use OpenBLAS for optimized BLAS operations. ```bash sudo apt install build-essential python3-dev libopenblas-dev pip install torch ninja pip install -U MinkowskiEngine --install-option="--blas=openblas" -v --no-deps ``` -------------------------------- ### Run ModelNet40 Classification Examples Source: https://github.com/nvidia/minkowskiengine/blob/master/examples/README.md Demonstrates how to run different ModelNet40 classification models using Python, including PyTorch PointNet and MinkowskiEngine variants like MinkPointNet and MinkFCNN. These commands execute the respective training or inference scripts. ```python python -m examples.classification_modelnet40 --network pointnet # torch PointNet python -m examples.classification_modelnet40 --network minkpointnet # MinkowskiEngine PointNet python -m examples.classification_modelnet40 --network minkfcnn # MinkowskiEngine FCNN ``` -------------------------------- ### Install CUDA 11.1 and MinkowskiEngine with Specific CUDA Home Source: https://github.com/nvidia/minkowskiengine/blob/master/README.md This Bash snippet provides commands to download and silently install the CUDA Toolkit 11.1. It then demonstrates how to install MinkowskiEngine using pip, explicitly setting the `CUDA_HOME` environment variable to the newly installed CUDA path, ensuring the correct CUDA version is used for compilation. ```bash wget https://developer.download.nvidia.com/compute/cuda/11.1.1/local_installers/cuda_11.1.1_455.32.00_linux.run sudo sh cuda_11.1.1_455.32.00_linux.run --toolkit --silent --override # Install MinkowskiEngine with CUDA 11.1 export CUDA_HOME=/usr/local/cuda-11.1; pip install MinkowskiEngine -v --no-deps ``` -------------------------------- ### Anaconda Installation for MinkowskiEngine (CUDA 10.2) Source: https://github.com/nvidia/minkowskiengine/blob/master/README.md Sets up an Anaconda environment for MinkowskiEngine with CUDA 10.2. This involves installing GCC 7, creating a new conda environment, installing PyTorch with CUDA 10.2, and then installing MinkowskiEngine either via pip or by building from a local clone. ```bash sudo apt install g++-7 # For CUDA 10.2, must use GCC < 8 # Make sure `g++-7 --version` is at least 7.4.0 conda create -n py3-mink python=3.8 conda activate py3-mink conda install openblas-devel -c anaconda conda install pytorch=1.9.0 torchvision cudatoolkit=10.2 -c pytorch -c nvidia # Install MinkowskiEngine export CXX=g++-7 # Uncomment the following line to specify the cuda home. Make sure `$CUDA_HOME/nvcc --version` is 10.2 # export CUDA_HOME=/usr/local/cuda-10.2 pip install -U git+https://github.com/NVIDIA/MinkowskiEngine -v --no-deps --install-option="--blas_include_dirs=${CONDA_PREFIX}/include" --install-option="--blas=openblas" ``` ```bash git clone https://github.com/NVIDIA/MinkowskiEngine.git cd MinkowskiEngine export CXX=g++-7 python setup.py install --blas_include_dirs=${CONDA_PREFIX}/include --blas=openblas ``` -------------------------------- ### Execute MinkowskiEngine Training Script from Command Line Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/demo/training.rst This shell command executes the main training script for the MinkowskiEngine example. It uses the Python module execution flag (`-m`) to run the `training.py` script located within the `examples` package, initiating the training process as configured in the script. ```shell $ python -m examples.training ``` -------------------------------- ### Run Classification Example (Minkowski Engine ModelNet40) Source: https://github.com/nvidia/minkowskiengine/blob/master/README.md Execute the classification example using the Minkowski Engine, specifically tailored for the ModelNet40 dataset. This command runs a Python module demonstrating 3D object classification. ```shell python -m examples.classification_modelnet40 ``` -------------------------------- ### MinkowskiEngine SparseTensor Initialization Syntax Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/migration_05.md This snippet illustrates the SparseTensor constructor syntax in both Minkowski Engine v0.4 and v0.5. It shows that the basic initialization arguments for feats, coords, and D remain consistent across versions. ```python # 0.4 ME.SparseTensor(feats=feats, coords=coords, D=3) # 0.5 ME.SparseTensor(feats=feats, coords=coords, D=3) ``` -------------------------------- ### Install Minkowski Engine from Latest Source via Pip Source: https://github.com/nvidia/minkowskiengine/blob/master/README.md This optional command allows installing the Minkowski Engine directly from its GitHub repository's latest source using pip. It's useful for developers who need the most up-to-date version, bypassing pre-built packages and their dependencies. ```bash # For pip installation from the latest source # pip install -U git+https://github.com/NVIDIA/MinkowskiEngine --no-deps ``` -------------------------------- ### Anaconda Installation for MinkowskiEngine (CUDA 11.X) Source: https://github.com/nvidia/minkowskiengine/blob/master/README.md Configures an Anaconda environment for MinkowskiEngine with CUDA 11.x. This process includes creating a new conda environment, installing PyTorch with CUDA 11.1, and then installing MinkowskiEngine either through pip or by building from a local repository clone. ```bash conda create -n py3-mink python=3.8 conda activate py3-mink conda install openblas-devel -c anaconda conda install pytorch=1.9.0 torchvision cudatoolkit=11.1 -c pytorch -c nvidia # Install MinkowskiEngine # Uncomment the following line to specify the cuda home. Make sure `$CUDA_HOME/nvcc --version` is 11.X # export CUDA_HOME=/usr/local/cuda-11.1 pip install -U git+https://github.com/NVIDIA/MinkowskiEngine -v --no-deps --install-option="--blas_include_dirs=${CONDA_PREFIX}/include" --install-option="--blas=openblas" ``` ```bash git clone https://github.com/NVIDIA/MinkowskiEngine.git cd MinkowskiEngine python setup.py install --blas_include_dirs=${CONDA_PREFIX}/include --blas=openblas ``` -------------------------------- ### Create New Conda Environment for MinkowskiEngine Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/issues.md Steps to create a new Conda virtual environment with Python 3.7, activate it, and install essential dependencies like OpenBLAS, NumPy, PyTorch, and torchvision. This can resolve persistent compilation issues by providing a clean environment. ```bash conda create -n py3-mink-2 python=3.7 anaconda conda activate py3-mink-2 conda install openblas numpy conda install pytorch torchvision -c pytorch ``` -------------------------------- ### Visualize 3D Reconstruction Predictions Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/demo/sparse_tensor_reconstruction.rst This command line snippet shows how to run the 3D reconstruction example to visualize network predictions or test a pretrained model. When executed, it will display the target 3D shape alongside the reconstructed prediction, allowing for visual comparison. ```bash python -m examples.reconstruction ``` -------------------------------- ### Specify C++ Compiler for Minkowski Engine Setup Source: https://github.com/nvidia/minkowskiengine/blob/master/README.md This snippet shows how to optionally set the C++ compiler for the Minkowski Engine's setup script by exporting the CXX environment variable. This can be useful for troubleshooting compilation issues or when a specific compiler version is required. ```bash # Uncomment some options if things don't work # export CXX=c++; # set this if you want to use a different C++ compiler ``` -------------------------------- ### Initialize Sparse Tensor from Continuous Coordinates (Python) Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/tutorial/sparse_tensor_basic.rst This example demonstrates initializing a `MinkowskiEngine.SparseTensor` from continuous coordinates. It illustrates how to quantize continuous coordinates to an integer grid using `ME.utils.batched_coordinates` and how to handle feature averaging for points falling into the same discrete coordinate using `quantization_mode`. ```python sinput = ME.SparseTensor( features=torch.from_numpy(colors), # Convert to a tensor coordinates=ME.utils.batched_coordinates([coordinates / voxel_size]), # coordinates must be defined in a integer grid. If the scale quantization_mode=ME.SparseTensorQuantizationMode.UNWEIGHTED_AVERAGE # when used with continuous coordinates, average features in the same coordinate ) logits = model(sinput).slice(sinput).F ``` -------------------------------- ### Create Batched MinkowskiEngine TensorField Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/demo/segmentation.rst Illustrates the creation of a batched `MinkowskiEngine.TensorField` from point cloud data. It shows how to pass features (colors), batched and quantized coordinates, and specify quantization and algorithm modes for efficient sparse tensor processing on a given device. ```python # Create a batch, this process is done in a data loader during training in parallel. in_field = ME.TensorField( features=torch.from_numpy(colors).float(), coordinates=ME.utils.batched_coordinates([coords / voxel_size], dtype=torch.float32), quantization_mode=ME.SparseTensorQuantizationMode.UNWEIGHTED_AVERAGE, minkowski_algorithm=ME.MinkowskiAlgorithm.SPEED_OPTIMIZED, device=device, ) ``` -------------------------------- ### MinkowskiEngine UNet Training Loop Implementation Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/demo/training.rst This Python snippet demonstrates the setup and execution of a training loop for a MinkowskiEngine UNet model. It initializes the neural network, defines the optimizer (SGD) and loss criterion (CrossEntropyLoss), and configures the data loader. The main loop iterates through epochs and batches, performing forward and backward passes, optimizing model parameters, and printing training progress. A key consideration is setting `num_workers=1` for the DataLoader due to `MinkowskiEngine.CoordsManager` limitations with multiprocessing. ```python # Binary classification net = UNet( 2, # in nchannel 2, # out_nchannel D=2) optimizer = optim.SGD( net.parameters(), lr=config.lr, momentum=config.momentum, weight_decay=config.weight_decay) criterion = torch.nn.CrossEntropyLoss(ignore_index=-100) # Dataset, data loader train_dataset = RandomLineDataset(noise_type='gaussian') train_dataloader = DataLoader( train_dataset, batch_size=config.batch_size, collate_fn=collation_fn, num_workers=1) for epoch in range(config.max_epochs): train_iter = iter(train_dataloader) # Training net.train() for i, data in enumerate(train_iter): coords, feats, labels = data out = net(ME.SparseTensor(feats, coords)) optimizer.zero_grad() loss = criterion(out.F.squeeze(), labels.long()) loss.backward() optimizer.step() accum_loss += loss.item() accum_iter += 1 tot_iter += 1 if tot_iter % 10 == 0 or tot_iter == 1: print( f'Iter: {tot_iter}, Epoch: {epoch}, Loss: {accum_loss / accum_iter}' ) accum_loss, accum_iter = 0, 0 ``` -------------------------------- ### Specify CUDA Architecture List for PyTorch Installation Source: https://github.com/nvidia/minkowskiengine/blob/master/README.md This Bash command exports the `TORCH_CUDA_ARCH_LIST` environment variable, specifying a comprehensive list of CUDA compute capabilities. This is crucial for ensuring PyTorch compiles correctly for your specific GPU architecture, especially when the default list might be insufficient, and is followed by a `setup.py install` command. ```bash export TORCH_CUDA_ARCH_LIST="5.2 6.0 6.1 7.0 7.5 8.0 8.6+PTX"; python setup.py install --force_cuda ``` -------------------------------- ### Force Recompile MinkowskiEngine After Upgrade Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/issues.md Commands to clean previous build artifacts and force a complete reinstallation of MinkowskiEngine. This is recommended when encountering undefined symbol errors or `thrust::system::system_error` after upgrading the library, PyTorch, or CUDA. ```bash cd /path/to/MinkowskiEngine make clean python setup.py install --force ``` -------------------------------- ### Perform MinkowskiEngine Model Inference and Slice Output Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/demo/segmentation.rst Demonstrates the process of feeding a `MinkowskiEngine.TensorField` into a neural network model. It covers converting the `TensorField` to a sparse tensor, passing it through the `model`, and then slicing the output sparse tensor to align predictions with the original input field. ```python # Convert to a sparse tensor sinput = in_field.sparse() # Output sparse tensor soutput = model(sinput) # get the prediction on the input tensor field out_field = soutput.slice(in_field) ``` -------------------------------- ### MinkowskiEngine CoordsManager.initialize Method API (v0.4.x) Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/migration_05.md Documents the initialize method of the CoordsManager class from Minkowski Engine v0.4.x. It details the method signature, parameters (coords, coords_key, force_creation, force_remap, allow_duplicate_coords, return_inverse), and its return type (torch.LongTensor). This method is used for setting up coordinate maps. ```APIDOC def initialize(self, coords: torch.IntTensor, coords_key: CoordsKey, force_creation: bool = False, force_remap: bool = False, allow_duplicate_coords: bool = False, return_inverse: bool = False) -> torch.LongTensor: ``` -------------------------------- ### Initialize MinkowskiEngine Single Convolution Layer Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/benchmark.md This Python snippet demonstrates the initialization of a `MinkowskiConvolution` layer from the MinkowskiEngine library. It configures a 3D convolution with specific input/output channels, kernel size, stride, dilation, and disables bias, serving as the setup for single-layer performance benchmarks. ```python import MinkowskiEngine as ME conv = ME.MinkowskiConvolution( in_channels=3, out_channels=32, kernel_size=7, stride=1, dilation=1, bias=False, dimension=3) ``` -------------------------------- ### Load 3D Point Cloud Data with Open3D Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/demo/segmentation.rst Defines a Python function `load_file` that uses the Open3D library to read a point cloud file, extracting and returning its coordinates and colors as NumPy arrays, along with the Open3D point cloud object. ```python def load_file(file_name): pcd = o3d.read_point_cloud(file_name) coords = np.array(pcd.points) colors = np.array(pcd.colors) return coords, colors, pcd ``` -------------------------------- ### Define MinkowskiEngine Collation Function and DataLoader Setup Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/demo/multigpu.md This Python code provides `minkowski_collate_fn`, a custom collation function essential for batching data into `MinkowskiEngine.SparseTensor` format by merging coordinates, features, and labels. It also illustrates how to instantiate a `torch.utils.data.DataLoader` using this custom function with a `DummyDataset` for efficient batch processing. ```python def minkowski_collate_fn(list_data): r""" Collation function for MinkowskiEngine.SparseTensor that creates batched cooordinates given a list of dictionaries. """ coordinates_batch, features_batch, labels_batch = ME.utils.sparse_collate( [d["coordinates"] for d in list_data], [d["features"] for d in list_data], [d["labels"] for d in list_data], dtype=torch.float32, ) return { "coordinates": coordinates_batch, "features": features_batch, "labels": labels_batch, } ... dataset = torch.utils.data.DataLoader( DummyDataset("train", voxel_size=voxel_size), batch_size=batch_size, collate_fn=minkowski_collate_fn, shuffle=True, ) ``` -------------------------------- ### Initialize Google Analytics Data Layer and Tracking Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/_templates/layout.html This JavaScript code initializes the Google Analytics data layer and configures a gtag for basic page view tracking. It's a standard and essential setup for integrating Google Analytics into a web page, enabling the collection of valuable analytics data on user behavior. ```JavaScript window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-43980256-3'); ``` -------------------------------- ### Install PyTorch with Specific CUDA Toolkit Version Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/issues.md Installs PyTorch and torchvision along with a specific CUDA toolkit version (e.g., 10.1) into a Conda environment. This is crucial for resolving CUDA version mismatch errors when compiling MinkowskiEngine. ```bash conda install pytorch torchvision cudatoolkit=10.1 -c pytorch ``` -------------------------------- ### Build Sphinx HTML Documentation Website Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/README.md This command prepares the `README.md` file as an `overview.md` for inclusion in the documentation and then executes `make html` to compile all Sphinx documentation into a static HTML website. The generated website will be located in the `_build/html` directory. ```Shell cp ../README.md overview.md; make html ``` -------------------------------- ### Diagnose CUDA Compilation Segmentation Fault Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/issues.md This snippet shows a typical error message indicating a segmentation fault during NVCC compilation, often due to incorrect CUDA setup or environment configuration. ```bash NVCC ... Segmentation fault ``` -------------------------------- ### Build MinkowskiEngine Docker Image Source: https://github.com/nvidia/minkowskiengine/blob/master/README.md Clones the MinkowskiEngine repository from GitHub and then builds a Docker image named 'minkowski_engine' using the Dockerfile located within the cloned directory. ```bash git clone https://github.com/NVIDIA/MinkowskiEngine cd MinkowskiEngine docker build -t minkowski_engine docker ``` -------------------------------- ### Set CUDA_HOME Automatically via nvcc Path Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/issues.md Automatically determines the CUDA_HOME path based on the location of the `nvcc` compiler and then proceeds with MinkowskiEngine installation. This is a robust way to ensure the correct CUDA path is used. ```bash export CUDA_HOME=$(dirname $(dirname $(which nvcc))); python setup.py install ``` -------------------------------- ### Execute Forward Pass and Calculate Loss with MinkowskiEngine Network Source: https://github.com/nvidia/minkowskiengine/blob/master/README.md This Python snippet demonstrates the usage of the `ExampleNetwork` by initializing it and performing a forward pass with a `ME.SparseTensor` input. It also shows how to calculate a cross-entropy loss using the network's output, preparing for a backward pass in a training loop. ```python # loss and network criterion = nn.CrossEntropyLoss() net = ExampleNetwork(in_feat=3, out_feat=5, D=2) print(net) # a data loader must return a tuple of coords, features, and labels. coords, feat, label = data_loader() input = ME.SparseTensor(feat, coordinates=coords) # Forward output = net(input) # Loss loss = criterion(output.F, label) ``` -------------------------------- ### MinkowskiEngine.MinkowskiUnion Class API Reference Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/union.rst API documentation for the `MinkowskiEngine.MinkowskiUnion` class, detailing its constructor (`__init__`) and the `forward` method. This class is part of the MinkowskiEngine library. ```APIDOC class MinkowskiEngine.MinkowskiUnion: __init__ forward ``` -------------------------------- ### Basic MinkowskiEngine Import and Quantization Utility Source: https://github.com/nvidia/minkowskiengine/blob/master/README.md Demonstrates the initial steps to use MinkowskiEngine by importing the library and referencing its `sparse_quantize` utility function, which is used for voxelizing or quantizing spatial data into a sparse tensor. ```python import MinkowskiEngine # Example of a utility function for quantization MinkowskiEngine.utils.sparse_quantize ``` -------------------------------- ### Implement `DummyDataset.__getitem__` for Point Cloud Processing Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/demo/multigpu.md This Python code defines the `__getitem__` method for a `DummyDataset` class. It demonstrates reading a point cloud using `o3d.io.read_point_cloud`, quantizing coordinates and features with `ME.utils.sparse_quantize`, and returning them along with dummy labels, preparing data for MinkowskiEngine sparse tensors. ```python class DummyDataset(Dataset): ... def __getitem__(self, i): filename = self.filenames[i] pcd = o3d.io.read_point_cloud(filename) quantized_coords, feats = ME.utils.sparse_quantize( np.array(pcd.points, dtype=np.float32), np.array(pcd.colors, dtype=np.float32), quantization_size=self.voxel_size, ) random_labels = torch.zeros(len(feats)) return { "coordinates": quantized_coords, "features": feats, "labels": random_labels, } ``` -------------------------------- ### MinkowskiBroadcastAddition Class API Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/broadcast.rst Documents the MinkowskiBroadcastAddition class from MinkowskiEngine, detailing its constructor (`__init__`) and forward pass method for broadcasting operations. ```APIDOC MinkowskiEngine.MinkowskiBroadcastAddition: __init__() forward() ``` -------------------------------- ### MinkowskiEngine.MinkowskiPruning Class API Reference Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/pruning.rst API documentation for the `MinkowskiEngine.MinkowskiPruning` class, outlining its structure and the `__init__` method. This class is part of the MinkowskiEngine library. ```APIDOC MinkowskiEngine.MinkowskiPruning Class Description: A class for pruning operations within the MinkowskiEngine. Members: __init__() Description: Constructor for the MinkowskiPruning class. ``` -------------------------------- ### MinkowskiBroadcast Class API Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/broadcast.rst Documents the general MinkowskiBroadcast class from MinkowskiEngine, detailing its constructor (`__init__`) and forward pass method for broadcasting operations. ```APIDOC MinkowskiEngine.MinkowskiBroadcast: __init__() forward() ``` -------------------------------- ### Migrating CoordsManager to CoordinateManager Initialization Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/migration_05.md Illustrates the class name change for the coordinate management system. In v0.4.x, CoordsManager was used, which has been updated to CoordinateManager in v0.5.x for initialization. ```python # 0.4.x manager = CoordsManager(D=3) # 0.5.x manager = CoordinateManager(D=3) ``` -------------------------------- ### MinkowskiConvolution Bias Argument Renaming Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/migration_05.md Demonstrates the change in the argument name for specifying bias in ME.MinkowskiConvolution. In v0.4, has_bias was used, which has been renamed to bias in v0.5 for clarity and consistency. ```python # 0.4 ME.MinkowskiConvolution(..., has_bias=True) # 0.5 ME.MinkowskiConvolution(..., bias=True) ``` -------------------------------- ### MinkowskiEngine RegionType Enum Value Update Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/migration_05.md Shows the update to the RegionType enumeration member. The HYPERCUBE value in v0.4 has been renamed to HYPER_CUBE in v0.5 to follow a more consistent naming convention. ```python # 0.4 RegionType.HYPERCUBE # 0.5 RegionType.HYPER_CUBE ``` -------------------------------- ### Generate Sphinx API Documentation from Modules Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/README.md This command first removes any existing `source` directory to ensure a clean generation, then uses `sphinx-apidoc` to automatically create reStructuredText files for API documentation from the project's modules. The generated files are placed in the `source/` directory. ```Shell rm -rf source && sphinx-apidoc -o source/ ../ ``` -------------------------------- ### Train Classification Model with MinkowskiEngine and PyTorch Loss Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/demo/interop.rst This Python code snippet illustrates a basic training loop for a classification model. It demonstrates how to initialize `torch.nn.CrossEntropyLoss`, prepare `MinkowskiEngine.SparseTensor` inputs, perform a forward pass through the network, extract features from the sparse tensor output, and compute the loss against ground truth labels. ```python criterion = nn.CrossEntropyLoss() for i in range(10): optimizer.zero_grad() # Get new data coords, feat, label = data_loader() input = ME.SparseTensor(features=feat, coordinates=coords, device=device) label = label.to(device) # Forward output = net(input) # Loss out_feats = output.F loss = criterion(out_feats, label) ``` -------------------------------- ### MinkowskiBroadcastMultiplication Class API Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/broadcast.rst Documents the MinkowskiBroadcastMultiplication class from MinkowskiEngine, detailing its constructor (`__init__`) and forward pass method for broadcasting operations. ```APIDOC MinkowskiEngine.MinkowskiBroadcastMultiplication: __init__() forward() ``` -------------------------------- ### MinkowskiBroadcastConcatenation Class API Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/broadcast.rst Documents the MinkowskiBroadcastConcatenation class from MinkowskiEngine, detailing its constructor (`__init__`) and forward pass method for broadcasting operations. ```APIDOC MinkowskiEngine.MinkowskiBroadcastConcatenation: __init__() forward() ``` -------------------------------- ### Configure PyTorch Lightning Optimizer for MinkowskiEngine Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/demo/multigpu.md Defines the `configure_optimizers` method for a PyTorch Lightning module, setting up the SGD optimizer with specified learning rate and weight decay for the model's parameters. This method is automatically called by PyTorch Lightning to prepare the optimizer for training. ```python def configure_optimizers(self): return SGD(self.model.parameters(), lr=self.lr, weight_decay=self.weight_decay) ``` -------------------------------- ### Clear GPU Cache During MinkowskiEngine Training Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/issues.md A Python code snippet demonstrating the use of `torch.cuda.empty_cache()` within a training loop. This function is essential for managing GPU memory when working with sparse tensors in MinkowskiEngine, preventing Out-Of-Memory errors due to dynamic memory allocation. ```python def training(...): ... sinput = ME.SparseTensor(...) loss = criterion(...) loss.backward() optimizer.step() ... torch.cuda.empty_cache() ``` -------------------------------- ### MinkowskiEngine Core API Reference Source: https://github.com/nvidia/minkowskiengine/blob/master/docs/coords.rst Comprehensive API documentation for fundamental components of the MinkowskiEngine, covering coordinate map keys, coordinate managers, GPU memory allocator types, and the function to set the GPU allocator. ```APIDOC MinkowskiEngine.CoordinateMapKey: Type: Class Description: Manages coordinate map keys. Methods: __init__(): Constructor for CoordinateMapKey. MinkowskiEngine.CoordinateManager: Type: Class Description: Manages coordinates within the MinkowskiEngine. Methods: __init__(): Constructor for CoordinateManager. MinkowskiEngine.GPUMemoryAllocatorType: Type: Class Description: Enumeration or type defining GPU memory allocator options. Members: All public members are documented. MinkowskiEngine.set_gpu_allocator: Type: Function Description: Sets the global GPU memory allocator for MinkowskiEngine operations. ```