使用 CNN 检测一个人是否戴了口罩

news2024/10/7 6:46:43

在本文中,我们将使用 CNN (卷积神经网络)和机器学习分类器创建一个检测一个人是否戴着口罩的分类器。它将检测一个人是否戴着口罩。

我们将从头开始学习,我将对每一步进行解释。我需要你对机器学习和数据科学有基本的了解。我已经在本地 Windows 10 机器上实现了它,如果你愿意,你也可以在 Google Colab 上实现它。

卷积神经网络是一种人工神经网络,旨在处理像素数据。它们经常用于图像处理和图像识别。

图 1 戴口罩 V/S 没戴口罩

CNN 模型管道

首先,我们将输入大小为 224×224 像素的 RGB 图像。然后这些图像将进入一个 CNN 模型,从中提取 128 个相关的特征向量。然后我们将使用这些特征向量来训练我们的各种机器学习分类器,如逻辑回归、随机森林等,以分类该图像中的人是否戴着口罩。你可以参考下图以获得更好的理解。

图 2 解释我们的整个机器学习管道

让我们开始吧

技术提升

本文由技术群粉丝投稿分享,项目源码、数据、技术交流提升,均可加交流群获取,群友已超过2000人,添加时最好的备注方式为:来源+兴趣方向,方便找到志同道合的朋友

方式①、添加微信号:dkl88191,备注:来自CSDN +研究方向
方式②、微信搜索公众号:Python学习与数据挖掘,后台回复:加群

训练 CNN 模型的代码工作

在本节中,我们将学习编码部分。

我们将讨论数据集的加载和预处理、训练 CNN 模型以及提取特征向量以训练机器学习分类器。

导入必要的库:

我们将导入此项目所需的所有必要库。

我们将使用 Numpy ,用于执行复杂的数学计算。Pandas 加载和预处理数据集。

import numpy as np  
import pandas as pd  
import matplotlib.pyplot as plt  
import os  
  
from itertools import cycle  
from sklearn.model_selection import train_test_split  
from tensorflow.keras.models import Model  
from tensorflow.keras.layers import Dropout, Dense, AveragePooling2D, Flatten ,Dense, Input  
from sklearn.metrics import classification_report, confusion_matrix  
  
import cv2  
from sklearn.metrics import roc_curve, auc  
from sklearn.preprocessing import label_binarize  
  
from scipy import interp  
from sklearn.ensemble import RandomForestClassifier  
  
from tensorflow.keras.preprocessing.image import ImageDataGenerator  
from tensorflow.keras.applications import MobileNetV2  
from tensorflow.keras.optimizers import Adam  

数据集的加载和预处理

你可以从该 GitHub Repo 下载数据集:https://github.com/prajnasb/observations/tree/master/experiements

从上述存储库中克隆数据集。

该数据集包含 1200 多张不同人是否戴口罩的图像。加载数据集后,我们将对其进行预处理。

预处理涉及拆分训练和测试数据集,将像素值转换为 0 到 1 之间,并将标签转换为 one-hot 编码标签。

下面是加载和预处理数据集的代码。它的注释很完整,你可以轻松理解它。
在这里插入图片描述

显示训练和测试集

在下面的代码中,我们将首先从文件夹中读取所有图像,然后通过将它们调整为 224×224 像素将它们存储在一个数组中。之后,我们将标记这些图像。带有口罩的图像有一个标签 0,没有口罩的图像有一个标签 1。最后,我们将使用名为 train test split 的 sklearn 函数将此数据集拆分为训练和测试。

# 列出主目录中所有带口罩的图像。

filenames = os.listdir("observations-master/experiements/data/with_mask")  
np.random.shuffle(filenames)  
print(filenames) # Read all the images from that directory and resize them into 224x224 pixels.  
  
with_mask_data = [cv2.resize(cv2.imread("observations-master/experiements/data/with_mask/"+img), (224,224)) for img in filenames]  
print(len(with_mask_data))  

# 对于不包含口罩的图像,执行上述类似步骤。

filenames = os.listdir("observations-master/experiements/data/without_mask")  
np.random.shuffle(filenames)  
print(filenames)  
  
without_mask_data = [cv2.resize(cv2.imread("observations-master/experiements/data/without_mask/"+img), (224,224)) for img in filenames]  
print(len(without_mask_data))  

