This repository implements a simple pipeline for plant–soil segmentation using simulated datasets generated in PyBullet and a deep‐learning segmentation model. It also supports applying a style‐transfer step (via an external repository) to improve domain adaptation.
.
├── config.yml
├── environment.yml
├── requirements.txt
├── pybullet
│ ├── generate_train_dataset.py
│ └── generate_test_dataset.py
└── segmentation
├── train.py
├── inference.py
├── metrics.py
└── visualization.py
You will also add your raw inputs here:
data/
└── input/
├── soil/ # .jpg images of soil textures
└── plant/ # .stl mesh files of plant models
-
Clone the repo
git clone https://github.com/arthurbbm/cv_final_project cd cv_final_project -
Create the conda environment
conda env create -f environment.yml conda activate cv_final_project
-
(Optional) You can also install via
pipif you prefer:pip install -r requirements.txt
All configurable paths go into config.yml. At minimum, set:
pybullet_dataset: /absolute/path/to/data
segmentation_dataset: /path/to/segmentation_dataset-
pybullet_datasetRoot of your data directory for PyBullet jobs.-
Input soil images in
…/data/input/soil/ -
Input plant meshes in
…/data/input/plant/ -
After running PyBullet scripts, outputs will be written to:
[pybullet_dataset]/output/images [pybullet_dataset]/output/masks -
Important: after each run of
generate_train_dataset.pyorgenerate_test_dataset.py, rename theoutput/folder (e.g.output_train/,output_test/) to prevent overwriting/mixture.
-
-
segmentation_datasetRoot of your segmentation dataset. It should contain two subdirectories:/path/to/segmentation_dataset/ ├── train_sim/ # ground-truth images/masks └── inference_train_sim/ # predicted masks
What is PyBullet? PyBullet is a physics‐simulation library that can simulate rigid‐body dynamics and sensor rendering. Here it’s used to spawn synthetic scenes of soil + plant meshes and render:
- RGB images → saved to
…/output/images - Ground‐truth masks → saved to
…/output/masks
# Generate training dataset
python pybullet/generate_train_dataset.py
# Generate testing dataset
python pybullet/generate_test_dataset.pyAfter each run, rename the …/output/ directory before running the other script.
This project does not implement a new style‑transfer method, but you can apply one to make your simulated images look more “real.” We recommend the DT‑MARS‑CycleGAN codebase:
You can use their pretrained models or train your own, then apply to the images in your PyBullet output/images before training the segmentation network.
The segmentation scripts live under segmentation/. First, make sure your combined dataset (possibly style‑transferred) is arranged as:
/path/to/dataset/
├── images/
│ ├── img_0001.png
│ └── …
└── masks/
├── mask_0001.png
└── …
cd segmentation
python train.py \
--n_epochs 10 \
--batchSize 4 \
--dataroot /path/to/dataset \
--outdir /path/to/save/model \
--checkpoint_freq 5 \
--lr 1e-4 \
--num_labels 2 \
[--device cuda]-
Train script:
train.pyis the correct entry point. -
File naming requirement: The script pairs images and masks by sorted order—make sure each RGB image and its corresponding mask share the same filename (aside from extension) so that after sorting they align correctly.
-
Output files (in
--outdir):checkpoint.pth(everycheckpoint_freqepochs)segmentation_model.pth(finalstate_dict)
Once you have a trained model (.pth), you can predict on new images:
cd segmentation
python inference.py \
--model_path /path/to/segmentation_model.pth \
--num_labels 2 \
--test_dir /path/to/test/images \
--output_dir /path/to/save/predicted/masks \
[--device cuda]Predicted masks will be saved as PNGs in output_dir.
This project includes scripts for evaluating and visualizing model predictions.
-
Purpose: Compute image-wise and overall segmentation metrics (accuracy, precision, recall, F1-score, IoU).
-
Configuration: Ensure
config.ymlcontains:segmentation_dataset: /path/to/segmentation_dataset
with structure:
segmentation_dataset/ ├── train_sim/ # ground-truth images and masks └── inference_train_sim/ # predicted masks (same filenames) -
Usage:
cd segmentation python metrics.py -
Outputs:
metrics_imagewise.csv– per-image metrics tablemetrics_overall.csv– aggregated metrics summary
-
Purpose: Overlay predicted masks on original RGB images and save blended figures for qualitative inspection.
-
Configuration: Uses the same
segmentation_datasetpath from above. -
Usage:
cd segmentation python visualization.py