diff --git a/hd_gliomouse/__init__.py b/hd_gliomouse/__init__.py index 74b37f7..d8dbfb1 100644 --- a/hd_gliomouse/__init__.py +++ b/hd_gliomouse/__init__.py @@ -1,10 +1,10 @@ from __future__ import absolute_import from . import utils from . import paths from . import setup_hd_gliomouse print("\n########################") print("If you are using hd-bet, please cite the following papers:\n") -print("UPCOMMING\n") -print("Isensee, Fabian, et al. \"nnU-Net: Breaking the Spell on Successful Medical Image Segmentation.\" " - "arXiv preprint arXiv:1904.08128 (2019). (https://arxiv.org/abs/1904.08128)\n") +print("UPCOMING\n") +print("Isensee, Fabian, et al. \"Automated Design of Deep Learning Methods for Biomedical Image Segmentation.\" " + "arXiv preprint arXiv:1904.08128 (2020). (https://arxiv.org/abs/1904.08128)\n") diff --git a/hd_gliomouse/hd_gliomouse_predict.py b/hd_gliomouse/hd_gliomouse_predict.py index 90dbdfc..7827089 100644 --- a/hd_gliomouse/hd_gliomouse_predict.py +++ b/hd_gliomouse/hd_gliomouse_predict.py @@ -1,55 +1,47 @@ # Copyright 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from hd_gliomouse.utils import blockPrint, enablePrint blockPrint() from nnunet.inference.predict import predict_cases enablePrint() import argparse from hd_gliomouse.paths import folder_with_parameter_files from hd_gliomouse.setup_hd_gliomouse import maybe_download_weights def main(): - parser = argparse.ArgumentParser(description="This script will allow you to predict a single case with hd_glio. " - "If you have multiple cases, please use hd_glio_predict_folder (this one " + parser = argparse.ArgumentParser(description="This script will allow you to predict a single case with hd_gliomouse. " + "If you have multiple cases, please use hd_gliomouse_predict_folder (this one " "will be substantially faster for multiple cases because we can " - "interleave preprocessing, GPU prediction and nifti export." - "\n" - "IMPORTANT!\n" - "The input files must be brain extracted with the non-brain region being " - "0 (you can achieve that by using hd-bet " - "(https://github.com/MIC-DKFZ/HD-BET). Furthermore, the input files " - "must be co-registered and in the same co-ordinate system (pixels " - "arrays must be aligned)\n" - "All input files must be niftis (.nii.gz)") + "interleave preprocessing, GPU prediction and nifti export.") parser.add_argument("-i", type=str, required=True, help="input file") parser.add_argument("-o", "--output_file", type=str, required=True, help="output filename. Must end with .nii.gz") args = parser.parse_args() inp = args.i output_file = args.output_file maybe_download_weights() predict_cases(folder_with_parameter_files, [[inp, ]], [output_file], (0, 1, 2, 3, 4), False, 1, 1, None, True, None, True) if __name__ == "__main__": main() diff --git a/hd_gliomouse/hd_gliomouse_predict_folder.py b/hd_gliomouse/hd_gliomouse_predict_folder.py index a7dffd3..2760220 100644 --- a/hd_gliomouse/hd_gliomouse_predict_folder.py +++ b/hd_gliomouse/hd_gliomouse_predict_folder.py @@ -1,60 +1,60 @@ # Copyright 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from batchgenerators.utilities.file_and_folder_operations import subfiles, join from hd_gliomouse.utils import blockPrint, enablePrint blockPrint() from nnunet.inference.predict import predict_cases enablePrint() import argparse from hd_gliomouse.paths import folder_with_parameter_files from hd_gliomouse.setup_hd_gliomouse import maybe_download_weights def main(): parser = argparse.ArgumentParser() parser.add_argument("-i", "--input_folder", type=str, required=True, help="folder with input files. All .nii.gz files in this folder will be processed.") parser.add_argument("-o", "--output_folder", type=str, required=True, help="output folder. This is there the resulting segmentations will be saved. Cannot be the " "same folder as the input folder. If output_folder does not exist " "it will be created") parser.add_argument("-p", "--processes", default=4, type=str, required=False, help="number of processes for data preprocessing and nifti export. You should not have to " "touch this. So don't unless there is a clear indication that it is required. Default: 4") - parser.add_argument('--overwrite_existing', default=True, type=str, required=False, + parser.add_argument('--keep_existing', default=True, type=str, required=False, action='store_false', help="set to False to keep segmentations in output_folder and continue where you left off " - "(useful if something crashes). If True then all segmentations that may already be " - "present in output_folder will be overwritten. Default: True") + "(useful if something crashes). If this flag is not set, all segmentations that may " + "already be present in output_folder will be overwritten.") args = parser.parse_args() input_folder = args.input_folder output_folder = args.output_folder processes = args.processes - overwrite_existing = args.overwrite_existing + keep_existing = args.keep_existing maybe_download_weights() # we must generate a list of input filenames nii_files = subfiles(input_folder, suffix='.nii.gz', join=False) input_list_of_lists = [[join(input_folder, i)] for i in nii_files] output_filenames = [join(output_folder, i) for i in nii_files] predict_cases(folder_with_parameter_files, input_list_of_lists, output_filenames, (0, 1, 2, 3, 4), False, processes, - processes, None, True, None, overwrite_existing, False, 2, None, 3, 0) + processes, None, True, None, not keep_existing, False, 2, None, 3, 0) if __name__ == "__main__": main() diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..3e1789d --- /dev/null +++ b/readme.md @@ -0,0 +1,31 @@ +# Installation instructions +## Installation requirements +hd-gliomouse only runs on Linux. You need a pytorch capable GPU with 4GB of GPU memory to run hd-gliomouse. + +1) We strongly recommend you install hd-gliomouse in a separate python virtual environment. [Here is a quick how-to for Ubuntu.](https://linoxide.com/linux-how-to/setup-python-virtual-environment-ubuntu/) +2) Once you set up the environment (and activated it), install hd-gliomouse with pip: `pip install hd_gliomouse` - Done + +This will install hd_gliomouse commands directly onto your system. You can use them from anywhere. + +# Usage + +## Run hd-gliomouse +hd-gliomouse provides two main scripts: `hd_gliomouse_predict` and `hd_gliomouse_predict_folder`. + +### Predicting a single case +`hd_gliomouse_predict` can be used to predict a single image. It is useful for exploration or if the number of cases +to be procesed is low. Here is how to use it: + +`hd_gliomouse_predict -i INPUT_FILE -o OUTPUT_FILE` + +INPUT_FILE and OUTPUT_FILE must be a niftis (end with .nii.gz). + +### Predicting multiple cases +`hd_gliomouse_predict_folder` is useful for batch processing, especially if the number of cases to be processed is large. By +interleaving preprocessing, inference and segmentation export we can speed up the prediction significantly. Furthermore, +the pipeline is initialized only once for all cases, again saving a lot of computation and I/O time. Here is how to use it: + +`hd_gliomouse_predict_folder -i INPUT_FOLDER -o OUTPUT_FOLDER` + +INPUT_FOLDER must contain nifti images (.nii.gz). The results will be written to the OUTPUT_FOLDER (with the same file names). + If the output folder does not exist it will be created. \ No newline at end of file