Giter Club home page Giter Club logo

aigt's Introduction

AIGT

This repository contains scripts for deep learning for guided medical interventions. For some projects, the complete workflow is implemented, from formatting and annotations to deployment of models in real time. Most projects use ultrasound imaging.

Getting started

Install and set up Anaconda environment

  • Install a recent Anaconda version for Python 3.9 version from the Anaconda download page
  • Clone this repository on your computer. Your local clone may be in a path like c:\dev\aigt
  • Start the Anaconda Prompt application and navigate to the environment setup folder cd c:\dev\aigt\SetupAnaconda
  • Run the setup_env.bat file to create environment in a folder, e.g. setup_env.bat c:\dev\dlenv This will install TensorFlow 2.0 and other packages that are used by projects. The previous environment setup script (for TensorFlow v1 is still available as setup_env_tf1.bat

Additional local files you may need, but they are not in the code repository

Please do not commit/push these local files, as everybody sets them up with values that only apply to their environment.

  • local_vars.py - Some notebooks require a file in the Notebooks folder of your local repository clone, named local_vars.py. This file should define the root_folder variable. The file may just contain this single line of code: root_folder = r"c:\Data".
  • girder_apikey_read.py - Some notebooks require a file named girder_apikey_read.py with a single line of code that specifies your personal API key to the private data collection. If you work with non-public data stored on a Girder server, ask your supervisor for a Girder account and how to generate API keys for yourself.

To run Slicer notebooks

  • Install Slicer 4.11 or newer version (later than 2019-09-16 is recommended, for full functionality)
  • Install the SlicerJupyter extension for Slicer, and follow the extension user guide to add Slicer as a kernel in Jupyter Notebook (use the Copy command to clipboard button and paste it in the active Anaconda environment).
  • If you have a GPU and would like Slicer's TensorFlow to use it, then install CUDA 10.1 and cuDNN 7.6.5. GPUs can make training of models much faster, but may not significantly speed up trained models for prediction compared to CPUs.
  • Some users have reported that they needed to install Visual Studio (2015 or later) to be able to use TensorFlow.
  • Install additional packages in the Slicer python environment, to be able to run all Slicer notebooks. Use the Python console of Slicer to run this command:
pip_install("tensorflow opencv-contrib-python girder_client pandas nbformat nbconvert")
  • To run notebooks, start the Anaconda command prompt, navigate to the aigt folder, and type the jupyter notebook command.

Acquire tracked ultrasound

  • Use the Sequences extension in 3D Slicer to record tracked ultrasound sequences.
  • Record Image_Image (the ultrasound in the Image coordinate system) and ImageToReference transform sequences. Note that Slicer cannot record transformed images, so recording Image_Reference is not an option.
  • If you work on segmentation, you can use the SingleSliceSegmentation Slicer module in this repository to speed up manual segmentation.
  • Create annotations by placing fiducials or creating segmentations with the SingleSliceSegmentation module.
  • For segmentations, you may use the SingleSliceSegmentation module to export images and segmentations in png file format.
  • Use scripts in the Notebooks/Slicer folder to export images and annotations.

Process exported data

  • It is recommended that you save separate sequences for validation and testing
  • Use Notebooks/FoldersToSavedArrays to save data sequences as single files for faster data loading during training.

Acknowledgements

Canarie Logo This work was supported through CANARIE’s Research Software Program through RS3-036. Principal investigator: Gabor Fichtinger.

aigt's People

Contributors

bennetmontgomery avatar chriscyyeung avatar gracepigeau avatar hastingsgreer avatar jcfr avatar jlaframboise avatar keiranbarr avatar khashtrudi avatar lassoan avatar markasselin avatar nkitner avatar oliviaodriscoll avatar pdc878 avatar rebeccahisey avatar robertzsoltszabo avatar sunderlandkyl avatar ungi avatar vctoriawu avatar zacbaum avatar zoeyiyi11 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

Watchers

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

aigt's Issues

Support images multiple segments

We need to start supporting multiple segments by one-hot encoding, multi-channel model outputs, and softmax instead of sigmoid final activation. Robert tried this on his dataset by modifying our code, and he says it was quite simple to do.

I think Single Slice Segmentation exports different segments as different values, so that may need to be converted to one-hot encoding later by one of the scripts. The safest place to do this would be in the training script. But we may need to modify the prepare_data script too. Multi-value segmentation arrays should only be resized using nearest neighbor interpolation. Standard image resize functions can interpolate between values (if a new pixel position falls between two old pixel positions). But interpolated non-integer values cannot be later converted using one-hot encoding.

Better control for selecting training/validation data

It should be easier to add/remove data to/from validation rounds. It should also be possible to specify validation data without leave-one-out, or no validation at all (when want to maximize training data before testing).

Record performance metrics of each trained model

  • Implement timing of final model in train scrip
  • Implement timing in the Slicer sequence segmentation module.

We should keep in mind that most of our models will be deployed in real time. A typical ultrasound machine produces 15-25 frames/second. At the end of training script, we should add a loop that feeds a batch of (or e.g. 100) image frames to the trained model and computes the prediction (inference mode, no augmentation). We should time this and save the average, min, max times /frame.

The goal is around 20 ms inference time, to leave time in the user application for resizing images and do some UI rendering after each frame. We can save trained models with higher inference time for experimentation. But if we see much higher numbers, that should tell us to look at smaller models.

Additionally, we should check time/frame when using the trained model in Slicer, so we have an idea how much overhead it takes to also render images at the same time.

Issue with Running prepare_data.py Script

I'm currently facing an issue while running the prepare_data.py script, and I could use your expertise to resolve it.

Here's a brief overview of the problem:

I exported my segmentations from 3DSlicer in the form of two files: "_segmentation.py" and "_ultrasound.py." I've placed these two files in a folder named "SegmentationOutput" and attempted to execute the following command in my terminal:

python prepare_data.py --input_dir SegmentationOutput --output_dir PatientArrays --config_file prepare_data_config.yaml --log_file "PrepareData.log"

My problem arises from the creation of the "_indices.py" file. As per my understanding of the prepare_data.py script, the "_indices.py" file should be derived from the "_segmentation.npy" file. However, the line in the script that reads seg_filename.replace("_segmentation", "_indices") seems to only change the string that describes the path to the folder, but it does not actually create the "_indices.py" file. Even if it did, just renaming "_segmentation.py" to "_indices.py" wouldn't work because the dimensions don't match. Ideally, the "_indices.py" file should have only one dimension, but it appears to be 3D when derived from "_segmentation.py."

I would greatly appreciate your assistance in understanding how to obtain the correct "_indices.py" file or any insights on how to resolve this issue.

Thank you in advance for your support.

Add option to shuffle training data

The current dataset is great for saving memory. But using it with shuffle option is extremely slow.
Shuffling datasets would be important. The way it is now, we only use data from one patient in one batch. This makes every training step biased towards one patient. Even worse, one batch of data only contains one part of the anatomy, because they are all consecutive ultrasound images.

The fastest and most memory efficient for training would be to implement suffling in the prepare_data script. It would take slower to prepare the shuffled data, but then it could be used many times. It's not ideal in the sense that the same batches would be used in every epoch. But at least the represent a broader range of data.

Another option would be to load a set of data arrays (patients) at a time, and adding shuffling among those while in memory. The number of arrays loaded could be a parameter in the dataset class. This would create different batches in every epoch.

Dataset availability

Hi,

Is the dataset used to train the US bone segmentation networks publicly available?

If so, could you please provide me with a link?

Thanks!

Update repo description

The repo description of: "Module to export ultrasound annotations for machine learning" isn't a great fit anymore. It would be nice to update to something more relevant such as the first sentence in Readme.md. -- Requires admin privileges to change

Customize SegmentationUNet.py

Hi, I am trying to run Live US Segmentation in Slicer and have customized the loading and preprocessing of the input/output image to my training net. However, the SegmentationUNet extension is no longer visible in the Slicer modules. I am using a FlexibleUNet and Pytorch (Monai Template). How can I adapt the SegmentationUNet.py so that it is available in Slicer?

Where is the "Processes" modules?

Hi,

Thank you for developing such a wonderful software!

Inspired by a very interesting YouTube video about Spine Ultrasound Segmentation, I wanted to test with the same data as the video, but I'm suffering from errors.

I get an error with from Processes import Process, ProcessesLogic in
SlicerExtension/LiveUltrasoundAi/SegmentationUNet/SegmentationUNet.py.

Where can I get this "Processes" module?

train.py stopped logging into file and prints log in terminal

This coincides in time with the code starting to use monai. I'm not sure if the two are related. Even though the config-file argument is given and logging.basicConfig is called with the correct file name, the log output still goes to the terminal and not in the file. It would be good to debug this, because log files are best preserved in the same folder together with trained models. So we have a good record of how the model was trained.

Dataset __getitem__ cannot return None

None was being returned from the __getitem__ method of the UltrasoundDataset in the case where transform arrays were not provided, causing Pytorch to raise an error. This issue was temporarily fixed in 1a4c1dd by removing None from the method return, but there is probably a better way to handle this.

Add Sequence Segmentation module to Sequence extension

Idea from an earlier issue: #3

Probably for this it would be good to have a Sequence Segmentation module, which would help setting up segmentation sequence (synchronized with the input image sequence) and some tools to help with propagating segmentation between time points (e.g., using intensity based registration). This module could also have an export feature to save both input image sequence and corresponding segmentation.
This module should be probably in the Sequences extension.

However, in ultrasound sequences, we typically don't segment every item in the input sequence. We skip 5-10 frames between ones that we invest time in segmenting. The number of skipped frames varies within one sequence. When the ultrasound is not moving, we may skip a lot more frames.

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.