首页 > 解决方案 > 如果 Python 的百分比低于 50,如何将图像放入相关文件夹

问题描述

 # loop over the indexes of the high confidence class labels
                for (i, j) in enumerate(idxs):
                    label1 = mlb.classes_[j]  # Label
                    label2 = "{:.2f}%".format(proba[j] * 100)  # Percentage
                    label3 = "{}: {:.2f}%".format(mlb.classes_[j], proba[j] * 100)  # Label and Percentage

                    # accuracy = label2[0][i] * 100
                    text = cv2.putText(output, label3, (10, (i * 30) + 25),
                                       cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 100, 0), 

                    pat = os.path.split(imagePath)
                    print(pat[0])
                    print(pat[1])

                if label1 == "Looking Straight" and label2 >= str(50):
                    path = "D:/Icorve Project/Learn Neural Networks/Categorical/Looking Straight/{}"
                    print(path.format(pat[1]))
                    cv2.imwrite(path.format(pat[1]), output)

                else:
                    path = "D:/Icorve Project/Learn Neural Networks/Categorical/Looking Away/{}"

这里有三个班。例如: 1. 直视

for an example if i take Looking straight one the label is printing on on the image saying "Looking straight" : 98.25%  its working perfectly. But i want to put below 50 percentage images to another folder. How to do it ???
Label1 = Class name
label2 = Percentage 
label 3 = Class name + percentage       

:GeForce GTX 1050 Ti,pci 总线 ID:0000:01:00.0,计算能力:6.1)警告:tensorflow:加载保存的优化器状态时出错。因此,您的模型从一个新初始化的优化器开始。[INFO] 图像分类...示例 data_248000_249000.h5_922.png D:/Icorve Project/Learn Neural Networks/Categorical/Looking Straight/data_248000_249000.h5_922.png (531, 413) (531, 413, 3) (180, 140 , 1)

标签: opencvtensorflowkerasneural-networkconv-neural-network

解决方案


我想第一个 if 在 for 循环内。

然后,您可以使用:

proba[j] >= 0.5

代替

label2 >= str(50)

推荐阅读