1 Star 1 Fork 0

HaixiongLi/selfreformer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test_f3.py 2.26 KB
一键复制 编辑 原始数据 按行查看 历史
HaixiongLi 提交于 2022-11-27 20:11 . save metric
#!/usr/bin/python3
#coding=utf-8
import os
import sys
sys.path.insert(0, '../')
sys.dont_write_bytecode = True
import cv2
import numpy as np
import matplotlib.pyplot as plt
plt.ion()
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.data import DataLoader
from tensorboardX import SummaryWriter
import dataset
from net import F3Net
class Test(object):
def __init__(self, Dataset, Network, path):
## dataset
self.cfg = Dataset.Config(datapath=path, snapshot='./out/model-32', mode='test')
self.data = Dataset.Data(self.cfg)
self.loader = DataLoader(self.data, batch_size=1, shuffle=False, num_workers=8)
## network
self.net = Network(self.cfg)
self.net.train(False)
self.net.cuda()
def show(self):
with torch.no_grad():
for image, mask, shape, name in self.loader:
image, mask = image.cuda().float(), mask.cuda().float()
out1u, out2u, out2r, out3r, out4r, out5r = self.net(image)
out = out2u
plt.subplot(221)
plt.imshow(np.uint8(image[0].permute(1,2,0).cpu().numpy()*self.cfg.std + self.cfg.mean))
plt.subplot(222)
plt.imshow(mask[0].cpu().numpy())
plt.subplot(223)
plt.imshow(out[0, 0].cpu().numpy())
plt.subplot(224)
plt.imshow(torch.sigmoid(out[0, 0]).cpu().numpy())
plt.show()
input()
def save(self):
with torch.no_grad():
for image, mask, shape, name in self.loader:
image = image.cuda().float()
out1u, out2u, out2r, out3r, out4r, out5r = self.net(image, shape)
out = out2u
pred = (torch.sigmoid(out[0,0])*255).cpu().numpy()
head = '../eval/maps/F3Net/'+ self.cfg.datapath.split('/')[-1]
if not os.path.exists(head):
os.makedirs(head)
cv2.imwrite(head+'/'+name[0]+'.png', np.round(pred))
if __name__=='__main__':
for path in ['../data/ECSSD', '../data/PASCAL-S', '../data/DUTS', '../data/HKU-IS', '../data/DUT-OMRON']:
t = Test(dataset, F3Net, path)
t.save()
# t.show()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lihaixiong/selfreformer.git
git@gitee.com:lihaixiong/selfreformer.git
lihaixiong
selfreformer
selfreformer
master

搜索帮助