A Python-based headless inference engine for TreeAIBox that performs wood/leaf classification on point cloud data using deep learning models.
- Headless operation - No GUI dependencies, runs on servers and clusters
- Multiple output formats - Create new fields or overwrite existing ones (e.g., alpha channel)
- PLY file support - Read and write point cloud data with colors, normals, and scalar fields
# Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtconda env create -f environment.yml
conda activate treeaiboxpython run_models_inference.py \
--input input.ply \
--model-path models/woodcls_branch_tls_segformer3D_112_4cm\(GPU6GB\).pth \
--wood-cls branch \
--output output.plyNote: --model-path is required and must point to a valid .pth model file.
# Write classification to alpha channel
python run_models_inference.py \
--input forest.ply \
--model-path models/woodcls_branch_tls_segformer3D_112_4cm\(GPU6GB\).pth \
--wood-cls branch \
--output-field alpha \
--output results.plypython run_models_inference.py \
--input forest.ply \
--model-path models/woodcls_branch_tls_segformer3D_112_4cm\(GPU6GB\).pth \
--wood-cls branch \
--no-gpu \
--output results.plypython run_models_inference.py \
-i input.ply \
--model-path models/woodcls_branch_tls_segformer3D_112_4cm\(GPU6GB\).pth \
-o output.ply \
--wood-cls branch \
--output-field alpha| Argument | Short | Type | Default | Description |
|---|---|---|---|---|
--input |
-i |
str | required | Input PLY file path |
--model-path |
str | required | Path to model file (.pth) |
|
--output |
-o |
str | output.ply |
Output PLY file path |
--wood-cls |
str | branch |
Classification type: branch or stem |
|
--output-field |
str | new field | Field name to overwrite with results (e.g., alpha, confidence) |
|
--use-gpu |
flag | True | Enable GPU acceleration | |
--no-gpu |
flag | False | Force CPU-only processing |
The model outputs two classes that are automatically remapped:
- 1 = Leaf
- 255 = Wood
These values are written to either:
- A new scalar field named
{wood_type}_classification(default) - An existing field you specify with
--output-field(overwrites)
TreeAIBox_Lite/
├── run_models_inference.py # Main inference script
├── mock_point_cloud.py # Point cloud data structures
├── requirements.txt # Pip dependencies
├── environment.yml # Conda environment
├── README.md # This file
├── models/ # Model files (.pth)
├── modules/
│ ├── filter/ # Wood classification modules
│ │ ├── componentFilter.py
│ │ ├── vox3DSegFormer.py
│ │ └── vox3DESegFormer.py
│ └── treeisonet/ # Tree isolation modules
├── forest.ply # Sample point cloud
└── model_zoo.json # Model configuration
python run_models_inference.py \
--input forest.ply \
--model-path models/woodcls_branch_tls_segformer3D_112_4cm\(GPU6GB\).pth \
--output classified.plypython run_models_inference.py \
--input forest.ply \
--model-path models/woodcls_branch_tls_segformer3D_112_4cm\(GPU6GB\).pth \
--wood-cls branch \
--output-field alpha \
--output forest_classified.plypython run_models_inference.py \
-i forest.ply \
--model-path "models/woodcls_branch_tls_segformer3D_112_4cm(GPU2GBDistilled).pth" \
--use-gpu \
-o results.plyMODEL="models/woodcls_branch_tls_segformer3D_112_4cm(GPU6GB).pth"
for file in *.ply; do
python run_models_inference.py \
--input "$file" \
--model-path "$MODEL" \
--no-gpu \
--output "classified_${file}"
doneThe following models are included in the models/ directory:
woodcls_branch_tls_segformer3D_112_4cm(GPU6GB).pth- Full model (6GB VRAM)woodcls_branch_tls_segformer3D_112_4cm(GPU2GBDistilled).pth- Distilled model (2GB VRAM)woodcls_branch_tls_esegformer3D_128_2.5cm(GPU3GB).pth- Efficient model (3GB VRAM)
woodcls_stem_tls_segformer3D_112_4cm_GPU12GB.pth- Full model (12GB VRAM)woodcls_stem_tls_segformer3D_112_20cm_GPU8GB.pth- Standard model (8GB VRAM)woodcls_stem_tls_esegformer3D_128_10cm(GPU3GB).pth- Efficient model (3GB VRAM)
Choose the model that fits your hardware constraints and use its full filename with --model-path.
- torch - PyTorch for model inference
- torchvision - Vision utilities
- torchaudio - Audio utilities
- numpy - Numerical computing
- plyfile - PLY file I/O
- timm - Transformer models
- numpy-indexed - Indexed array operations
- GPU (optional): NVIDIA GPU with CUDA 12.1 for accelerated processing
- CPU: CPU-only mode supported (slower)
- RAM: 8GB+ recommended for large point clouds
The output PLY file includes:
- Original point coordinates (x, y, z)
- Original colors (if present)
- Original normals (if present)
- All scalar fields including classification results
pip install -r requirements.txtTry forcing CPU mode:
python run_models_inference.py \
--input file.ply \
--model-path models/woodcls_branch_tls_segformer3D_112_4cm\(GPU6GB\).pth \
--no-gpu \
--output output.plyMake sure to specify the full path to the model file:
python run_models_inference.py \
--input file.ply \
--model-path models/woodcls_branch_tls_segformer3D_112_4cm\(GPU6GB\).pth \
--output output.plyAvailable models are in the ./models/ directory.
See project documentation for licensing information.