Comments (2)
# 前面是加载flow模型(略)
# 计算模板feat_mean
flow.eval()
feat_sum, cnt = [0 for _ in range(L)], 0
for val_dict in val_loader:
image = val_dict['images'].to(device)
with torch.no_grad():
pyramid2= flow(image)
cnt += 1
feat_sum = [p0+p for p0, p in zip(feat_sum, pyramid2)]
feat_mean = [p/cnt for p in feat_sum]
# 预处理
img2tensor = transforms.Compose([transforms.ToPILImage(),
transforms.Resize((x_size,x_size)),
transforms.ToTensor(),
transforms.Normalize(img_mean, img_std)])
for datapath in glob(osp.join(datadir, cls_name, 'test', '*', '*.png')): # 这里改成你需要的
save_dir = osp.join('diff', '/'.join(datapath.split('/')[-4:-1]) ) # 这里改成你需要的
os.makedirs(save_dir, exist_ok=True)
img = np.array(Image.open(datapath).convert('RGB'))
img = img2tensor(img).unsqueeze(0).to(device) # h,w,c
with torch.no_grad():
pyramid2 = flow(img)
pyramid_diff = [(feat2 - template).abs() for feat2, template in zip(pyramid2, feat_mean)]
diff = flow.pyramid.compose_pyramid(pyramid_diff).mean(1) # b,h,w
np_diff = diff[0].cpu().detach().numpy()
plt.imshow(np_diff, vmax=0.9*np_diff.max(),) # 绘制anomaly map
plt.gca().xaxis.set_major_locator(plt.NullLocator())
plt.gca().yaxis.set_major_locator(plt.NullLocator())
save_path = osp.join(save_dir, datapath.split('/')[-1] )
plt.savefig(save_path, bbox_inches='tight', pad_inches=0)
from pyramidflow.
from pyramidflow.
Related Issues (13)
- 你好,PyramidFlow是one-class模型吗?需要针对每一类去训练一个模型去识别缺陷? HOT 1
- feedback HOT 2
- About Training HOT 2
- 循环关于您的环境配置? HOT 1
- AUPRO might be too high? HOT 2
- why determinant of the Jacobian is not considered in loss? HOT 2
- ModuleNotFoundError: No module named 'autoFlow'
- How to inference HOT 2
- Difficult to reproduce paper results HOT 1
- [bug] VolumeNorm 加载权重大小不匹配 HOT 2
- Hello,your paper is excellent HOT 2
- 您好,train过程遇到的问题 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyramidflow.