1 Star 0 Fork 0

desperadoxhy/SAM-Adapt

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
val_hrf.py 3.60 KB
一键复制 编辑 原始数据 按行查看 历史
desperadoxhy 提交于 2024-05-29 00:54 . Remove .DS_Store files
# 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'])
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/xuhengyuplus/SAM-Adapt.git
[email protected]:xuhengyuplus/SAM-Adapt.git
xuhengyuplus
SAM-Adapt
SAM-Adapt
multout

搜索帮助