-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvaild.py
More file actions
66 lines (52 loc) · 1.91 KB
/
Copy pathvaild.py
File metadata and controls
66 lines (52 loc) · 1.91 KB
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
# -*- coding: utf-8 -*-
# Author : Li Chongyang of ACTL
# Email : lichongyang2016@163.com
# Date : 2024-07-11 08:14:27
# LastEditors : Li Chongyang of ACTL
# LastEditTime : 2024-07-12 09:30:17
# FilePath : \VM-UNet-main\test.py
import os
import torch
from models.mamba_vision import MVSC
from models.distortion import *
from classify_net import ResNet8
from engine import *
import os
from utils.datasets import *
from utils.utils import *
from configs.config import setting_config
import warnings
warnings.filterwarnings("ignore")
def main(config):
print('#----------GPU init----------#')
os.environ["CUDA_VISIBLE_DEVICES"] = config.gpu_id
set_seed(config.seed)
torch.cuda.empty_cache()
print('#----------Preparing dataset----------#')
train_loader, val_loader, test_loader = get_loader(config)
print('#----------Prepareing Model----------#')
sc_model = MVSC(config)
sc_model = sc_model.cuda()
cl_model = ResNet8({'in_channels': 3, 'out_channels': 10, 'activation': 'relu'})
cl_model = cl_model.cuda()
print('#----------Prepareing loss, opt, sch and amp----------#')
psnr_crit = config.psnr_crit
config.work_dir = 'results/' + 'CIFAR10_2024-09-03_11-00-40' + '/'
log_dir = os.path.join(config.work_dir, 'log')
logger = get_logger('train', log_dir)
if os.path.exists(os.path.join(config.work_dir, 'checkpoints/best.pth')):
print('#----------Testing----------#')
best_weight = torch.load(config.work_dir + 'checkpoints/best.pth')
sc_model.load_state_dict(best_weight,strict=False)
cl_model.load_state_dict(torch.load('classify.pth'))
psnr = val_one_epoch(
train_loader,
sc_model,
psnr_crit,
1,
logger,
config
)
if __name__ == '__main__':
config = setting_config
main(config)