Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seg example #42

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
70aaa31
Segmentation example - 1st commit
Mar 15, 2022
c8674b0
fix elastic augmentation and loss bce+dice; update for new eval packa…
Mar 15, 2022
98ebeee
Change to eval package
Mar 20, 2022
62d3c1c
Merge branch 'master' into seg_example
mosheraboh Mar 25, 2022
26c1ffe
move example to a new folder
Mar 26, 2022
59afc55
Update the create_data script + add some comment regarding the origin…
Mar 26, 2022
310726e
remove old script and update main script according to PR comments (no…
Mar 26, 2022
76f834d
change names to eval*
Mar 26, 2022
13aa1da
Changes following the comments on the PR
Mar 27, 2022
4ad76f2
remove commented code
Apr 4, 2022
323c270
Merge branch 'master' into seg_example
Apr 4, 2022
960a484
Merge branch 'master' into seg_example
mosheraboh Apr 7, 2022
5a4a6cf
change input desc to file names and processor to compute mask images …
Apr 10, 2022
e1e601d
factor out end to end examples to seprate package
Apr 13, 2022
75ce22b
add examples to PYTHONPATH
Apr 13, 2022
c53c96c
run unittests in examples
Apr 13, 2022
3551533
remove fuse1 data package
Apr 14, 2022
97eac6b
remove dataset from manager
Apr 14, 2022
dddac6d
convert mnist to fuse2 style
Apr 14, 2022
83936d0
create dl package
Apr 17, 2022
69a3b09
remove Fuse prefix
Apr 17, 2022
5771c85
reorg examples
Apr 17, 2022
13c5f0b
Merge branch 'master' of github.com:IBM/fuse-med-ml into fuse2
Apr 17, 2022
c12ff08
Merge branch 'fuse2' of github.com:IBM/fuse-med-ml into data_package
Apr 17, 2022
3e3a476
add fuse data package
Apr 17, 2022
5f614a0
Merge branch 'data_package' of github.com:IBM/fuse-med-ml into mnist_…
Apr 17, 2022
9b511cc
adjust mnist runner
Apr 17, 2022
532b347
imaging extension
Apr 18, 2022
1a94187
Merge branch 'data_package' of github.com:IBM/fuse-med-ml into mnist_…
Apr 18, 2022
92d78d1
Move changes from master's branch to mnist_fuse2_style's branch
Apr 18, 2022
0b8b573
Fixed import path
Apr 18, 2022
fb72386
remove the create-data script and move all its functionality to input…
Apr 19, 2022
bab4bf7
Updated the notebook (mnist example) to fuse2
Apr 25, 2022
d4a5c02
Skip test - temp
Apr 25, 2022
68df39c
Update test_notebook_hello_world.py
SagiPolaczek Apr 25, 2022
ae69698
Data package (#61)
mosheraboh Apr 28, 2022
b4804c3
skip test (it works locally)
Apr 28, 2022
63f2a29
Move changes from master's branch to mnist_fuse2_style's branch
Apr 18, 2022
c40f129
Fixed import path
Apr 18, 2022
419a36b
Updated the notebook (mnist example) to fuse2
Apr 25, 2022
13536f0
Skip test - temp
Apr 25, 2022
1077b8c
Update test_notebook_hello_world.py
SagiPolaczek Apr 25, 2022
85cdae4
skip test (it works locally)
Apr 28, 2022
26f78f8
Merge branch 'hello_world_unittest' of github.com:IBM/fuse-med-ml int…
Apr 28, 2022
0f3abf3
Fixed override in the set_device functionality and made cpu usage mor…
Apr 28, 2022
5d0b65a
Merge pull request #63 from IBM/hello_world_unittest
SagiPolaczek Apr 28, 2022
3f71935
data package readme
mosheraboh May 2, 2022
17ef080
Merge with master
May 3, 2022
1dc5050
merged with fuse2
May 3, 2022
2e1f98c
Fix import for fuse2 + add a static pipeline + change data source int…
May 10, 2022
dbe44a5
Complete data pipeline including the dynamic part
May 10, 2022
6c4232c
Working fuse2 version + fix to gaussian op data type
May 17, 2022
0ef6742
remove comments and non-required input processor file
May 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ lib64
**/*.log
Result
__pycache__
fuse_examples/classification/knight/baseline/*.csv
fuse_examples/classification/knight/baseline/clinical_data/*
fuse_examples/classification/knight/baseline/model_dir
fuse_examples/imaging/classification/knight/baseline/*.csv
fuse_examples/imaging/classification/knight/baseline/clinical_data/*
fuse_examples/imaging/classification/knight/baseline/model_dir
.gitignore.save
fuse_examples/classification/mnist/examples
fuse_examples/tutorials/hello_world/examples/
fuse_examples/imaging/classification/mnist/examples
fuse_examples/imaging/hello_world/examples/
.vscode/
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,35 @@ $ pip install -e .
```
This mode, allows to edit the source code and easily contribute back to the open-source project.

In this mode you can also install and run our end to end examples using:
```bash
$ pip install -e examples
```
An alternative, is to simply install using PyPI
```bash
$ pip install fuse-med-ml
```

FuseMedML supports Python 3.6 or later and PyTorch 1.5 or later. A full list of dependencies can be found in [**requirements.txt**](https://github.com/IBM/fuse-med-ml/tree/master/requirements.txt).
FuseMedML supports Python 3.7 or later and PyTorch 1.5 or later. A full list of dependencies can be found in [**requirements.txt**](https://github.com/IBM/fuse-med-ml/tree/master/requirements.txt).


# Ready to get started?
## FuseMedML from the ground up
[**User Guide**](https://github.com/IBM/fuse-med-ml/tree/master/fuse/doc/user_guide.md) - including detailed explanation about FuseMedML modules, structure, concept, and more.

[**Hello World**](https://colab.research.google.com/github/IBM/fuse-med-ml/blob/master/fuse_examples/tutorials/hello_world/hello_world.ipynb) - Introductory hands-on notebook on the well-known MNIST dataset.
[**Hello World**](https://colab.research.google.com/github/IBM/fuse-med-ml/blob/master/fuse_examples/imaging/hello_world/hello_world.ipynb) - Introductory hands-on notebook on the well-known MNIST dataset.

[**High Level Code Example**](https://github.com/IBM/fuse-med-ml/tree/master/fuse/doc/high_level_example.md) - example of binary classifier for mammography with an auxiliary segmentation loss and clinical data

## Examples
* classification
* [**MNIST**](https://github.com/IBM/fuse-med-ml/tree/master/fuse_examples/classification/mnist/) - a simple example, including training, inference and evaluation over [MNIST dataset](http://yann.lecun.com/exdb/mnist/)
* [**KNIGHT Challenge**](https://github.com/IBM/fuse-med-ml/tree/master/fuse_examples/classification/knight) - preoperative prediction of risk class for patients with renal masses identified in clinical Computed Tomography (CT) imaging of the kidneys. Including data pre-processing, baseline implementation and evaluation pipeline for the challenge.
* [**Multimodality tutorial**](https://github.com/IBM/fuse-med-ml/blob/master/fuse_examples/tutorials/multimodality_image_clinical/multimodality_image_clinical.ipynb) - demonstration of two popular simple methods integrating imaging and clinical data (tabular) using FuseMedML
* [**Skin Lesion**](https://github.com/IBM/fuse-med-ml/tree/master/fuse_examples/classification/skin_lesion/) - skin lesion classification , including training, inference and evaluation over the public dataset introduced in [ISIC challenge](https://challenge.isic-archive.com/landing/2017)
* [**Prostate Gleason Classifiaction**](https://github.com/IBM/fuse-med-ml/tree/master/fuse_examples/classification/prostate_x/) - lesions classification of Gleason score in prostate over the public dataset introduced in [SPIE-AAPM-NCI PROSTATEx challenge](https://wiki.cancerimagingarchive.net/display/Public/SPIE-AAPM-NCI+PROSTATEx+Challenges#23691656d4622c5ad5884bdb876d6d441994da38)
* [**Lesion Stage Classification**](https://github.com/IBM/fuse-med-ml/tree/master/fuse_examples/classification/duke_breast_cancer/) - lesions classification of Tumor Stage (Size) in breast MRI over the public dataset introduced in [Dynamic contrast-enhanced magnetic resonance images of breast cancer patients with tumor locations (Duke-Breast-Cancer-MRI)](https://wiki.cancerimagingarchive.net/pages/viewpage.action?pageId=70226903)
* [**Breast Cancer Lesion Classification**](https://github.com/IBM/fuse-med-ml/tree/master/fuse_examples/classification/MG_CMMD) - lesions classification of tumor ( benign, malignant) in breast mammography over the public dataset introduced in [The Chinese Mammography Database (CMMD)](https://wiki.cancerimagingarchive.net/pages/viewpage.action?pageId=70230508)
* [**MNIST**](https://github.com/IBM/fuse-med-ml/tree/master/examples/fuse_examples/imaging/classification/mnist/) - a simple example, including training, inference and evaluation over [MNIST dataset](http://yann.lecun.com/exdb/mnist/)
* [**KNIGHT Challenge**](https://github.com/IBM/fuse-med-ml/tree/master/examples/fuse_examples/imaging/classification/knight) - preoperative prediction of risk class for patients with renal masses identified in clinical Computed Tomography (CT) imaging of the kidneys. Including data pre-processing, baseline implementation and evaluation pipeline for the challenge.
* [**Multimodality tutorial**](https://github.com/IBM/fuse-med-ml/blob/master/examples/fuse_examples/multimodality/image_clinical/multimodality_image_clinical.ipynb) - demonstration of two popular simple methods integrating imaging and clinical data (tabular) using FuseMedML
* [**Skin Lesion**](https://github.com/IBM/fuse-med-ml/tree/master/examples/fuse_examples/imaging/classification/skin_lesion/) - skin lesion classification , including training, inference and evaluation over the public dataset introduced in [ISIC challenge](https://challenge.isic-archive.com/landing/2017)
* [**Prostate Gleason Classification**](https://github.com/IBM/fuse-med-ml/tree/master/example/fuse_examples/imaging/classification/prostate_x/) - lesions classification of Gleason score in prostate over the public dataset introduced in [SPIE-AAPM-NCI PROSTATEx challenge](https://wiki.cancerimagingarchive.net/display/Public/SPIE-AAPM-NCI+PROSTATEx+Challenges#23691656d4622c5ad5884bdb876d6d441994da38)
* [**Lesion Stage Classification**](https://github.com/IBM/fuse-med-ml/tree/master/examples/fuse_examples/imaging/classification/duke_breast_cancer/) - lesions classification of Tumor Stage (Size) in breast MRI over the public dataset introduced in [Dynamic contrast-enhanced magnetic resonance images of breast cancer patients with tumor locations (Duke-Breast-Cancer-MRI)](https://wiki.cancerimagingarchive.net/pages/viewpage.action?pageId=70226903)
* [**Breast Cancer Lesion Classification**](https://github.com/IBM/fuse-med-ml/tree/master/examples/fuse_examples/imaging/classification/MG_CMMD) - lesions classification of tumor ( benign, malignant) in breast mammography over the public dataset introduced in [The Chinese Mammography Database (CMMD)](https://wiki.cancerimagingarchive.net/pages/viewpage.action?pageId=70230508)

## Walkthrough template
* [**Walkthrough Template**](https://github.com/IBM/fuse-med-ml/tree/master/fuse/templates/walkthrough_template.py) - includes several TODO notes, marking the minimal scope of code required to get your pipeline up and running. The template also includes useful explanations and tips.
Expand Down
1 change: 1 addition & 0 deletions VERSION.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.2.0
Original file line number Diff line number Diff line change
Expand Up @@ -42,50 +42,50 @@ The participants should submit a .csv file per task containing a row with a fina
**Task 1 Prediction File:**
\[image_name,predicted_label,Noncancerous-score,Precancerous-score,Cancerous-score\]

See [example prediction file for task 1](https://github.com/IBM/fuse-med-ml/blob/master/fuse_examples/classification/bright/eval/example/example_task1_predictions.csv)
See [example prediction file for task 1](https://github.com/IBM/fuse-med-ml/blob/master/fuse_examples/imaging/classification/bright/eval/example/example_task1_predictions.csv)

**Task 2 Prediction File:**
\[image_name,predicted_label,PB-score,UDH-score,FEA-score,ADH-score,DCIS-score,IC-score\]

See [example prediction file for task 2](https://github.com/IBM/fuse-med-ml/blob/master/fuse_examples/classification/bright/eval/example/example_task2_predictions.csv)
See [example prediction file for task 2](https://github.com/IBM/fuse-med-ml/blob/master/fuse_examples/imaging/classification/bright/eval/example/example_task2_predictions.csv)

Where “image_name" represents the sample (e.g. BRACS_264) and all scores represent the probability of a patient to belong to a class.

The evaluation script together with a dummy prediction files can be found in `fuse-med-ml/fuse_examples/classification/bright/eval`
The evaluation script together with a dummy prediction files can be found in `fuse-med-ml/fuse_examples/imaging/classification/bright/eval`
More details can be found in [challenge website](https://research.ibm.com/haifa/Workshops/BRIGHT)


<br/>

To run the evaluation script:
```
cd fuse-med-ml/fuse_examples/classification/knight/eval
cd fuse-med-ml/fuse_examples/imaging/classification/knight/eval
python eval.py <target_filename> <task1 prediction_filename> <task1 prediction_filename> <output dir>
```
To evaluate the dummy example predictions and targets
```
cd fuse-med-ml/fuse_examples/classification/knight/eval
cd fuse-med-ml/fuse_examples/imaging/classification/knight/eval
python eval.py example/example_targets.csv example/example_task1_predictions.csv example/example_task2_predictions.csv example/results
```

### Baseline
As an additional example, we also include the validation prediction files and validation target file of the challenge baseline implementation:


See [validation baseline prediction file for task 1](https://github.com/IBM/fuse-med-ml/blob/master/fuse_examples/classification/bright/eval/baseline/validation_baseline_task1_predictions.csv)
See [validation baseline prediction file for task 1](https://github.com/IBM/fuse-med-ml/blob/master/fuse_examples/imaging/classification/bright/eval/baseline/validation_baseline_task1_predictions.csv)


See [validation baseline prediction file for task 2](https://github.com/IBM/fuse-med-ml/blob/master/fuse_examples/classification/bright/eval/baseline/validation_baseline_task2_predictions.csv)
See [validation baseline prediction file for task 2](https://github.com/IBM/fuse-med-ml/blob/master/fuse_examples/imaging/classification/bright/eval/baseline/validation_baseline_task2_predictions.csv)


See [validation targets file](https://github.com/IBM/fuse-med-ml/blob/master/fuse_examples/classification/bright/eval/validation_targets.csv)
See [validation targets file](https://github.com/IBM/fuse-med-ml/blob/master/fuse_examples/imaging/classification/bright/eval/validation_targets.csv)



<br/>

To evaluate the baseline predictions over the validation set:
```
cd fuse-med-ml/fuse_examples/classification/bright/eval
cd fuse-med-ml/fuse_examples/imaging.classification/bright/eval
python eval.py validation_targets.csv baseline/validation_baseline_task1_predictions.csv baseline/validation_baseline_task2_predictions.csv baseline/validation_results
```
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ def eval(task1_prediction_filename: str, task2_prediction_filename: str, target_
"""
Run evaluation:
Usage: python eval.py <target_filename> <task1_prediction_filename> <task2_prediction_filename> <output dir>
Run dummy example (set the working dir to fuse-med-ml/fuse_examples/classification/bright/eval): python eval.py example/example_targets.csv example/example_task1_predictions.csv example/example_task2_predictions.csv example/results
Run baseline (set the working dir to fuse-med-ml/fuse_examples/classification/bright/eval): python eval.py validation_targets.csv baseline/validation_baseline_task1_predictions.csv baseline/validation_baseline_task2_predictions.csv baseline/validation_results
Run dummy example (set the working dir to fuse-med-ml/fuse_examples/imaging/classification/bright/eval): python eval.py example/example_targets.csv example/example_task1_predictions.csv example/example_task2_predictions.csv example/results
Run baseline (set the working dir to fuse-med-ml/fuse_examples/imaging/classification/bright/eval): python eval.py validation_targets.csv baseline/validation_baseline_task1_predictions.csv baseline/validation_baseline_task2_predictions.csv baseline/validation_results
"""

if len(sys.argv) == 1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@
from pathlib import Path


from fuse.data.visualizer.visualizer_default import FuseVisualizerDefault
from fuse.data.augmentor.augmentor_default import FuseAugmentorDefault
from fuse.data.visualizer.visualizer_default import VisualizerDefault
from fuse.data.augmentor.augmentor_default import AugmentorDefault
from fuse.data.augmentor.augmentor_toolbox import aug_op_color, aug_op_gaussian, aug_op_affine
from fuse.data.dataset.dataset_default import FuseDatasetDefault
from fuse.data.dataset.dataset_default import DatasetDefault

from fuse.utils.rand.param_sampler import Uniform, RandInt, RandBool

from fuse_examples.classification.cmmd.input_processor import FuseMGInputProcessor
from fuse_examples.classification.cmmd.ground_truth_processor import FuseMGGroundTruthProcessor
from fuse.data.data_source.data_source_folds import FuseDataSourceFolds
from fuse_examples.imaging.classification.cmmd.input_processor import MGInputProcessor
from fuse_examples.imaging.classification.cmmd.ground_truth_processor import MGGroundTruthProcessor
from fuse.data.data_source.data_source_folds import DataSourceFolds

from typing import Tuple


def CMMD_2021_dataset(data_dir: str, data_misc_dir: str ,cache_dir: str = 'cache', reset_cache: bool = False,
post_cache_processing_func: Optional[Callable] = None) -> Tuple[FuseDatasetDefault, FuseDatasetDefault]:
post_cache_processing_func: Optional[Callable] = None) -> Tuple[DatasetDefault, DatasetDefault]:
"""
Creates Fuse Dataset object for training, validation and test
:param data_dir: dataset root path
:param data_misc_dir path to save misc files to be used later
:param cache_dir: Optional, name of the cache folder
:param reset_cache: Optional,specifies if we want to clear the cache first
:param post_cache_processing_func: Optional, function run post cache processing
:return: training, validation and test FuseDatasetDefault objects
:return: training, validation and test DatasetDefault objects
"""
augmentation_pipeline = [
[
Expand Down Expand Up @@ -60,7 +60,7 @@ def CMMD_2021_dataset(data_dir: str, data_misc_dir: str ,cache_dir: str = 'cache
input_source_gt = merge_clinical_data_with_dicom_tags(data_dir, data_misc_dir, target)

partition_file_path = os.path.join(data_misc_dir, 'data_fold_new.csv')
train_data_source = FuseDataSourceFolds(input_source=input_source_gt,
train_data_source = DataSourceFolds(input_source=input_source_gt,
input_df=None,
phase='train',
no_mixture_id='ID1',
Expand All @@ -73,21 +73,21 @@ def CMMD_2021_dataset(data_dir: str, data_misc_dir: str ,cache_dir: str = 'cache

# Create data processors:
input_processors = {
'image': FuseMGInputProcessor(input_data=data_dir)
'image': MGInputProcessor(input_data=data_dir)
}
gt_processors = {
'classification': FuseMGGroundTruthProcessor(input_data=input_source_gt)
'classification': MGGroundTruthProcessor(input_data=input_source_gt)
}

# Create data augmentation (optional)
augmentor = FuseAugmentorDefault(
augmentor = AugmentorDefault(
augmentation_pipeline=augmentation_pipeline)

# Create visualizer (optional)
visualiser = FuseVisualizerDefault(image_name='data.input.image', label_name='data.gt.classification')
visualiser = VisualizerDefault(image_name='data.input.image', label_name='data.gt.classification')

# Create train dataset
train_dataset = FuseDatasetDefault(cache_dest=cache_dir,
train_dataset = DatasetDefault(cache_dest=cache_dir,
data_source=train_data_source,
input_processors=input_processors,
gt_processors=gt_processors,
Expand All @@ -100,7 +100,7 @@ def CMMD_2021_dataset(data_dir: str, data_misc_dir: str ,cache_dir: str = 'cache
lgr.info(f'- Load and cache data: Done')

# Create validation data source
validation_data_source = FuseDataSourceFolds(input_source=input_source_gt,
validation_data_source = DataSourceFolds(input_source=input_source_gt,
input_df=None,
phase='validation',
no_mixture_id='ID1',
Expand All @@ -111,7 +111,7 @@ def CMMD_2021_dataset(data_dir: str, data_misc_dir: str ,cache_dir: str = 'cache
partition_file_name=partition_file_path)

## Create dataset
validation_dataset = FuseDatasetDefault(cache_dest=cache_dir,
validation_dataset = DatasetDefault(cache_dest=cache_dir,
data_source=validation_data_source,
input_processors=input_processors,
gt_processors=gt_processors,
Expand All @@ -120,7 +120,7 @@ def CMMD_2021_dataset(data_dir: str, data_misc_dir: str ,cache_dir: str = 'cache
visualizer=visualiser)
validation_dataset.create( pool_type='thread') # use ThreadPool to create this dataset, to avoid cv2 problems in multithreading

test_data_source = FuseDataSourceFolds(input_source=input_source_gt,
test_data_source = DataSourceFolds(input_source=input_source_gt,
input_df=None,
phase='test',
no_mixture_id='ID1',
Expand All @@ -129,7 +129,7 @@ def CMMD_2021_dataset(data_dir: str, data_misc_dir: str ,cache_dir: str = 'cache
folds=[4],
num_folds=5,
partition_file_name=partition_file_path)
test_dataset = FuseDatasetDefault(cache_dest=cache_dir,
test_dataset = DatasetDefault(cache_dest=cache_dir,
data_source=test_data_source,
input_processors=input_processors,
gt_processors=gt_processors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import pandas as pd
import numpy as np

from fuse.data.processor.processor_base import FuseProcessorBase
from fuse.data.processor.processor_base import ProcessorBase


class FuseMGGroundTruthProcessor(FuseProcessorBase):
class MGGroundTruthProcessor(ProcessorBase):
def __init__(self,
input_data: str):

Expand Down
Loading