| { | |
| "imports": [ | |
| "$import glob", | |
| "$import numpy", | |
| "$import json", | |
| "$import pathlib", | |
| "$import os" | |
| ], | |
| "bundle_root": ".", | |
| "image_key": "image", | |
| "output_dir": "$@bundle_root + '/eval'", | |
| "output_ext": ".png", | |
| "output_dtype": "$numpy.float32", | |
| "output_postfix": "trans", | |
| "separate_folder": true, | |
| "load_pretrain": true, | |
| "dataset_dir": "/workspace/data/CoNSePNuclei", | |
| "images": "$list(sorted(glob.glob(@dataset_dir + '/Test/Images/*.png')))[:1]", | |
| "centroids": "$list(sorted(glob.glob(@dataset_dir + '/Test/Centroids/*.txt')))[:1]", | |
| "input_data": "$[{'image': i, 'foreground': json.loads(pathlib.Path(c).read_text())} for i,c in zip(@images, @centroids)]", | |
| "device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')", | |
| "network_def": { | |
| "_target_": "BasicUNet", | |
| "spatial_dims": 2, | |
| "in_channels": 5, | |
| "out_channels": 1, | |
| "features": [ | |
| 32, | |
| 64, | |
| 128, | |
| 256, | |
| 512, | |
| 32 | |
| ] | |
| }, | |
| "network": "$@network_def.to(@device)", | |
| "preprocessing": { | |
| "_target_": "Compose", | |
| "transforms": [ | |
| { | |
| "_target_": "LoadImaged", | |
| "keys": "@image_key", | |
| "dtype": "uint8", | |
| "image_only": false | |
| }, | |
| { | |
| "_target_": "EnsureChannelFirstd", | |
| "keys": "@image_key" | |
| }, | |
| { | |
| "_target_": "ScaleIntensityRanged", | |
| "keys": "@image_key", | |
| "a_min": 0.0, | |
| "a_max": 255.0, | |
| "b_min": -1.0, | |
| "b_max": 1.0 | |
| }, | |
| { | |
| "_target_": "AddClickSignalsd", | |
| "image": "@image_key", | |
| "foreground": "foreground", | |
| "gaussian": false | |
| }, | |
| { | |
| "_target_": "SqueezeDimd", | |
| "keys": "@image_key" | |
| } | |
| ] | |
| }, | |
| "dataset": { | |
| "_target_": "Dataset", | |
| "data": "@input_data", | |
| "transform": "@preprocessing" | |
| }, | |
| "dataloader": { | |
| "_target_": "DataLoader", | |
| "dataset": "@dataset", | |
| "batch_size": 1, | |
| "shuffle": false, | |
| "num_workers": 4 | |
| }, | |
| "inferer": { | |
| "_target_": "SimpleInferer" | |
| }, | |
| "postprocessing": { | |
| "_target_": "Compose", | |
| "transforms": [ | |
| { | |
| "_target_": "Activationsd", | |
| "keys": "pred", | |
| "sigmoid": true | |
| }, | |
| { | |
| "_target_": "AsDiscreted", | |
| "keys": "pred", | |
| "threshold": 0.5 | |
| }, | |
| { | |
| "_target_": "KeepLargestConnectedComponentd", | |
| "keys": "pred" | |
| }, | |
| { | |
| "_target_": "SaveImaged", | |
| "keys": "pred", | |
| "meta_keys": "pred_meta_dict", | |
| "output_dir": "@output_dir", | |
| "output_ext": "@output_ext", | |
| "output_dtype": "@output_dtype", | |
| "output_postfix": "@output_postfix", | |
| "separate_folder": "@separate_folder" | |
| } | |
| ] | |
| }, | |
| "handlers": [ | |
| { | |
| "_target_": "StatsHandler", | |
| "iteration_log": false | |
| } | |
| ], | |
| "evaluator": { | |
| "_target_": "SupervisedEvaluator", | |
| "device": "@device", | |
| "val_data_loader": "@dataloader", | |
| "network": "@network", | |
| "inferer": "@inferer", | |
| "postprocessing": "@postprocessing", | |
| "val_handlers": "@handlers", | |
| "amp": true | |
| }, | |
| "checkpointloader": { | |
| "_target_": "CheckpointLoader", | |
| "load_path": "$@bundle_root + '/models/model.pt'", | |
| "load_dict": { | |
| "model": "@network" | |
| } | |
| }, | |
| "initialize": [ | |
| "$import sys", | |
| "$sys.path.append(@bundle_root)", | |
| "$monai.utils.set_determinism(seed=123)", | |
| "$@checkpointloader(@evaluator) if @load_pretrain else None" | |
| ], | |
| "run": [ | |
| "$@evaluator.run()" | |
| ] | |
| } | |