| { | |
| "imports": [ | |
| "$import json", | |
| "$import os", | |
| "$import numpy", | |
| "$import torch" | |
| ], | |
| "bundle_root": ".", | |
| "image_key": "image", | |
| "load_pretrain": true, | |
| "output_dir": "$@bundle_root + '/eval'", | |
| "output_filename": "predictions.csv", | |
| "dataset_dir": "/workspace/data/endoscopic_inbody_classification", | |
| "test_json": "$@bundle_root+'/label/test_samples.json'", | |
| "test_fp": "$open(@test_json,'r', encoding='utf8')", | |
| "test_dict": "$json.load(@test_fp)", | |
| "device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')", | |
| "network_def": { | |
| "_target_": "SEResNet50", | |
| "spatial_dims": 2, | |
| "in_channels": 3, | |
| "num_classes": 2 | |
| }, | |
| "network": "$@network_def.to(@device)", | |
| "preprocessing": { | |
| "_target_": "Compose", | |
| "transforms": [ | |
| { | |
| "_target_": "LoadImaged", | |
| "keys": "@image_key", | |
| "image_only": false | |
| }, | |
| { | |
| "_target_": "EnsureChannelFirstd", | |
| "keys": "@image_key", | |
| "channel_dim": -1 | |
| }, | |
| { | |
| "_target_": "Resized", | |
| "keys": "@image_key", | |
| "spatial_size": [ | |
| 256, | |
| 256 | |
| ], | |
| "mode": "bilinear" | |
| }, | |
| { | |
| "_target_": "CastToTyped", | |
| "dtype": "$torch.float32", | |
| "keys": "@image_key" | |
| }, | |
| { | |
| "_target_": "NormalizeIntensityd", | |
| "nonzero": true, | |
| "channel_wise": true, | |
| "keys": "@image_key" | |
| }, | |
| { | |
| "_target_": "EnsureTyped", | |
| "keys": "@image_key" | |
| } | |
| ] | |
| }, | |
| "dataset": { | |
| "_target_": "Dataset", | |
| "data": "@test_dict", | |
| "transform": "@preprocessing" | |
| }, | |
| "dataloader": { | |
| "_target_": "DataLoader", | |
| "dataset": "@dataset", | |
| "batch_size": 1, | |
| "shuffle": false, | |
| "num_workers": 4 | |
| }, | |
| "inferer": { | |
| "_target_": "SimpleInferer" | |
| }, | |
| "postprocessing": { | |
| "_target_": "Compose", | |
| "transforms": [ | |
| { | |
| "_target_": "AsDiscreted", | |
| "argmax": true, | |
| "to_onehot": 2, | |
| "keys": [ | |
| "pred" | |
| ] | |
| }, | |
| { | |
| "_target_": "SaveClassificationd", | |
| "keys": "pred", | |
| "meta_keys": "$@image_key + '_meta_dict'", | |
| "output_dir": "@output_dir", | |
| "filename": "@output_filename" | |
| } | |
| ] | |
| }, | |
| "handlers": [ | |
| { | |
| "_target_": "StatsHandler", | |
| "iteration_log": true | |
| } | |
| ], | |
| "evaluator": { | |
| "_target_": "SupervisedEvaluator", | |
| "device": "@device", | |
| "val_data_loader": "@dataloader", | |
| "network": "@network", | |
| "inferer": "@inferer", | |
| "postprocessing": "@postprocessing", | |
| "val_handlers": "@handlers" | |
| }, | |
| "checkpointloader": { | |
| "_target_": "CheckpointLoader", | |
| "load_path": "$@bundle_root + '/models/model.pt'", | |
| "load_dict": { | |
| "model": "@network" | |
| } | |
| }, | |
| "initialize": [ | |
| "$monai.utils.set_determinism(seed=123)", | |
| "$@checkpointloader(@evaluator) if @load_pretrain else None" | |
| ], | |
| "run": [ | |
| "$@evaluator.run()" | |
| ], | |
| "finalize": [ | |
| "$@test_fp.close()" | |
| ] | |
| } | |