- Ubuntu 24.04
- Python 3.8
The point cloud is recursively partitioned using binary clustering.
Both standard KMeans and balanced KMeans were tested. The final implementation uses standard KMeans.
- Input mesh:
welsh-dragon-small-centered.stl - Number of levels: 10
- Output:
binary_level_{level}.vtk(10 files total)
Each level’s binary labels are stored in the "clusters" attribute of the .vtk file.
python generate_training_data.py \
--output_root ./dataset_normal \
--start_id 0 \
--num_samples 2000This step:
- samples 2000 random seeds
- generates random camera 6DoF poses
- applies rotation and translation to the mesh
- renders X-ray images
- produces corresponding masks and 10-bit binary codes
dataset/
├── sample_000000/
│ ├── xray.png
│ ├── mask.png
│ ├── mask.npy
│ ├── code_stack.npy
│ ├── packed_code.npy
│ ├── code_vis.png
│ └── sample_meta.json
├── sample_000001/
│ ├── xray.png
│ ├── mask.png
│ ├── mask.npy
│ ├── code_stack.npy
│ ├── packed_code.npy
│ ├── code_vis.png
│ └── sample_meta.json
...
-
xray.png
Input image to the neural network. -
mask.npy
(H, W)0= background1= object
-
code_stack.npy
(10, H, W)- contains 10 binary code channels
- only valid where
mask == 1 - background is all zeros
-
packed_code.npy
Encoded as:code = b0 + 2b1 + 4b2 + ... + 2^9 b9 -
code_vis.png
Visualization for quick sanity checking.
python train.py \
--data_root ./dataset_test \
--save_dir ./checkpoints \
--epochs 50 \
--batch_size 8 \
--lr 1e-3 \
--backbone resnet34python train.py \
--data_root ./dataset_normal \
--save_dir ./checkpoints \
--epochs 50 \
--batch_size 8 \
--lr 1e-3 \
--backbone resnet34 \
--alpha 1.0 \
--sigma 3.0 \
--momentum 0.9 \
--use_pred_mask_for_codepython train.py \
--data_root ./dataset_normal \
--save_dir ./checkpoints \
--epochs 50 \
--batch_size 8 \
--lr 3e-4 \
--backbone resnet34 \
--alpha 1.5 \
--sigma 5.0 \
--momentum 0.7 \
--use_pred_mask_for_code
python train_resnet_codebook.py \
--data_root ./dataset \
--save_dir ./checkpoints \
--epochs 50 \
--batch_size 8 \
--lr 1e-3 \
--backbone resnet18 \
--pretrainedAfter training, save_dir will contain:
history.json/history.csvbest_metrics.json— best epoch and corresponding metricslast.pth/best.pth— model checkpoints
python analyze_training_results.py \
--save_dir ./checkpoints \
--out_dir ./checkpoints/analysis- Binary codes are only meaningful inside object regions (
mask == 1). - Background pixels are always zero.
code_vis.pngis intended only for visualization, not training.
