我的分类对象应该是黑色还是白色内联[关闭]

问题描述 投票:0回答:1

我有一个简单的问题。我正在使用 Keras 进行 2D 形状识别。我有使用 cv2 生成的这些示例图像:

四分之一圆

十字

长方形。

我想知道我应该做黑色背景与白色物体还是黑色物体与白色背景?

这还重要吗?

python tensorflow keras classification shapes
1个回答
1
投票

根据您的训练数据,您的验证准确度几乎为 97%,因此当您评估测试集时,您应该会得到接近该结果的结果。 首先,在测试生成器中设置 shuffle=False 。 下面是进行预测、获取准确性、混淆矩阵和分类报告的代码

from sklearn.metrics import confusion_matrix, classification_report
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('darkgrid')

def predictor(model,test_gen):
    classes=list(test_gen.class_indices.keys())
    class_count=len(classes)
    preds=model.predict(test_gen, verbose=1)
    errors=0
    pred_indices=[]
    test_count =len(preds)    
    for i, p in enumerate (preds):
        pred_index=np.argmax(p)
        pred_indices.append(pred_index)
        true_index= test_gen.labels[i]    
        if  pred_index != true_index:        
            errors +=1 
    accuracy = (test_count-errors)*100/test_count
    ytrue=np.array(test_gen.labels, dtype='int')
    ypred=np.array(pred_indices, dtype='int')    
    msg=f'There were {errors} errors in {test_count} tests for an accuracy of {accuracy:6.2f} '
    print (msg)
    cm = confusion_matrix(ytrue, ypred )
    # plot the confusion matrix
    plt.figure(figsize=(20, 20))
 sns.heatmap(cm, annot=True, vmin=0, fmt='g', cmap='Blues', cbar=False)       
    plt.xticks(np.arange(class_count)+.5, classes, rotation=90)
    plt.yticks(np.arange(class_count)+.5, classes, rotation=0)
    plt.xlabel("Predicted")
    plt.ylabel("Actual")
    plt.title("Confusion Matrix")
    plt.show()
    clr = classification_report(ytrue, ypred, target_names=classes, digits= 4) # create classification report
    print("Classification Report:\n----------------------\n", clr)
    return 
predictor(loaded_model,test_generator)

© www.soinside.com 2019 - 2024. All rights reserved.