Git Product home page Git Product logo

umessen / salt Goto Github PK

View Code? Open in Web Editor NEW
73.0 4.0 4.0 61.89 MB

Softmax for Arbitrary Label Trees (SALT) is a framework for training segmentation networks using conditional probabilities to model hierarchical relationships in the data.

Home Page: https://ship-ai.ikim.nrw/

License: MIT License

Dockerfile 0.33% Python 99.67%
3d-segmentation medical-image-segmentation conditional-probabilities hierarchical-labels

salt's Introduction

License: MIT


Logo

Softmax for Arbitrary Label Trees

This segmentation framework was developed at the Institute for AI in Medicine of the University Hospital Essen by the SHIP-AI team. The framework can be used for any 2D or 3D segmentation task that exhibits a hierarchical labels structure. In our case, we applied this to medical imaging and provide the segmentation of 145 different structures in the human body.

The model is very fast (average of 35 seconds for a 1000 whole body!) and can segment 113 body regions in a single pass.

Segmentation

Training

Datasets

For training, the dataset folder should have the following structure:

data/
├── lits/
├── kits/
├── saros/
├── ...

Each dataset should contain the following files and folders:

data/
├── saros/
│   ├── labels.txt
|   ├── tree-labels.txt
│   ├── train/
│   │   ├── images/
│   │   │   ├── s0001.nii.gz
│   │   │   ├── s0002.nii.gz
│   │   ├── labels/
│   │   │   ├── s0001.nii.gz
│   │   │   ├── s0002.nii.gz
│   ├── val/
│   │   ├── images
│   │   │   ├── ...
│   │   ├── labels
│   │   │   ├── ...
│   ├── test/
│   │   ├── images
│   │   │   ├── ...
│   │   ├── labels

The datasets do not need to have all three train, val, and test folders, and may only include a test set.

The files labels.txt and tree-labels.txt specify the labels from the dataset. labels.txt should contain the label names, while tree-labels.txt should define the hierarchical structure of the labels from the tree. In the labels folder, you can find some examples for these files, and in the conversion you can find examples on how the data was converted to this format.

Train

Once the data is set up, you can build the docker image with

docker build -t shipai/salt .

and then run the container with

docker run -it --rm \
       --runtime=nvidia \
       --network host \
       --user $(id -u):$(id -g) \
       --shm-size=8g --ulimit memlock=-1 --ulimit stack=67108864 \
       -v /path/to/storage:/storage \
       -e NVIDIA_VISIBLE_DEVICES=0,1,2 \
       shipai/salt

Once the container is running, you can use the following commands to train the models:

python3 -m salt.train \
    --data-dir /storage/datasets/data/ \
    --mixed-precision \
    --train-dir /storage/models/your-model-name \
    --epochs 1000 --batch-size 3 --gpus 0 1 2 --sink-weight 0.0

The number of gpus and the batch size you use depends on how many GPUs you made available in your docker run command.

Once the training is finished, you can export the model to a single model file:

python -m salt.export \
       --train-dir /storage/models/your-model-name \
       --output-dir /storage/models/exports/your-model-name

Prediction & Evaluation

You can build the docker image with

docker build -t shipai/salt .

and then run the container with

docker run -it --rm \
       --runtime=nvidia \
       --network host \
       --user $(id -u):$(id -g) \
       --shm-size=8g --ulimit memlock=-1 --ulimit stack=67108864 \
       -v /path/to/storage:/storage \
       -e NVIDIA_VISIBLE_DEVICES=0,1,2 \
       shipai/salt

Once the container is running, you can compute the predictions for your dataset using our model

python -m salt.predict \
       --data-dir /storage/datasets/data/dataset-name/images \
       --output_dir /storage/results/your-model-name/dataset-name

or run it with your newly trained model

python -m salt.predict \
       --model-file /storage/models/exports/your-model-name/model.pt \
       --config-file /storage/models/exports/your-model-name/config.pkl \
       --data-dir /storage/datasets/data/dataset-name/images \
       --output_dir /storage/results/your-model-name/dataset-name

Note that for the predictions, the data does not need to be in a particular format, and any folder containing NIfTI files can be used as input.

If your dataset has a ground truth, you can evaluate the predictions from outside the container using:

poetry run python -m salt.classic_evaluate \
       --config-file /path/to/the/model/config.pkl \
       --data-dir /path/to/the/data \
       --predictions-dir /path/to/the/predictions \
       --output-dir /path/for/results

salt's People

Contributors

giuliabaldini avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

salt's Issues

generic conversion scripts for bringing TCIA data into SALT/MONAI

This looks really cool! I noticed that you've used a few datasets from The Cancer Imaging Archive as I'm seeing names like SAROS, LCTSC, CT-ORG and that you provided some conversion steps to prepare each of them for your model. Do you think there is some way to integrate generic preprocessing functionality into SALT/MONAI that would allow people to go from TCIA DICOM data with SEG/RTSTRUCT labels to something that's shovel-ready for segmentation models? Or will it always require dealing with quirks that are unique to each dataset?

Also, just FYI, https://github.com/kirbyju/TCIA_Notebooks/blob/main/TCIA_REST_API_Downloads.ipynb may be of interest to you. You could potentially use some of the examples there to help people easily download the images for datasets where you have prepared conversion scripts so they don't have to manually go to our website and find these images.

Best,
Justin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.