Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 加入噪声后图像检测精度提高_Python_Machine Learning_Image Processing_Svm - Fatal编程技术网

Python 加入噪声后图像检测精度提高

Python 加入噪声后图像检测精度提高,python,machine-learning,image-processing,svm,Python,Machine Learning,Image Processing,Svm,我在做一个实验,使用不同侧面的面部图像。第一个数据集只是普通的脸,我的第二个数据集是通过添加不同级别的噪声而产生的错觉。第一个数据集包含方差为0.025的噪声,第二个数据集包含方差为0.05的图像。第三个数据集的图像方差为0.1。因此,我使用线性支持向量机对它们进行训练和测试,其中方差水平,我期望测试精度下降。当我使用正常人脸图像进行测试时,测试精度为:正常人脸图像为96.59,模拟遮挡图像为48.04,方差值为0.025为95.01,方差值为0.05为93.65。到目前为止,一切看起来都是合理

我在做一个实验,使用不同侧面的面部图像。第一个数据集只是普通的脸,我的第二个数据集是通过添加不同级别的噪声而产生的错觉。第一个数据集包含方差为0.025的噪声,第二个数据集包含方差为0.05的图像。第三个数据集的图像方差为0.1。因此,我使用线性支持向量机对它们进行训练和测试,其中方差水平,我期望测试精度下降。当我使用正常人脸图像进行测试时,测试精度为:正常人脸图像为96.59,模拟遮挡图像为48.04,方差值为0.025为95.01,方差值为0.05为93.65。到目前为止,一切看起来都是合理的,但是对于0.1的方差,im得到95.46,这比方差为0.05的图像噪声要高

我希望最后一个值低于95.01

我对每个数据集培训使用相同的模型:

SVC(kernel='linear',  C=0.00006)
我想知道为什么会发生这样的事情,合理的解决办法是什么?假设我想使用相同的正则化参数来训练每个数据集

如何以百分比级别向图像添加噪波:

    def generate_noisy_image(x: np.array, variance: float) -> np.array:
        noise = np.random.normal(loc=0, scale=variance, size=x.shape)
        return x + noise

    def load_dataset(path, max_num):
        imagesList = listdir(path)
        loadedImages = []
        for root, dirs, files in os.walk(path):
            for i, name in enumerate(files):
                if i == max_num:
                    break
            print(image)
            img = PImage.open(path + image)
            img.resize((81, 150))
            arr = np.array(img)
            noise_image = generate_noisy_image(x = arr, variance=0.1)
            noise_image = Image.fromarray(noise_image)
            noise_image = noise_image.convert("L")
            loadedImages.append(arr)
            #noise_image.save('C:/Users/Noise-Dataset/Noise_Value_10/'+person_folder+filepath, 'JPEG')
        return loadedImages
    
    
    noise_dataset_1 = load_dataset('C:/Users/Noise-Dataset/Noise_Value_10', 50) 

    X_train_n1, X_test_n1, y_train_n1, y_test_n1 = train_test_split(
            noise_dataset_1_array, noise_1_target, test_size=0.49, random_state=0)


def train(clf, X_train, X_test, y_train, y_test):
    
    clf.fit(X_train, y_train)
    print ("Accuracy on training set:")
    print (clf.score(X_train, y_train))
    print ("Accuracy on testing set:")
    print (clf.score(X_test, y_test))
    
    y_pred = clf.predict(X_test)
    
    print ("Classification Report:")
    print (metrics.classification_report(y_test, y_pred))
    print ("Accuracy:")
    print (metrics.accuracy_score(y_test, y_pred))

svc_1 = SVC(kernel='linear', C=0.00006)
train(svc_1, X_train_n1, X_test_n1, y_train_n1, y_test_n1 )

我以前做过类似的事情,增强图像实际上提高了准确性。这里我假设你在做一个分类任务,比如性别检测?结果背后的原因是,原始面部图像在预测类中可能具有不同程度的噪声(例如,大多数男性图像噪声较大,女性图像噪声较小),因此在检测输出时,模型使用低级别线索,即噪声作为特征。您可以认为模型是“懒惰”的,尤其是在这里,您没有使用DNN,因此模型更可能是“懒惰”的,并且依赖于低级线索。通过添加噪波,模型更难依赖信息,因为所有图像现在都有噪波,因此模型开始寻找高级线索,在您的情况下,这些线索可能会为模型提供更高的预测能力/准确性。

您报告的所有准确度都非常接近,因此差异可能只是统计上的侥幸,尤其是当您的测试集相对较小时。