# 我们将两个数组组合成一个数组,通过将它们除以 255 将每个像素值在 0 和 1 之间转换。

data = np.array(with_mask_data + without_mask_data).astype('float32')/255 # Label of the image with a mask - 0 # Label of the image without mask - 1  
labels = np.array([0]*len(with_mask_data) + [1]*len(without_mask_data))  
print(data.shape) # Splitting the data into training and testing sets.  
  
(training_data, testing_data, training_label, testing_label) = train_test_split(data, labels, test_size=0.50, stratify=labels, random_state=42)  
print(training_data.shape) # Function to Plot the Accuracy/Loss Curves  
  
def plot_acc_loss(result, epochs):  
acc = result.history['accuracy']  
loss = result.history['loss']  
  
val_acc = result.history['val_accuracy']  
val_loss = result.history['val_loss']  
  
plt.figure(figsize=(15, 5))  
plt.subplot(121)  
plt.plot(range(1,epochs), acc[1:], label='Train_acc')  
plt.plot(range(1,epochs), val_acc[1:], label='Val_acc')  
  
plt.title('Accuracy over ' + str(epochs) + ' Epochs', size=15)  
plt.legend()  
  
plt.grid(True)  
plt.subplot(122)  
plt.plot(range(1,epochs), loss[1:], label='Train_loss')  
plt.plot(range(1,epochs), val_loss[1:], label='Val_loss')  
  
plt.title('Loss over ' + str(epochs) + ' Epochs', size=15)  
plt.legend()  
plt.grid(True)  
plt.show()  

构建卷积神经网络 (CNN)

现在我们将构建我们的卷积神经网络。首先,我们使用图像数据生成器来增加数据集中的图像数量。该图像生成器将从这些现有图像中生成更多照片。它执行顺时针或逆时针旋转,改变对比度,执行放大或缩小等。

之后,我们将使用预训练的 MobileNetV2 架构来训练我们的模型。它是一种迁移学习模型。迁移学习是使用预训练模型来训练新的深度学习模型,即如果两个模型执行相似的任务,我们可以共享知识。

应用迁移学习后,我们将应用展平层将 2D 矩阵转换为 1D 数组。之后,我们将应用 dense 层和 dropout 层来执行分类。

最后,我们将批量大小设为 32,epoch 数设为 25 来训练我们的模型。你可以根据自己的计算能力取其他值。

在这里插入图片描述

图 3 解释我们的卷积神经网络

训练卷积神经网络模型的代码:

我们将构建我们的迁移学习 MobileNetV2 架构,这是一个预训练的 CNN 模型。

首先,我们将使用图像数据生成器 ImageDataGenerator 从我们的数据集中生成更多图像。

之后,我们将设置我们的超参数,例如学习率、批量大小、epoch 数量等。

最后,我们将训练我们的模型并在测试集上检查它的准确性。

# Image data generator to generate more images.   
generator = ImageDataGenerator(  
rotation_range=20,  
zoom_range=0.15,  
width_shift_range=0.2,  
height_shift_range=0.2,  
shear_range=0.15,  
horizontal_flip=True,  
fill_mode="nearest")  
# Setting the hyperparameters.  
learning_rate = 0.0001  
epoch = 25  
batch_size = 32  
# Training the mobile net v2 architecture.  
transfer_learning_model = MobileNetV2(weights="imagenet", include_top=False,  
input_tensor=Input(shape=(224, 224, 3)))  
  
model_main = transfer_learning_model.output  
model_main = AveragePooling2D(pool_size=(7, 7))(model_main) # Applying the flattening layer.  
model_main = Flatten(name="flatten")(model_main)  
model_main = Dense(128, activation="relu", name="dense_layer")(model_main)  
model_main = Dropout(0.5)(model_main)  
model_main = Dense(2, activation="softmax")(model_main)  
cnn = Model(inputs=transfer_learning_model.input, outputs=model_main)  
  
for row in transfer_learning_model.layers:  
row.trainable = False  
optimizer = Adam(lr=learning_rate, decay=learning_rate / epoch)  
cnn.compile(loss="sparse_categorical_crossentropy", optimizer=optimizer,  
metrics=["accuracy"])  
# Train the CNN model  
history = cnn.fit(  
generator.flow(training_data, training_label, batch_size=batch_size),  
steps_per_epoch=len(training_data) // batch_size,  
validation_data=(testing_data, testing_label),  
validation_steps=len(testing_data) // batch_size,  
epochs=epoch)  
# Evaluate the trained model  
# Evaluate the model on the test set.  
  
