Giter VIP home page Giter VIP logo

intracranial-hemorrhage-detection's Introduction

intracranial-hemorrhage-detection

Repo for RSNA intracranial hemorrhage detection. Instructions for reproducability can be found below.

Overview

Intracranial hemorrhage (bleeding within the cranium) accounts for ~10% of strokes in the U.S., where stroke is the fifth-leading cause of death. There are several types of hemorrhage and indentifying/locating them in a patient quickly is not only a matter of life and death, but speed also plays a critical part in the quality of life a survior can expext post recovery.

Diagnosing and locating an intracranial hemorrhage from neurological symptoms (e.g. severe headache or loss of consciousness) and medical imagery is a complicated, time consuming process requiring a highly trained spcialist. A technology solution would enhance the speed and diagnostic ability of medical practioners as well as potentially provide diagnostic ability or relief to patients who are not near an expert. Our goal is to build a model and system which detecs acute intracranial hemorrhages and its subtypes. hemorrhage_subtypes

Data

The dataset has been provided by the Radiological Society of North America (RSNA®) in collaboration with members of the American Society of Neuroradiology and MD.ai.

Data Augmentation

Data is augmented via random flips (vertical and horizontal), rotations (+/- 10 degrees), Salt&Pepper noise, and affine transformations (deformation) to help capture the invariants. This also helps to upsample class 1 data. We also window channels sepretly. In the image below we show a 3 channel img combined via np.dstack(), and the corrosponding individual channels. The windowing used on this particular hounsfield normalized data are: brain, subdural, and blood. We also apply image normalization to help the CNN.

sample_data_augmentation

Furthermore we also downsample class 0 data by randomly selecting images to match the number of class 1 training data. When training binary cross entropy for "any" class 1 subtype, we set all subtypes to class 1 and an equal amount of class 0 to 0

Model

Based on InceptionV3

num_epochs = 8
img_shape = (256,256,3)
batch_size=24
learning_rate=5e-4
decay_rate=0.8
decay_steps=1
weights="imagenet"
verbose=1

Evaluation

Model evaluated using a weighted multi-label logarithmic loss (same as cross-entropy for all intents and purposes). Using the minmax rule to avoid undefinned predictions at {0,1}, offset by a small epsilon: max(min(p, 1−10^−15), 10^-15).

Team

  • Chris Chen
  • Tony Reina
  • Kyle Shannon

Getting Started, Training, & Testing Instructions:

Instructions for deploying our codebase and reproducing our results:

  1. Run the shell script create_config.ini, also create the following directories if they do not exist: submissions/, models/, eda/, logs/, src/tensorboards, and src/model_defs
  2. Set you config.ini script, use_docker must be true if you are training with our docker script, you must also set your docker paths to the data, in our case we mounted a drive to the docker container, our docker run command looks like this:
