-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest.py
36 lines (28 loc) · 1.11 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
import torch
import argparse
from torch.utils.data import DataLoader
from load_dataset import Load_Dataset
from validation import val_multi
import glob
from LWANet import LWANet
from focalloss import FocalLoss
# os.environ["CUDA_VISIBLE_DEVICES"] = "3"
device_ids = [0]
parse=argparse.ArgumentParser()
weight_load = 'Logs/T20200911_211620/weights_7.pth'
num_classes=11
def test():
device = torch.device("cpu")
model = LWANet(num_classes=num_classes, pretrained=True)
model.load_state_dict({k.replace('module.', ''): v for k, v in torch.load(weight_load, map_location=device).items()})
model=model.cuda(device_ids[0])
criterion = FocalLoss(gamma=6)
val_file_names = glob.glob('dataset/test/images/*.png')
val_dataset = Load_Dataset(val_file_names)
val_loader = DataLoader(val_dataset, batch_size=args.batch_size,num_workers=16)
val_multi(model, criterion, val_loader, num_classes,batch_size=args.batch_size,device_ids=device_ids)
if __name__ == '__main__':
parse = argparse.ArgumentParser()
parse.add_argument("--batch_size", type=int, default=8)
args = parse.parse_args()
test()