-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
72 lines (60 loc) · 2.3 KB
/
test.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
import torch
from torch.utils.data import DataLoader
from datasets.dataset import NPY_datasets
from tensorboardX import SummaryWriter
from models.lbunet import LBUNet
from engine import *
import os
from utils import *
from configs.config_setting import setting_config
import warnings
warnings.filterwarnings("ignore")
def main(config):
config.work_dir = '/data1/xujiahao/Project/LB-UNet/'
log_dir = os.getcwd()
global logger
logger = get_logger('test', log_dir)
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----------#')
train_dataset = NPY_datasets(config.data_path, config, train=True)
train_loader = DataLoader(train_dataset,
batch_size=config.batch_size,
shuffle=True,
pin_memory=True,
num_workers=config.num_workers)
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=False)
print('#----------Prepareing Model----------#')
model_cfg = config.model_config
if config.network == 'lbunet':
model = LBUNet(num_classes=model_cfg['num_classes'],
input_channels=model_cfg['input_channels'],
c_list=model_cfg['c_list'],
)
else: raise Exception('network in not right!')
model = model.cuda()
input_path = ''
if os.path.exists(input_path):
print('#----------Testing----------#')
best_weight = torch.load(input_path, map_location=torch.device('cpu'))
model.load_state_dict(best_weight)
test_one_epoch(
val_loader,
model,
config.criterion,
logger,
config,
path = 'ultimate'
)
if __name__ == '__main__':
config = setting_config
main(config)