docker run \
  --mount type=bind,source=/media/mount_point/intracranial-hemorrhage-detection-data,destination=/home/data \
  --mount type=bind,source=/home/kyle/dev/kaggle/intracranial-hemorrhage-detection,destination=/home/intracranial-hemorrhage-detection \
  --name baseline \
  --gpus all \
  --expose=8888 \
  --rm \
  -it rsna-kaggle
  1. Run the Docker script to create a GPU ready linux container. (We assume you will be using Nvidia GPUs on a Linux based system. We also use tmux in the docker container during training.
  2. Ensure that the conda environment was set up properly and matches the .yaml environment configuration.
  3. Training was perfoemd using train.py, model.py, and data_loader.py many ideas we wound up using in our final model came from several
  4. Inference is performed using the inference.py file. The batch size for inference must be 1 or evenly divisible by the dataset being tested.

Final Results:

We ended up training a model for 3 epochs based off of InceptionV3. This model was trained off of stage_1_training images. We did not perform any additional training in stage 2 with the updated training data and produced a result of 0.185 loss on 1% of the final stage 2 test data. Will update when we have the final results.

OLD Model Training Instructions:

These instructions were for the original idea we had of training seperate binary cross entropy models and predicting on class "any" first. We decided to abandon this pursuit when using a categorical cross entropy loss approach and a vector of all subtype including any, proved to be easier to get better results in the limited time we had.

start training via: python train.py {model-name}-{dims}-{loss}-{subtype}-{monthDay-version} e.g. $ python train.py resnet50-dim224x224-bce-intraparenchymal-oct18v1

After training is complete, please create a folder in the google drive shared folder with the models name (e.g. resnet50-dim224x224-bce-intraparenchymal-oct18v1) in that folder please upload the model.pb, model's tensorboard folder, and the current src/ folder that was used to train the model, that way we are ensured to know which copy of the data_loader etc was used to train the model. Note you might need to $ sudo chown user ./dir/* the models and tensboard folder, because the permissions may be different from the docker container when writing to local disk.

In the google spreadsheet, you can add more info about the model, anything interesting you noted and be on your merry way. Thanks! I used the following arguments for IH subtypes on ResNet50:

BATCH_SIZE = 32
EPOCHS = 15 
DIMS = (224,224)
training_data_gen = DataGenerator(csv_filename=TRAIN_CSV,
                                    data_path=DATA_DIRECTORY,
                                    batch_size=BATCH_SIZE,
                                    dims=DIMS,
                                    augment=True,
                                    balance_data = True,
                                    subtype = "intraparenchymal",  ####### <-- change this
                                    channel_types = ['subdural','soft_tissue','brain']) ### <-- we are using these windows?
validation_data_gen = DataGenerator(csv_filename=VALIDATE_CSV,
                                    data_path=DATA_DIRECTORY,
                                    batch_size=BATCH_SIZE,
                                    dims=DIMS,
                                    augment=False,
                                    balance_data = True,
                                    subtype = "intraparenchymal",  ####### <-- change this
                                    channel_types = ['subdural','soft_tissue','brain']) ### <-- we are using these windows?

intracranial-hemorrhage-detection's People

Contributors

kshannon avatar utcsox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

intracranial-hemorrhage-detection's Issues

EDA

  • Please add an intracranial-hemorrhage-detection/eda/ directory at the top level and put *.ipynb eda scrips in this folder.
  • Tony, you had mentioned you did a first pass EDA on the data? If so you can upload it and maybe chris can do some more work on it once he gets the data?

Enhance predict script

Need to make use of the data loader to do batch processing of predictions and write them out to a csv file. Most of the infrastructure for this already exists currently. Might need to tweak the data loader slightly. Might be a good task for @utcsox to work.

Modeling Ideas

vgg16 and resnet50 as a starting point was a good idea, and it seems that other people in the field have taken similar courses of actions.

Our proposed system for the detection and classification of ICH uses multiple ImageNet6 pretrained deep convolutional neural networks (DCNNs), a preprocessing pipeline, an atlas creation module and a prediction-basis selection module (Fig. 1). The four DCNNs used for building our model are VGG167, ResNet-508, Inception-v39 and Inception-ResNet-v210." Lee et. al. NATURE BIOMEDICAL ENGINEERING | VOL 3 | MARCH 2019 | 173–182 |

add random data augmentation to data loader

Rotation: could be bound to 90 degree increments or perhaps 10 degree...
Flip: yes this is a good option to include
Scaling: could random zooms work? possibly not need to be careful because we could crop out the actual hemorrhage thus losing class 1 data and misclassifying it....
Translation: could be maybe +/- 50px? how to interpolate area (constant, edge, reflect, wrap?)
Denoising/Noise: add Gaussian noise?

Training data augmentation. Real-time data augmentation (Fig. 3, M4) was performed by applying geometric transformations (rotation, scaling and translation) to make models learn invariant features to geometric perturbations. In addition, to improve invariance of the model to noise, either standard or denoised images was randomly selected to be used. We generated denoised images for standard cases by applying a median filter with a window size of 3 and used the scanner-generated denoised images if they already existed in the datasets. For the cases only with scanner-generated denoised images, only the denoised images were used as we were concerned about a bias that might be produced by reversing the denoising processes that are unknown to us. Rotation angles ranging from –10o to 10o with an interval of 1o, scaling ratios of heights and widths ranging from 90% to 100% with an interval of 1%, translation parameters ranging from − 12 to 12 pixels in x and y directions with an interval of 1 pixel, and a median filter with a window size of 3 were used for augmentation. All these parameters were randomly selected in the predefined ranges. Lee et. al. NATURE BIOMEDICAL ENGINEERING | VOL 3 | MARCH 2019 | 173–182

Update Dicom Reader Function

need to add the ability to recenter, window and level a dicom. These should be flagged and params set for the size fo the window/level.

Kaggle Team

Accept Tony/Chris on team. general housekeeping..

Enhance data loader

Might be nice for the data loader to asisst with:

  • upsample/downsample of class All or 0
  • good to consider being able to train only on class != 0
  • Good to be able to mini batch sample on class 1/0 also possibly on subclass level

we need to talk more about this soon as this will allow to apply more complex training schemes and modeling.

data preprocessing

need to add true upsampling and mind distributions. Generate new train/validation CSVs for data loader

  • 7 col: id, subtype 1-5, all
  • remove duplicates (see comment below)
  • randomly downsample class 0 to match class 1
  • split into train/validation (look at bar plot distributions
  • create 3 sets of csvs [(balanced train/val), (class_any train/val), (class_subtypes train/val)] all using the same base test/train split.

3D ideas

Thoughts on maximizing 3d representation via interpolation w/o training a 3d model:

Slice inter-polation was introduced to mimic how radiologists integrate infor-mation from all adjacent images of a contiguous three-dimensional (3D) volume concurrently, rather than examine each single axial 2D slice in isolation. Interpolated images from adjacent slices were pro-vided to the model with a modified loss function during training to imitate the 3D integration of image interpretation by radiologists. Lee et. al. NATURE BIOMEDICAL ENGINEERING | VOL 3 | MARCH 2019 | 173–182 |

Though note this salient point from the same paper about strict 3d voxel based approaches:

Another approach to address inter-slice dependency is to build a 3D network that directly inputs the voxel data from the entire imaging volume into a 3D format rather than as pixel-data from discrete axial slices in a 2D format. To compare the 3D versus 2D approaches, we trained a 3D model using previously described methodology21 by using case-level labels aggregated from slice-level labels, as well as volume data with a standardized dimensionality (24 × 512 × 512 voxels) generated using 2D slices. The resulting 3D model, however, achieved a mAP of only 0.328 for the multi-label classification of our five ICH subtypes, which is substantially infe-rior to the mAP we obtained with our existing 2D model (mAP of 0.686). This finding is consistent with the ‘curse of dimensionality’ reported in a previous study24, which noted that the amount of data required to train a deep-learning model scales exponentially with the dimensionality of the data.

basic dataloader script

Need to implement the basic data loader. Shouldn't be too bad for this first version.

Tony, I am going to work on this today (Sat 9/28) and hopefully have something you can look at by tomorrow. If you can verify that it will work and look over the code that would be great.

CSV model logger

once a model is saved we can write to a csv file the model's name and specifications for what the model is and how it was trained e.g. batch size etc. perhaps even the time it took just to keep as a record.

define a model template script

scrpt should have a tf model defined along with consts that can be imported to the train.py script
which model-{custom-name}.py you use will be passed as an arg to the train.py folder

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.