cnn.evaluate(testing_data, testing_label)  
  
plot_acc_loss(history, 25)  

在这里插入图片描述

图 4 超过 25 个 epoch 的准确率和损失

我们在测试集上获得了 99.42% 的准确率

使用机器学习分类器

现在,我们将从之前训练的 CNN 模型中提取 128 个相关特征向量,并将它们应用于不同的 ML 分类器。我们将使用以下机器学习分类器:

EXtreme Gradient Boosting:

Extreme Gradient Boosting (XGBoost) 是一个开源库,可以高效地实现梯度提升算法。

首先,导入必要的库,然后将分类器定义为 XGBClassifier。拟合后,表示预测和准确度得分。我们得到准确率、混淆矩阵和分类报告作为输出。在这里,我们得到了 98.98% 的准确率。

随机森林分类器:

随机森林是一个分类器,它在给定数据集的不同子集上包含多个决策树,并取平均值以提高该数据集的预测准确性。森林中的树木数量越多,精度越高,并且可以防止过度拟合的问题。

首先,导入必要的库,然后将分类器定义为 RandomForestClassifier。拟合后,我们得到准确率、混淆矩阵和分类报告作为输出。在这里,我们的准确率达到了 99.41%,超过了 XGBoost。

逻辑回归:

逻辑回归是一种监督学习分类算法,用于预测目标变量的概率。目标或因变量的性质是二分类的,这意味着只有两个可能的类别。在这里,我们的准确率达到了 99.70%,高于 XGBoost,但略低于随机森林。

高斯分布:

正态分布也称为高斯分布。它表明接近平均值的数据比远离平均值的数据更频繁地出现。钟形曲线表示图形上的正态分布。

下面是提取基本特征向量并将这些特征向量放入机器学习分类器的代码。

在训练我们的 CNN 模型之后,我们现在将应用特征提取,并从这些图像中提取 128 个相关的特征向量。这些适当的特征向量被输入到我们的各种机器学习分类器中,以执行最终分类。

我们使用了各种机器学习模型,例如 XGBoost、随机森林、逻辑回归、GaussianNB 等。我们将选择能够提供最佳准确度的模型。

from keras.models import Model  
  
layer_name='dense_layer' # Extracting the layer from the above CNN model, which contains 128neurons.  
new_model = Model(inputs=cnn.input,  
  
outputs=cnn.get_layer(layer_name).output)  
new_model.summary()  
# Get new training data that only contains these 128 features.  
training_image_features = new_model.predict(training_data)  
training_image_features = pd.DataFrame(data=training_image_features)  
  
testing_image_features = new_model.predict(testing_data)  
testing_image_features = pd.DataFrame(data=testing_image_features)  
# Perform the classification using XGBoost Classifier. from xgboost import XGBClassifier  
  
from sklearn.metrics import accuracy_score  
  
classifier = XGBClassifier()  
classifier.fit(training_image_features, training_label)  
  
predictions = classifier.predict(testing_image_features) # Getting the accuracy score  
accuracy = accuracy_score(predictions, testing_label)  
print(f'{accuracy*100}%') # Getting the confusion matrix.  
  
cf = confusion_matrix(predictions, testing_label)  
print(cf)  
  
from sklearn.metrics import classification_report  
  
c_r = classification_report(predictions, testing_label, output_dict=True)  
print(c_r)  
# Perform the classification using RandomForest Classifier.  
  
from sklearn.ensemble import RandomForestClassifier  
  
rfc = RandomForestClassifier()  
rfc.fit(training_image_features, training_label)  
  
prediction = rfc.predict(testing_image_features)  
accuracy = accuracy_score(prediction, testing_label)  
print(f'{accuracy*100}%')  
  
cf = confusion_matrix(prediction, testing_label)  
print(cf)  
  
from sklearn.metrics import classification_report  
c_r = classification_report(prediction, testing_label, output_dict=True)  
  
print(c_r)  
# Perform the classification using LogisticRegression  
  
from sklearn.linear_model import LogisticRegression  
  
