ISLES 2022 Sub Acute Stroke
===========================

This project folder contains the configuration files, preprocessing, and visualization scripts for the
ISLES2022SubAcuteStroke dataset.

For more information, please refer to https://isles22.grand-challenge.org/dataset/.

Related papers:

* https://www.nature.com/articles/s41597-022-01875-5.

.. note::
    When running the preprocessing scripts please make sure you have the following packages installed: argparse,
    connected-components-3d, json, nibabel, numpy, pathlib, random, simpleitk. All those packages, except the
    connected-components-3d and simpleitk packages, are installed by default if atommic is installed. To install those
    two packages, please run the following commands:

    .. code-block:: bash

        pip install -r requirements/requirements-isles22.txt

**Visualization**
An example notebook for visualizing the data is provided in the
`visualize <https://github.com/wdika/atommic/tree/main/projects/SEG/ISLES2022SubAcuteStroke/visualize.ipynb>`_
notebook. You just need to set the path where the dataset is downloaded. You just need to set the path where
the dataset is downloaded. The notebook is copied and slightly modified from the
`original notebook <https://github.com/ezequieldlrosa/isles22/tree/main/utils>`_ provided by the ISLES challenge.

**Preprocessing**
The preprocessing pipeline is implemented in the
`preprocess_dataset.sh <https://github.com/wdika/atommic/tree/main/projects/SEG/ISLES2022SubAcuteStroke/preprocess_dataset.sh>`_
script, consisting of the following steps:
1. Clip to 0 - max values.
2. Normalize the images to zero mean and unit variance.
3. Resample the FLAIR data to the same resolution as the ADC and DWI data.
4. Stack all modalities (ADC, DWI, FLAIR) into a single 3D volume.
5. Fix the orientation of the images.
6. Updates headers and save to NIfTI format.
7. Split the dataset into training and validation sets.

**Training/Testing**

.. important::
    The ``ISLES2022SubAcuteStroke`` dataset is natively supported in ``atommic``. Therefore, you do not need to create
    a custom dataset class. You just need to set the ``dataset_format`` argument in the configuration file to
    ``ISLES2022SubAcuteStroke``. For example:

    .. code-block:: bash

        train_ds:
            dataset_format: ISLES2022SubAcuteStroke

        validation_ds:
            dataset_format: ISLES2022SubAcuteStroke

        test_ds:
            dataset_format: ISLES2022SubAcuteStroke

For training a model, you just need to set up the data and export paths to the
`configuration <https://github.com/wdika/atommic/tree/main/projects/SEG/ISLES2022SubAcuteStroke/conf/train/>`_
file of the model you want to train. In ``train_ds`` and `validation_ds` please set the ``data_path`` to the generated
json files. In ``exp_manager`` please set the ``exp_dir`` to the path where you want to save the model checkpoints and
tensorboard or wandb logs.

You can train a model with the following command:

.. code-block:: bash

    atommic run -c /projects/SEG/ISLES2022SubAcuteStroke/conf/train/{model}.yaml

For testing a model, you just need to set up the data and export paths to the
`configuration <https://github.com/wdika/atommic/tree/main/projects/SEG/ISLES2022SubAcuteStroke/conf/test/>`_ file
model you want to test. In ``checkpoint`` (line 2) set the path the trained model checkpoint and in ``test_ds`` please
set the ``data_path``. In ``exp_manager`` please set the ``exp_dir`` to the path where the predictions and logs will
be saved.

You can test a model with the following command:

.. code-block:: bash

    atommic run -c /projects/SEG/ISLES2022SubAcuteStroke/conf/test/{model}.yaml

**Note:** The default logger is tensorboard.
