Library for SAMUS training and late mask fusion.
Project description
samus-train-n-fusion
Repository containing the source code used for training segmentation models (SAMUS, PVT-Seg and CAFE-NET) and applying late fusion on segmentation ensembles on the chapter: Sample Size for Training and Testing: Segment Anything models and supervised approaches.
Project Structure
This project is structured as follows:
docker: files related to the environment used for training and testing the model. Includes the main Dockerfile and the pip requirments file;notebooks: contains the Jupyter notebooks used during experimentation;scripts: contains the executable files for the repository, such as the ones used for: training the models, inference, evaluation, etc.;seg_lib: library containing all of the shared source code that is used by the scripts (built using Poetry, more information on thepyproject.tomlfile).
Installation
To run the source code, please follow the steps as described:
- Create a conda environment and activate it
conda create -n seg_lib_env python==3.10
conda activate seg_lib_env
- Install poetry for dependency management and library building
pip install poetry
- Generate the library and install it
poetry build
pip install dist/seg_lib-1.0.0-py3-none-any.whl
If all of the steps were followed correctly, everything should be set up.
Running the Scripts
All of the scripts (or jobs) may be found in the scripts folder. It includes scripts for testing, training, fusion methods, etc. To run any of them, simply activate the conda environment that was previously set up and run the command as:
python scripts/submodule/script.py [ARGS]
A brief description of each one of the scripts may be found in READMEs contained inside each submodule. Currently, three submodules are available:
samus: scripts developed for training/evaluating SAMUS and its variations;seg: scripts developed for the general training/evaluation of segmentation models;seg_n_sam: scripts developed for the segmentation + SAM fusion pipeline.
Data Input Format
To run the training/evaluation scripts for SAMUS and Segmentation models, first refer to the arguments listed in scripts/samus/train.py. Each argument has a brief description and most of their default values are already set. After running the experiments, all of the outputs (including the best model's weights, logs, etc.) may be found in the path described in --output_path.
It is worth mentioning that the scripts expect that the data are described in a CSV file, contained in a metadata folder existing in --data_path. In order to set the data in the desired format, please follow the steps described as follows:
- create a folder called
metadata, such as:/path/to/your/data/metadata - place a CSV file
{DATASET_SNAME}.csvinside the matadata path - create the headers to the file and fill it with the information about each pair of image sample and label mask, as:
a. split: dataset split, used to filter the data during training and testing. Should be:
train,valortestb. class_id: integer describing the mask class identifier. If the problem deals with binary masking, it is assumed that this value is 1 c. subset: name of the subset wheret the image files are stored. Should be placed inside--data_pathd. img_name: file name of the input image source. Should be stored in{data_path}/{subset}/img/{img_name}e. label_name: file name of the refering mask image. Should be stored in{data_path}/{subset}/label/{label_name}
By the end of this process, it is expected that the metadata are created in the format:
split class_id subset img_name label_name
0 train 1 ribs_original VinDr_RibCXR_train_000.png VinDr_RibCXR_train_000_R1.bmp
1 train 1 ribs_original VinDr_RibCXR_train_000.png VinDr_RibCXR_train_000_R2.bmp
2 train 1 ribs_original VinDr_RibCXR_train_000.png VinDr_RibCXR_train_000_R3.bmp
3 train 1 ribs_original VinDr_RibCXR_train_000.png VinDr_RibCXR_train_000_R4.bmp
4 train 1 ribs_original VinDr_RibCXR_train_000.png VinDr_RibCXR_train_000_R5.bmp
and that the data follow the structure:
- metadata
|_ dataset_descriptor.csv
- subset_1
|- img
|- img_name_1.png
|- img_name_2.png
|- ...
|_ img_name_n.png
|- label
|- img_name_1.bmp
|- img_name_2.bmp
|- ...
|_ img_name_n.bmp
- subset_n
|- img
|- img_name_1.png
...
|- label
|- img_name_1.bmp
...
- ...
Some samples of datasets may be found at data/.
Citation
Whenever using the here available data, remember to cite the original chapter:
@inbook{cuza24,
author = {
Daniela Cuza
and Carlo Fantozzi
and Loris Nanni
and Daniel Fusaro
and Gustavo Zanoni Felipe
and Sheryl Brahnam},
title = {Advances in Intelligent Healthcare Delivery and Management},
chapter = {Sample Size for Training and Testing: Segment Anything models and supervised approaches},
pages = {40},
year = {2024},
publisher = {Springer Nature}
}
License
This repository is licensed under Apache 2.0.
It is advised to also check SAM's and SAMUS' licenses on their original repositories.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file seg_lib-1.0.0.tar.gz.
File metadata
- Download URL: seg_lib-1.0.0.tar.gz
- Upload date:
- Size: 78.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f9b1ff75df03b6f412b1af806965cf3f05b4527e030d16f928b8fbf5c70b356
|
|
| MD5 |
1ee02bfb410224471d0e07c5654c1945
|
|
| BLAKE2b-256 |
165bac5d42473e5dd66728b58e9c10625147fab20964dac06cb02242b2241577
|
File details
Details for the file seg_lib-1.0.0-py3-none-any.whl.
File metadata
- Download URL: seg_lib-1.0.0-py3-none-any.whl
- Upload date:
- Size: 106.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19d15ba73692274dea23179cd6dc945514fdf85e927fa236fb3ab7a40b05a739
|
|
| MD5 |
6421e8e8af87f1a02e49c3232fbe1fcc
|
|
| BLAKE2b-256 |
3524fbf425617aef2d91eb22daceb7c2a95d21b8f08d68eb38221068e5887399
|