onnx口罩分类
【摘要】
softmax python版:
# -*- coding: utf-8 -*-import osimport time import cv2import numpy as np net = cv2.dnn.readNetFromONNX(r'mobile_mask.onnx')print("net load") def softm...
softmax python版:
-
# -*- coding: utf-8 -*-
-
import os
-
import time
-
-
import cv2
-
import numpy as np
-
-
net = cv2.dnn.readNetFromONNX(r'mobile_mask.onnx')
-
print("net load")
-
-
-
def softmax(x, axis=1):
-
# 计算每行的最大值
-
row_max = x.max(axis=axis)
-
-
# 每行元素都需要减去对应的最大值,否则求exp(x)会溢出,导致inf情况
-
row_max = row_max.reshape(-1, 1)
-
x = x - row_max
-
-
x_exp = np.exp(x)
-
x_sum = np.sum(x_exp, axis=axis, keepdims=True)
-
s = x_exp / x_sum
-
return s
-
-
if __name__ == '__main__':
-
-
list_path=r"D:\project\face\face_mask\2020\0/"
-
list_path = r"test/"
-
-
g = os.walk(list_path)
-
files = ['%s\\%s' % (i[0], j) for i in g for j in i[-1] if
-
j.endswith('jpg')]
-
-
count=0
-
ok_count=0
-
for file in files:
-
file_path=file
-
img=cv2.imread(file)
-
if img is
文章来源: blog.csdn.net,作者:AI视觉网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/104393063
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)