monai
medical
File size: 3,088 Bytes
a23faaa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
{
    "imports": [
        "$import json",
        "$import os",
        "$import torch"
    ],
    "bundle_root": "/workspace/bundle/endoscopic_inbody_classification",
    "output_dir": "$@bundle_root + '/eval'",
    "dataset_dir": "/workspace/data/endoscopic_inbody_classification",
    "test_json": "$@dataset_dir+'/test.json'",
    "test_fp": "$open(@test_json,'r', encoding='utf8')",
    "test_dict": "$json.load(@test_fp)",
    "test_close": "$@test_fp.close()",
    "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"
            },
            {
                "_target_": "AsChannelFirstd",
                "keys": "image"
            },
            {
                "_target_": "Resized",
                "keys": "image",
                "spatial_size": [
                    256,
                    256
                ],
                "mode": "bilinear"
            },
            {
                "_target_": "CastToTyped",
                "dtype": "$torch.float32",
                "keys": "image"
            },
            {
                "_target_": "NormalizeIntensityd",
                "nonzero": true,
                "channel_wise": true,
                "keys": "image"
            },
            {
                "_target_": "EnsureTyped",
                "keys": "image"
            }
        ]
    },
    "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"
                ]
            }
        ]
    },
    "handlers": [
        {
            "_target_": "CheckpointLoader",
            "load_path": "$@bundle_root + '/models/model.pt'",
            "load_dict": {
                "model": "@network"
            }
        },
        {
            "_target_": "StatsHandler",
            "iteration_log": true
        }
    ],
    "evaluator": {
        "_target_": "SupervisedEvaluator",
        "device": "@device",
        "val_data_loader": "@dataloader",
        "network": "@network",
        "inferer": "@inferer",
        "postprocessing": "@postprocessing",
        "val_handlers": "@handlers"
    },
    "evaluating": [
        "$setattr(torch.backends.cudnn, 'benchmark', True)",
        "$@evaluator.run()"
    ]
}