lin_r = LogisticRegression()  
lin_r.fit(training_image_features, training_label)  
  
prediction = lin_r.predict(testing_image_features)  
accuracy = accuracy_score(prediction, testing_label)  
print(f'{accuracy*100}%')  
  
cf = confusion_matrix(prediction, testing_label)  
print(cf)  
  
from sklearn.metrics import classification_report  
  
c_r = classification_report(prediction, testing_label, output_dict=True)  
print(c_r)  
# Perform the classification using GaussianNB  
  
from sklearn.naive_bayes import GaussianNB  
  
n_b = GaussianNB()  
n_b.fit(training_image_features, training_label)  
  
prediction = n_b.predict(testing_image_features)  
accuracy = accuracy_score(prediction, testing_label)  
print(f'{accuracy*100}%')  
  
cf = confusion_matrix(prediction, testing_label)  
print(cf)  
  
from sklearn.metrics import classification_report  
c_r = classification_report(prediction, testing_label, output_dict=True)  
print(c_r)  

结果

在本节中,我们将讨论我们的分类结果。我们将讨论我们达到了多少准确度,以及召回率和 f1 分数是多少。

Accuracy: 评估分类模型的一个参数是 Accuracy(准确度)。我们的模型正确预测的预测百分比称为准确度。以下是准确度的官方定义:准确预测的数量除以样本总数。

Precision: 被分类器判定的阳性样本中真阳性样本的比重

**F1 分数:**机器学习中最重要的评估指标之一是 F1 分数。结合了准确率和召回率,它是一个很好的综合指标。
在这里插入图片描述

以下是我们用来训练模型的所有机器学习分类器的性能得分。逻辑回归给出的准确率最高,为 99.709%。

所有机器学习分类器的混淆矩阵是:混淆矩阵是一个总结预测结果的 NxN 矩阵。它包含每个类别的正确和错误预测的数量。

