代码拉取完成,页面将自动刷新
# train.py
#!/usr/bin/env python3
""" valuate network using pytorch
Junde Wu
"""
import os
import sys
import argparse
from datetime import datetime
from collections import OrderedDict
import numpy as np
import torch
import torch.nn as nn
import torch.optim as optim
from sklearn.metrics import roc_auc_score, accuracy_score,confusion_matrix
import torchvision
import torchvision.transforms as transforms
from skimage import io
from torch.utils.data import DataLoader
#from dataset import *
from torch.autograd import Variable
from PIL import Image
from tensorboardX import SummaryWriter
#from models.discriminatorlayer import discriminator
from dataset import *
from conf import settings
import time
import cfg
from tqdm import tqdm
from torch.utils.data import DataLoader, random_split
from union import get_test_results, get_test_mult_results
from utils import *
import function
GPUdevice = torch.device('cuda', args.gpu_device)
net = get_network(args, args.net, use_gpu=args.gpu, gpu_device=GPUdevice, distribution=args.distributed)
'''load pretrained model'''
assert args.weights != 0
print(f'=> resuming from {args.weights}')
assert os.path.exists(args.weights)
checkpoint_file = os.path.join(args.weights)
print(checkpoint_file)
assert os.path.exists(checkpoint_file)
loc = 'cuda:{}'.format(args.gpu_device)
checkpoint = torch.load(checkpoint_file, map_location=loc)
start_epoch = checkpoint['epoch']
best_tol = checkpoint['best_tol']
state_dict = checkpoint['state_dict']
if args.distributed != 'none':
from collections import OrderedDict
new_state_dict = OrderedDict()
for k, v in state_dict.items():
# name = k[7:] # remove `module.`
name = 'module.' + k
new_state_dict[name] = v
# load params
else:
new_state_dict = state_dict
net.load_state_dict(new_state_dict)
args.path_helper = set_log_dir('logs', args.exp_name)
logger = create_logger(args.path_helper['log_path'])
logger.info(args)
'''segmentation data'''
transform_train = transforms.Compose([
transforms.Resize((args.image_size,args.image_size)),
transforms.ToTensor(),
])
transform_train_seg = transforms.Compose([
transforms.Resize((args.out_size,args.out_size)),
transforms.ToTensor(),
])
if args.net == 'sam':
prompt = 'click'
elif args.net == 'sam_lite':
prompt = 'noprompt'
train_dataset = HRFRGB(args, data_path="HRFdatabaseslice/train", transform=transform_train,
transform_msk=transform_train_seg)
test_dataset = HRFRGB(args, data_path="HRFdatabaseslice/test", transform=transform_train,
transform_msk=transform_train_seg)
nice_train_loader = DataLoader(train_dataset, batch_size=args.b, num_workers=8, shuffle=True, pin_memory=True)
nice_test_loader = DataLoader(test_dataset, batch_size=args.b, num_workers=8, shuffle=False, pin_memory=True)
'''begain valuation'''
best_acc = 0.0
best_tol = 1e4
print(args.distributed)
if args.mod == 'sam_adpt':
net.eval()
fake_prompt = np.load('fake_prompt.npz')
tol, (eiou1, edice1), (eiou2, edice2), (eiou3, edice3) = function.validation_mult_sam_lite(args, nice_test_loader, start_epoch, net, get_mask=True, fake_prompt=fake_prompt)
logger.info(
f'T测试集平均loss: {tol}, 平均IOU: {eiou1},{eiou2},{eiou3} 平均DICE: {edice1}, {edice2}, {edice3}')
# get_test_mult_results(args.path_helper['mask_path'], GPUdevice, 'vessel', args.path_helper['result_path'])
# get_test_mult_results(args.path_helper['mask_path'], GPUdevice, 'arteriole', args.path_helper['result_path'])
# get_test_mult_results(args.path_helper['mask_path'], GPUdevice, 'venule', args.path_helper['result_path'])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。