-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfer_isic17.py
92 lines (74 loc) · 2.67 KB
/
infer_isic17.py
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
import torch
from torch.utils.data import DataLoader
import timm
from datasets.dataset import NPY_datasets
from tensorboardX import SummaryWriter
from models.CCViMUNet.CCViMUNet import LCVMUNet
from engine import *
import os
import sys
from utils import *
from configs.config_setting_isic17 import setting_config
import warnings
warnings.filterwarnings("ignore")
def main(config):
print('#----------Creating logger----------#')
sys.path.append(config.work_dir + '/')
log_dir = os.path.join(config.work_dir, 'log')
checkpoint_dir = os.path.join(config.work_dir, 'checkpoints')
outputs = os.path.join(config.work_dir, 'outputs')
if not os.path.exists(checkpoint_dir):
os.makedirs(checkpoint_dir)
if not os.path.exists(outputs):
os.makedirs(outputs)
global logger
logger = get_logger('train', log_dir)
global writer
writer = SummaryWriter(config.work_dir + 'summary')
log_config_info(config, logger)
print('#----------GPU init----------#')
os.environ["CUDA_VISIBLE_DEVICES"] = config.gpu_id
set_seed(config.seed)
torch.cuda.empty_cache()
print('#----------Preparing dataset----------#')
val_dataset = NPY_datasets(config.data_path, config, train=False)
val_loader = DataLoader(val_dataset,
batch_size=1,
shuffle=False,
pin_memory=True,
num_workers=config.num_workers,
drop_last=True)
print('#----------Prepareing Model----------#')
model_cfg = config.model_config
if config.network == 'CCViM_isic17':
model = LCVMUNet(
num_classes=model_cfg['num_classes'],
input_channels=model_cfg['input_channels'],
depths=model_cfg['depths'],
depths_decoder=model_cfg['depths_decoder'],
drop_path_rate=model_cfg['drop_path_rate'],
load_ckpt_path=model_cfg['load_ckpt_path'],
)
model_weight = torch.load("./pre_trained_weights/isic17.pth")
model.load_state_dict(model_weight, strict=False)
else:
raise Exception('network in not right!')
model = model.cuda()
cal_params_flops(model, 256, logger)
print('#----------Prepareing loss, opt, sch and amp----------#')
criterion = config.criterion
optimizer = get_optimizer(config, model)
scheduler = get_scheduler(config, optimizer)
print('#----------validate----------#')
torch.cuda.empty_cache()
loss, miou = val_one_epoch(
val_loader,
model,
criterion,
0,
logger,
config
)
if __name__ == '__main__':
config = setting_config
main(config)