-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from andreped/dev
Implemented working demo
- Loading branch information
Showing
9 changed files
with
120 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
venv/ | ||
*__pycache__/ | ||
resources/ | ||
*.DS_Store | ||
*.nii | ||
*.nii.gz | ||
*.nrrd | ||
*.obj | ||
*log.csv | ||
*.ini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
venv/ | ||
*__pycache__/ | ||
resources/ | ||
*.DS_Store | ||
*.nii | ||
*.nii.gz | ||
*.nrrd | ||
*.obj | ||
*log.csv | ||
*.ini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import os | ||
import shutil | ||
import configparser | ||
import logging | ||
import traceback | ||
|
||
|
||
def run_model(input_path: str, model_path: str, verbose: str = "info", task: str = "MRI_Meningioma"): | ||
logging.basicConfig() | ||
logging.getLogger().setLevel(logging.WARNING) | ||
|
||
if verbose == 'debug': | ||
logging.getLogger().setLevel(logging.DEBUG) | ||
elif verbose == 'info': | ||
logging.getLogger().setLevel(logging.INFO) | ||
elif verbose == 'error': | ||
logging.getLogger().setLevel(logging.ERROR) | ||
else: | ||
raise ValueError("Unsupported verbose value provided:", verbose) | ||
|
||
# create sequence folder, rename patient, and add to temporary patient directory | ||
filename = input_path.split("/")[-1] | ||
splits = filename.split(".") | ||
extension = ".".join(splits[1:]) | ||
patient_directory = "./patient/" | ||
os.makedirs(patient_directory + "T0/", exist_ok=True) | ||
shutil.copy(input_path, patient_directory + "T0/" + splits[0] + "-t1gd." + extension) | ||
|
||
# define output directory to save results | ||
output_path = "./result/prediction-" + splits[0] + "/" | ||
os.makedirs(output_path, exist_ok=True) | ||
|
||
# Setting up the configuration file | ||
rads_config = configparser.ConfigParser() | ||
rads_config.add_section('Default') | ||
rads_config.set('Default', 'task', 'neuro_diagnosis') | ||
rads_config.set('Default', 'caller', '') | ||
rads_config.add_section('System') | ||
rads_config.set('System', 'gpu_id', "-1") | ||
rads_config.set('System', 'input_folder', patient_directory) | ||
rads_config.set('System', 'output_folder', output_path) | ||
rads_config.set('System', 'model_folder', model_path) | ||
rads_config.set('System', 'pipeline_filename', os.path.join(model_path, task, 'pipeline.json')) | ||
rads_config.add_section('Runtime') | ||
rads_config.set('Runtime', 'reconstruction_method', 'thresholding') # thresholding, probabilities | ||
rads_config.set('Runtime', 'reconstruction_order', 'resample_first') | ||
rads_config.set('Runtime', 'use_preprocessed_data', 'False') | ||
|
||
with open("rads_config.ini", "w") as f: | ||
rads_config.write(f) | ||
|
||
# finally, run inference | ||
from raidionicsrads.compute import run_rads | ||
|
||
try: | ||
run_rads(config_filename='rads_config.ini') | ||
except Exception as e: | ||
print(e) | ||
|
||
# rename and move final result | ||
os.rename("./result/prediction-" + splits[0] + "/T0/" + splits[0] + "-t1gd_annotation-Tumor.nii.gz", "./prediction.nii.gz") | ||
|
||
# Clean-up | ||
if os.path.exists(patient_directory): | ||
shutil.rmtree(patient_directory) | ||
if os.path.exists(output_path): | ||
shutil.rmtree(output_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
raidionicsrads @ https://github.com/dbouget/raidionics_rads_lib/releases/download/v1.1.0/raidionicsrads-1.1.0-py3-none-manylinux1_x86_64.whl | ||
onnxruntime-gpu==1.12.1 | ||
#raidionicsrads @ https://github.com/dbouget/raidionics_rads_lib/releases/download/v1.1.0/raidionicsrads-1.1.0-py3-none-macosx_10_15_x86_64.whl | ||
gradio==3.32.0 |