KPConv-PyTorch
repository·master·Indexed 21 days ago
https://github.com/huguesthomas/kpconv-pytorchA PyTorch implementation of Kernel Point Convolution (KPConv), a flexible and deformable convolution operator for processing 3D point clouds based on the ICCV 2019 paper. The library includes support for object classification on ModelNet40 and scene segmentation on S3DIS and SemanticKitti datasets, along with tools for visualizing kernel deformations and using pretrained models.
What's inside kpconv-pytorch
- KPConv-PyTorch is a PyTorch implementation of Kernel Point Convolution (KPConv), a point convolution operator designed for point clouds. It is based on the ICCV 2019 paper 'KPConv: Flexible and Deformable Convolution for Point Clouds'.
Install KPConv-PyTorch
masterThe implementation has been tested on Ubuntu 18.04 and Windows 10. For detailed installation instructions, refer to theINSTALL.mdfile in the repository.Prepare S3DIS dataset for scene segmentation
masterTo perform scene segmentation, you must download and organize the S3DIS dataset.
- Download
Stanford3dDataset_v1.2.zip(4.8 GB) from the provided link. - Uncompress the file.
- Place the uncompressed data in a directory structure where it is accessible relative to your experiment folder. By default, the project expects the data at
../../Data/S3DISrelative toXXXX/Experiments/KPConv-PyTorch.
If you wish to use a different data location, you must modify the
self.pathvariable within theS3DISDatasetclass indatasets/S3DIS.py.# Example directory structure assumed by default: # XXXX/Data/S3DIS # XXXX/Experiments/KPConv-PyTorch/training_S3DIS.py- Download
Interactive controls for kernel deformation visualization
masterWhen the visualization window is open, use the following keyboard shortcuts and mouse actions to interact with the point clouds and kernels:
Keyboard Shortcuts
'b'/'n': Decrease or increase point size.'g'/'h': Navigate to the previous or next example in the current batch.'k': Toggle between the rigid kernel (original kernel point positions) and the deformed kernel (kernel point positions after shifts are applied).'z': Toggle the displayed points (input points, current layer points, or both).'0': Save the current example and the deformed kernel as.plyfiles.
Mouse Actions
- Left Click: Select a specific point to show the kernel at its location.
Window Management
- Exit Window: Closes the current view and computes the next batch of examples.
Prepare ModelNet40 data for object classification
masterTo perform object classification on ModelNet40, you must organize your data directory relative to your experiment folder.
- Download the regularly sampled clouds from ModelNet40: https://shapenet.cs.stanford.edu/media/modelnet40_normal_resampled.zip.
- Uncompress the data.
- Place the uncompressed data in
../../Data/ModelNet40(assuming your experiment folder is atXXXX/Experiments/KPConv-PyTorch).
If you need to use a different data location, modify the
self.pathvariable in theModelNet40Datasetclass withindatasets/ModelNet40.py.Plot training convergence logs
masterTraining results are saved in a
resultsfolder. Each training session creates a dated log folder containing loss values, validation metrics, and model checkpoints.To visualize the training progress, use
plot_convergence.py. You must follow the comments within the script to select the specific training log you wish to plot.python3 plot_convergence.pyInstall KPConv-PyTorch on Windows 10
masterTo set up KPConv-PyTorch on Windows 10, ensure you have CUDA and cuDNN installed. A tested configuration is PyTorch 1.4.0, CUDA 10.1, and cuDNN 7.5.
Follow these steps:
- Install PyTorch following the official PyTorch installation procedure.
- Install Python dependencies (e.g., via PyCharm venv or pip):
torchtorchvisionnumpyscikit-learnPyYAMLmatplotlib(for visualization)mayavi(for visualization)PyQt5(for visualization)
- Compile the C++ extension modules by executing the
.batfiles in thecpp_wrappersdirectory.
# Execute build scripts for C++ extensions cpp_wrappers\cpp_neighbors\build.bat cpp_wrappers\cpp_subsampling\build.batRun KPConv experiments
masterThe repository provides scripts and instructions for three main types of experiments located in the
doc/directory:- Object Classification: Instructions to train KP-CNN on the ModelNet40 dataset (
doc/object_classification_guide.md). - Scene Segmentation: Instructions to train KP-FCNN on the S3DIS dataset (
doc/scene_segmentation_guide.md). - SLAM Segmentation: Instructions to train KP-FCNN on the SemanticKitti dataset (
doc/slam_segmentation_guide.md).
- Object Classification: Instructions to train KP-CNN on the ModelNet40 dataset (
Train a model on ModelNet40
masterStart the training process by running the
training_ModelNet40.pyscript.This script uses a
ModelNet40Configsubclass (inherited fromConfiginutils/config.py). You can modify any parameter by editing this subclass.Note: The first time you run the script, it will precompute structures for the dataset, which may take some time.
python3 training_ModelNet40.pyVisualize kernel deformations
masterTo visualize kernel deformations, you must have a dataset and a pretrained model that utilizes deformable KPConv. The visualization is performed by running a script that executes a forward pass on a batch of test examples and displays them in an interactive window.
Run the following command to start the visualization:
python3 visualize_deformations.pyTrain the model on SemanticKitti
masterStart the training process by running the
training_SemanticKitti.pyscript.Configuration: You can modify training parameters by editing the
SemanticKittiConfigconfiguration subclass.Note: The first execution may take a significant amount of time as the script precomputes dataset structures.
python3 training_SemanticKitti.pyHow to use S3DIS pretrained models for testing
masterTo evaluate a pretrained S3DIS model using the provided scripts, follow these steps:
- Setup Files: Unzip the downloaded model weights and place the resulting folder inside your
resultsdirectory. - Configure Script: Open
test_any_model.pyand set thechosen_logvariable to the path of the folder you just placed inresults. - Execute Test: Run the test script via the command line:
python3 test_any_model.py - Monitor Progress: The script first evaluates performance on subsampled input clouds. After a few minutes, it automatically reprojects these results to the full (real) data to provide the final score.
- Retrieve Results: The script generates a folder at
test/<name-of-your-log>. This folder contains:- Predictions
- Potentials
- Probabilities per class
You can load these files into CloudCompare for visualization.
# Step 1: Place model in results/my_model_folder # Step 2: In test_any_model.py, set: # chosen_log = 'results/my_model_folder' # Step 3: Run python3 test_any_model.py- Setup Files: Unzip the downloaded model weights and place the resulting folder inside your