![](http://qiniu.aihubs.net/美国有线电视新闻网 (1).png)

完整代码

在本节中,我分享了该项目中使用的完整代码。除了上述代码之外,此代码还包含绘制机器学习模型的 ROC-AUC 曲线的代码。

ROC 曲线是显示分类模型在所有分类阈值下的性能的图表。该曲线绘制了两个参数:真阳性率、假阳性率。

首先我们加载数据集。然后我们使用 OpenCV 库读取图像,将它们转换为 224×224 像素大小,并将它们存储在一个数组中。之后,我们必须为这两个类制作标签,即有口罩(mask)和无口罩(no mask)。

然后我们讨论了图像数据生成器和 MobileNetV2 架构的代码。此外,我们在设置了 epochs、batch size 等超参数后训练了我们的 CNN 模型。在完成 25 个 epochs 后,我们在测试集上获得了 99.42% 的准确率。

在训练完 CNN 模型后,我们应用特征提取,从密集层中提取了 128 个特征向量,并将这些特征向量应用到机器学习模型中,得到最终的分类。然后我们编写了评估各种性能矩阵的代码,如准确度、F1 得分、精度等。最后,我们绘制了性能最佳的机器学习模型的 ROC-AUC 曲线。

import numpy as np  
import pandas as pd  
import matplotlib.pyplot as plt  
import os  
  
from itertools import cycle  
from sklearn.model_selection import train_test_split  
  
from tensorflow.keras.models import Model  
from tensorflow.keras.layers import Dropout, Dense, AveragePooling2D, Flatten ,Dense, Input  
  
from sklearn.metrics import classification_report, confusion_matrix  
  
import cv2  
  
from sklearn.metrics import roc_curve, auc  
from sklearn.preprocessing import label_binarize  
from scipy import interp  
from sklearn.ensemble import RandomForestClassifier  
from tensorflow.keras.preprocessing.image import ImageDataGenerator  
from tensorflow.keras.applications import MobileNetV2  
from tensorflow.keras.optimizers import Adam  
  
def plot_acc_loss(result, epochs):  
acc = result.history['accuracy']  
loss = result.history['loss']  
val_acc = result.history['val_accuracy']  
val_loss = result.history['val_loss']  
  
plt.figure(figsize=(15, 5))  
plt.subplot(121)  
plt.plot(range(1,epochs), acc[1:], label='Train_acc')  
plt.plot(range(1,epochs), val_acc[1:], label='Val_acc')  
plt.title('Accuracy over ' + str(epochs) + ' Epochs', size=15)  
  
plt.legend()  
plt.grid(True)  
  
plt.subplot(122)  
plt.plot(range(1,epochs), loss[1:], label='Train_loss')  
plt.plot(range(1,epochs), val_loss[1:], label='Val_loss')  
plt.title('Loss over ' + str(epochs) + ' Epochs', size=15)  
plt.legend()  
plt.grid(True)  
plt.show()  
  
# filenames = glob(mypath +'with_mask/'+'*.jpg')  
  
filenames = os.listdir("observations-master/experiements/data/with_mask")  
  
np.random.shuffle(filenames)  
  
print(filenames) # 460 , 116  
  
with_mask_data = [cv2.resize(cv2.imread("observations-master/experiements/data/with_mask/"+img), (224,224)) for img in filenames]  
  
print(len(with_mask_data))  
  
filenames = os.listdir("observations-master/experiements/data/without_mask")  
np.random.shuffle(filenames)  
print(filenames) # 460 , 116  
  
without_mask_data = [cv2.resize(cv2.imread("observations-master/experiements/data/without_mask/"+img), (224,224)) for img in filenames]  
print(len(without_mask_data))  
  
data = np.array(with_mask_data + without_mask_data).astype('float32')/255  
labels = np.array([0]*len(with_mask_data) + [1]*len(without_mask_data))  
print(data.shape)  
  
(training_data, testing_data, training_label, testing_label) = train_test_split(data, labels, test_size=0.50, stratify=labels, random_state=42)  
print(training_data.shape)  
  
generator = ImageDataGenerator(  
rotation_range=20,  
zoom_range=0.15,  
width_shift_range=0.2,  
height_shift_range=0.2,  
shear_range=0.15,  
horizontal_flip=True,  
fill_mode="nearest")  
  
learning_rate = 0.0001  
epoch = 25  
batch_size = 32  
  
transfer_learning_model = MobileNetV2(weights="imagenet", include_top=False,  
input_tensor=Input(shape=(224, 224, 3)))  
  
model_main = transfer_learning_model.output  
model_main = AveragePooling2D(pool_size=(7, 7))(model_main)  
model_main = Flatten(name="flatten")(model_main)  
model_main = Dense(128, activation="relu", name="dense_layer")(model_main)  
model_main = Dropout(0.5)(model_main)  
model_main = Dense(2, activation="softmax")(model_main)  
  
cnn = Model(inputs=transfer_learning_model.input, outputs=model_main)  
  
for row in transfer_learning_model.layers:  
row.trainable = False  
  
optimizer = Adam(lr=learning_rate, decay=learning_rate / epoch)  
  
cnn.compile(loss="sparse_categorical_crossentropy", optimizer=optimizer,  
  
metrics=["accuracy"])  
  
history = cnn.fit(  
  
generator.flow(training_data, training_label, batch_size=batch_size),  
steps_per_epoch=len(training_data) // batch_size,  
  
validation_data=(testing_data, testing_label),  
validation_steps=len(testing_data) // batch_size,  
  
epochs=epoch)  
  
cnn.evaluate(testing_data, testing_label)  
  
plot_acc_loss(history, 25)  
  
from keras.models import Model  
layer_name='dense_layer'  
new_model = Model(inputs=cnn.input,  
outputs=cnn.get_layer(layer_name).output)  
  
new_model.summary()  
  
training_image_features = new_model.predict(training_data)  
training_image_features = pd.DataFrame(data=training_image_features)  
  
testing_image_features = new_model.predict(testing_data)  
testing_image_features = pd.DataFrame(data=testing_image_features)  
  
from xgboost import XGBClassifier  
  
from sklearn.metrics import accuracy_score  
  
classifier = XGBClassifier()  
classifier.fit(training_image_features, training_label)  
  
predictions = classifier.predict(testing_image_features)  
accuracy = accuracy_score(predictions, testing_label)  
print(f'{accuracy*100}%')  
  
cf = confusion_matrix(predictions, testing_label)  
print(cf)  
  
from sklearn.metrics import classification_report  
c_r = classification_report(predictions, testing_label, output_dict=True)  
  
print(c_r)  
  
from sklearn.ensemble import RandomForestClassifier  
  
rfc = RandomForestClassifier()  
rfc.fit(training_image_features, training_label)  
  
prediction = rfc.predict(testing_image_features)  
accuracy = accuracy_score(prediction, testing_label)  
print(f'{accuracy*100}%')  
  
cf = confusion_matrix(prediction, testing_label)  
print(cf)  
  
from sklearn.metrics import classification_report  
c_r = classification_report(prediction, testing_label, output_dict=True)  
print(c_r)  
  
from sklearn.linear_model import LogisticRegression  
  
lin_r = LogisticRegression()  
lin_r.fit(training_image_features, training_label)  
  
prediction = lin_r.predict(testing_image_features)  
accuracy = accuracy_score(prediction, testing_label)  
print(f'{accuracy*100}%')  
  
cf = confusion_matrix(prediction, testing_label)  
print(cf)  
  
from sklearn.metrics import classification_report  
c_r = classification_report(prediction, testing_label, output_dict=True)  
print(c_r)  
  
from sklearn.naive_bayes import GaussianNB  
n_b = GaussianNB()  
n_b.fit(training_image_features, training_label)  
  
prediction = n_b.predict(testing_image_features)  
accuracy = accuracy_score(prediction, testing_label)  
print(f'{accuracy*100}%')  
  
cf = confusion_matrix(prediction, testing_label)  
print(cf)  
  
from sklearn.metrics import classification_report  
c_r = classification_report(prediction, testing_label, output_dict=True)  
print(c_r)  
  
# Binarize the output  
y = label_binarize(training_label, classes=[0, 1])  
y_test = label_binarize(testing_label, classes=[0, 1])  
n_classes = 2  
  
# Learn to predict each class against the other  
classifier = RandomForestClassifier()  
classifier.fit(training_image_features, y)  
y_score = classifier.predict(testing_image_features)  
  
print(accuracy_score(y_score, y_test))  
  
# Compute the ROC curve and ROC area for each class  
fpr = dict()  
tpr = dict()  
roc_auc = dict()  
  
for i in range(n_classes):  
fpr[i], tpr[i], _ = roc_curve(y_test[:, i], y_score[:, i])  
roc_auc[i] = auc(fpr[i], tpr[i])  
  
# Compute micro-average ROC curve and ROC area  
fpr["micro"], tpr["micro"], _ = roc_curve(y_test.ravel(), y_score.ravel())  
roc_auc["micro"] = auc(fpr["micro"], tpr["micro"])  
  
# First aggregate all false positive rates  
all_fpr = np.unique(np.concatenate([fpr[i] for i in range(n_classes)]))  
  
# Then interpolate all ROC curves at these points  
mean_tpr = np.zeros_like(all_fpr)  
for i in range(n_classes):  
mean_tpr += interp(all_fpr, fpr[i], tpr[i])  
  
# Finally, average it and compute AUC  
mean_tpr /= n_classes  
fpr["macro"] = all_fpr  
tpr["macro"] = mean_tpr  
roc_auc["macro"] = auc(fpr["macro"], tpr["macro"])  
  
  
# Plot all ROC curves  
plt.figure()  
plt.plot(fpr["micro"], tpr["micro"],  
label='micro-average ROC curve (area = {0:0.2f})'  
''.format(roc_auc["micro"]),  
color='deeppink', linestyle=':', linewidth=4)  
  
plt.plot(fpr["macro"], tpr["macro"],  
label='macro-average ROC curve (area = {0:0.2f})'  
''.format(roc_auc["macro"]),  
color='navy', linestyle=':', linewidth=4)  
colors = cycle(['aqua', 'darkorange', 'cornflowerblue'])  
  
for i, color in zip(range(n_classes), colors):  
plt.plot(fpr[i], tpr[i], color=color,  
label='ROC curve of class {0} (area = {1:0.2f})'  
''.format(i, roc_auc[i]))  
  
plt.plot([0, 1], [0, 1], 'k--')  
plt.xlim([0.0, 1.0])  
plt.ylim([0.0, 1.05])  
plt.xlabel('False Positive Rate')  
plt.ylabel('True Positive Rate')  
plt.title('Some extension of Receiver operating characteristic to multi-class')  
plt.legend(loc="lower right")  
plt.show()  

使用的实验设置:

  • Python 3.8 编程语言

  • IntelR Core i5-1155G7 CPU @ 2.30GHz × 8 处理器

  • 8GB RAM

  • Windows 10

  • NVIDIA Geforce MX 350 with 2GB Graphics

结论

本文要点:

  • 展示了使用卷积网络和机器学习分类器来有效地对戴口罩和没戴口罩的图像进行分类。

  • 在数据集中使用了图像增强来标准化图像。

  • 通过 CNN 提取图像特征后,应用机器学习算法进行最终分类,卷积神经网络获得了最佳结果,随机森林的准确率分别为 99.42% 和 99.21%,逻辑回归的准确率为 99.70%,这是所有方法中最高的。

  • 因此,这种图像处理方法和图像处理技术可以成为一种大规模、更快且具有成本效益的分类方法。使用更大规模的数据集进行训练,并在更大的队列中进行现场测试可以提高准确性。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/101956.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Bootstrap5 表单

在本章中&#xff0c;我们将学习如何使用 Bootstrap 创建表单。Bootstrap 通过一些简单的 HTML 标签和扩展的类即可创建出不同样式的表单。 表单元素 <input>, <textarea>, 和 <select> elements 在使用 .form-control 类的情况下&#xff0c;宽度都是设置为…

【HAL库】STM32CubeMX开发----delay延时实验----NOP空指令

STM32CubeMX 下载和安装 详细教程 【HAL库】STM32CubeMX开发----STM32F103/F207/F407----目录 前言 HAL库有自带的 ms级 延时函数&#xff1a; HAL_Delay(); 缺点1&#xff1a; 无法实现 us级延时 缺点2&#xff1a; 此延时函数是由SysTick滴答定时器中断产生的&#xff0…

【性能篇】28 # Canvas、SVG与WebGL在性能上的优势与劣势

说明 【跟月影学可视化】学习笔记。 可视化渲染的性能问题有哪些&#xff1f; 渲染效率问题&#xff1a;指的是图形系统在绘图部分所花费的时间计算问题&#xff1a;指绘图之外的其他处理所花费的时间&#xff0c;包括图形数据的计算、正常的程序逻辑处理等等。 在浏览器上…

Leetcode 1760. 袋子里最少数目的球

给你一个整数数组 nums &#xff0c;其中 nums[i] 表示第 i 个袋子里球的数目。同时给你一个整数 maxOperations 。你可以进行如下操作至多 maxOperations 次&#xff1a;选择任意一个袋子&#xff0c;并将袋子里的球分到 2 个新的袋子中&#xff0c;每个袋子里都有 正整数 个球…

深圳电巢携手东华理工大学“电巢相伴 研职引航” 线上讲座圆满结束

前 言 2022年12月13日下午2时&#xff0c;电巢十日谈——“电巢相伴 研职引航”在电巢app直播间开讲&#xff0c;本次活动由电巢科技与东华理工大学共同举办&#xff0c;为机械与电子工程学院的大一到大四的学生带来了不少启发。 「电巢十日谈」这一系列活动正是受到薄伽丘《…

如何实现冷库冷链远程监控

本解决方案是通过智能物联网技术&#xff0c;实现对冷库温湿度的远程监控管理。 根据冷库内的温湿度数据可以及时掌握冷库内的环境状况&#xff0c;并及时采取相应的措施。 该系统通过实时监测与显示不同冷库的温湿度&#xff0c;将温度数据上传到服务器&#xff0c;并可根据实…

Fully Convolutional Adaptation Networks for Semantic Segmentation

参考 论文解析之《Fully Convolutional Adaptation Networks for Semantic Segmentation》 - 云社区 - 腾讯云 论文网址&#xff1a;Fully Convolutional Adaptation Networks for Semantic Segmentation 摘要 深度神经网络的最新进展令人信服地证明了在大数据集上学习视觉模…

基于MediatR管道的公共业务校验

基于MediatR的管道模式&#xff0c;我们可以在处理业务之前&#xff0c;进行统一验证&#xff0c;记录日志等。 所有命令&#xff08;Command&#xff09;再被处理(Handle)之前&#xff0c;都要经过IRequestPreProcessor处理&#xff0c;我们注入自己的拦截器&#xff0c;执行…

chrome拓展插件开发中使用chrome.storage本地存储

一、描述 在扩展程序中本地存储数据可以通过 chrome.storage API 实现&#xff0c;和 web 中的 localstorage 在某些方面是有区别的&#xff0c;chrome.storage 已经做了优化。 与 localStorage 的区别&#xff1a; 用户数据可以与 chrome 自动同步&#xff08;通过 storage…

【推荐】智能制造工业4.0与MES资料合集

智能制造&#xff0c;源于人工智能的研究&#xff0c;一般认为智能是知识和智力的总和&#xff0c;前者是智能的基础&#xff0c;后者是指获取和运用知识求解的能力。 智能制造应当包含智能制造技术和智能制造系统&#xff0c;智能制造系统不仅能够在实践中不断地充实知识库&a…

请上车MySQL面试必备点:从常见的存储引擎到混淆的锁分类

我们之前的文章InnoDB解决幻读的方案中提到了记录锁&#xff08;行锁&#xff09;、间隙锁和临键锁&#xff0c;后台有小伙伴催我更新一下其他的锁。拖延症又犯了&#xff0c;趁周末&#xff0c;今天我们来总结一下MyISAM和InnoDB引擎下锁的种类及使用方法。 MySQL的四大常见存…

面试题:Linux是如何避免内存碎片的

Linux是如何避免内存碎片的&#xff1f; 在网上看到这个面试题&#xff0c;参考答案是这样的&#xff1a; 伙伴算法&#xff0c;用于管理物理内存&#xff0c;避免内存碎片;高速缓存Slab层用于管理内核分配内存&#xff0c;避免碎片。 故继而去深入了解了一波&#xff0c;做了…

牛客之基础单片机知识_1

✅作者简介&#xff1a;大家好我是 xxx&#xff0c;是一名嵌入式工程师&#xff0c;希望一起努力&#xff0c;一起进步&#xff01; &#x1f4c3;参照主页&#xff1a;嵌入式基地 &#x1f525;系列专栏&#xff1a;硬件基础知识——单片机 习题专栏 &#x1f4ac;网上关于嵌入…

软件测试不常用但是一定要会的测试技术与用例设计

一、认识基本术语 术语一&#xff1a; ◆动态测试&#xff08;dynamic testing&#xff09; 通过运行软件的组件或系统来测试软件(实际运行被测软件/系统)【需要进行操作】 ◆静态测试&#xff08;static testing) 对组件的规格说明书进行评审&#xff0c;对静态代码进行走…

【推荐】700套高端简历模板合集

简历&#xff08;英语&#xff1a;resume&#xff09;&#xff0c;顾名思义&#xff0c;就是对个人学历、经历、特长、爱好及其它有关情况所作的简明扼要的书面介绍。简历是有针对性的自我介绍的一种规范化、逻辑化的书面表达。对应聘者来说&#xff0c;简历是求职的“敲门砖”…

JSP学生宿舍网站

开发工具(eclipse/idea/vscode等)&#xff1a; 数据库(sqlite/mysql/sqlserver等)&#xff1a; 功能模块(请用文字描述&#xff0c;至少200字)&#xff1a; 模块划分&#xff1a;通知类型模块、通知信息模块、院系信息、班级信息、宿舍 楼信息、宿舍信息、宿管信息、学生信息、…

three.js之多线条组合

文章目录多线条组合例子专栏目录请点击 多线条组合 我们可以通过CurvePath把多个曲线、直线等合并成一个曲线 例子 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><style>body {margin: 0;overflow: hidde…

CSS习题解答

文章目录1.1 样式定义方式1.2 选择器1.3 颜色1.4 文本1.5 字体1.6 背景1.7 边框1.8 元素展示格式1.9 内边距与外边距1.10 盒子模型1.11 位置1.12 浮动实战&#xff1a;个人名片1.13 flex布局1.14 响应式布局作业01作业02作业03作业04作业05作业06作业07作业08作业09作业10其他1…

正则表达式学习

文章目录入门开始和结束字符组区间特殊字符转义取反快捷匹配数字和字母匹配空白任意字符重复次数和区间或者条件进阶分组非捕获分组分组的引用正向先行断言反向先行断言正向后行断言反向后行断言常用元字符整理相关网站在线测试网站题目练习网站其他笔记入门 开始和结束 正则…

计算机毕设Python+Vue学生量化考核系统(程序+LW+部署)

项目运行 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; SSM mybatis Maven Vue 等等组成&#xff0c;B/S模式 M…