From f7fca4fec1640c300ebe8c59b139e06f778ad110 Mon Sep 17 00:00:00 2001 From: Alexander Getka Date: Wed, 25 Sep 2024 17:32:10 -0400 Subject: [PATCH 1/2] Add cache-clear, add longpath note to README --- DLICV/__main__.py | 33 +++++++++++++++++++++++++++++++++ README.md | 7 +++++++ 2 files changed, 40 insertions(+) diff --git a/DLICV/__main__.py b/DLICV/__main__.py index c259f85..fb7d10b 100644 --- a/DLICV/__main__.py +++ b/DLICV/__main__.py @@ -161,10 +161,33 @@ def main() -> None: help="Set this flag to disable progress bar. Recommended for HPC environments (non interactive " "jobs)", ) + parser.add_argument( + "--clear_cache", + action="store_true", + required=False, + default=False, + help="Set this flag to clear any cached models before running. This is recommended if a previous download failed." + ) args = parser.parse_args() args.f = [0] + if args.clear_cache: + shutil.rmtree(os.path.join( + Path(__file__).parent, + "nnunet_results" + )) + shutil.rmtree(os.path.join( + Path(__file__).parent, + ".cache" + )) + if not args.input or not args.output: + print("Cache cleared and missing either -i / -o. Exiting.") + sys.exit(0) + + if not args.input or not args.output: + parser.error("The following arguments are required: -i, -o") + # data conversion src_folder = args.i # input folder if not os.path.exists(args.o): # create output folder if it does not exist @@ -189,6 +212,16 @@ def main() -> None: % (args.d, args.d), ) + if args.clear_cache: + shutil.rmtree(os.path.join( + Path(__file__).parent, + "nnunet_results" + )) + shutil.rmtree(os.path.join( + Path(__file__).parent, + ".cache" + )) + # Check if model exists. If not exist, download using HuggingFace if not os.path.exists(model_folder): # HF download model diff --git a/README.md b/README.md index c299c2b..c8ab406 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,13 @@ Feel free to use it under the package's [licence](LICENCE) DLICV -i "input_folder" -o "output_folder" -device cpu ``` +#### Troubleshooting model download failures +Our model download process creates several deep directory structures. If you are on Windows and your model download process fails, it may be due to Windows file path limitations. + +To enable long path support in Windows 10, version 1607, and later, the registry key `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem LongPathsEnabled (Type: REG_DWORD)` must exist and be set to 1. + +If this affects you, we recommend re-running DLICV with the `--clear_cache` flag set on the first run. + ## Contact For more information, please contact [CBICA Software](mailto:software@cbica.upenn.edu). From 9122954d15673e245c921ea9df71c913bfa848a6 Mon Sep 17 00:00:00 2001 From: KyleB Date: Thu, 26 Sep 2024 10:55:51 -0400 Subject: [PATCH 2/2] some bug fixes with cleaning for main --- DLICV/__main__.py | 67 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 20 deletions(-) diff --git a/DLICV/__main__.py b/DLICV/__main__.py index fb7d10b..ffab865 100644 --- a/DLICV/__main__.py +++ b/DLICV/__main__.py @@ -12,26 +12,62 @@ warnings.simplefilter(action="ignore", category=FutureWarning) warnings.simplefilter(action="ignore", category=UserWarning) +# VERSION = pkg_resources.require("NiChart_DLMUSE")[0].version +VERSION = 1.0 def main() -> None: + prog="DLICV" parser = argparse.ArgumentParser( - description="Use this to run inference with nnU-Net. This function is used when " - "you want to manually specify a folder containing a trained nnU-Net " - "model. This is useful when the nnunet environment variables " - "(nnUNet_results) are not set." + prog=prog, + description="DLICV - Deep Learning Intra Cranial Volume.", + usage = """ + DLICV v{VERSION} + ICV calculation for structural MRI data. + + Required arguments: + [-i, --in_dir] The filepath of the input directory + [-o, --out_dir] The filepath of the output directory + Optional arguments: + [-device] cpu|cuda|mps - Depending on your system configuration (default: cuda) + [-h, --help] Show this help message and exit. + [-V, --version] Show program's version number and exit. + EXAMPLE USAGE: + DLICV -i /path/to/input \ + -o /path/to/output \ + -device cpu|cuda|mps + + """.format(VERSION=VERSION), ) + + # Required Arguments parser.add_argument( "-i", type=str, required=True, - help="input folder or list or image (nii.gz). Remember to use the correct channel numberings for your files (_0000 etc). File endings must be the same as the training dataset!", + help="[REQUIRED] Input folder with T1 sMRI images (nii.gz).", ) parser.add_argument( "-o", type=str, required=True, - help="Output folder. If it does not exist it will be created. Predicted segmentations will " - "have the same name as their source images.", + help="[REQUIRED] Output folder. If it does not exist it will be created. Predicted segmentations will have the same name as their source images.", + ) + + # Optional Arguments + parser.add_argument( + "-device", + type=str, + default="cuda", + required=False, + help="[Recommended] Use this to set the device the inference should run with. Available options are 'cuda' (GPU), " + "'cpu' (CPU) or 'mps' (Apple M-series chips supporting 3D CNN).", + ) + parser.add_argument( + "-V", + "--version", + action="version", + version=prog + ": v{VERSION}.".format(VERSION=VERSION), + help="Show the version and exit", ) parser.add_argument( "-d", @@ -144,15 +180,6 @@ def main() -> None: "5 and use -part_id 0, 1, 2, 3 and 4. Simple, right? Note: You are yourself responsible " "to make these run on separate GPUs! Use CUDA_VISIBLE_DEVICES (google, yo!)", ) - parser.add_argument( - "-device", - type=str, - default="cuda", - required=False, - help="Use this to set the device the inference should run with. Available options are 'cuda' (GPU), " - "'cpu' (CPU) or 'mps' (Apple M-series chips supporting 3D CNN)." - "Use CUDA_VISIBLE_DEVICES=X nnUNetv2_predict [...] instead!", - ) parser.add_argument( "--disable_progress_bar", action="store_true", @@ -166,7 +193,7 @@ def main() -> None: action="store_true", required=False, default=False, - help="Set this flag to clear any cached models before running. This is recommended if a previous download failed." + help="Set this flag to clear any cached models before running. This is recommended if a previous download failed.", ) args = parser.parse_args() @@ -181,11 +208,11 @@ def main() -> None: Path(__file__).parent, ".cache" )) - if not args.input or not args.output: + if not args.i or not args.o: print("Cache cleared and missing either -i / -o. Exiting.") sys.exit(0) - if not args.input or not args.output: + if not args.i or not args.o: parser.error("The following arguments are required: -i, -o") # data conversion @@ -313,7 +340,7 @@ def main() -> None: if os.path.exists(des_folder): shutil.rmtree(des_folder) - print("Inference Process Done!") + print("DLICV Process Done!") if __name__ == "__main__":