卷积神经网络 svm分类器_使用卷积神经网络的狗品种分类器

本文介绍了一种使用卷积神经网络(CNN)进行狗品种分类的方法,探讨了CNN在计算机视觉任务中的应用,特别是针对TensorFlow框架的实现。
摘要由CSDN通过智能技术生成

卷积神经网络 svm分类器

介绍 (Introduction)

Do you know the breed of the dog in the picture above? If you don’t then it’s completely fine because I don’t know either. Well, we come across a lot of different breeds of dogs while walking on the street and the second thing that we want to know is his breed (wondering what’s the first thing?! His name!). Why waste time then and let’s take some help from one of the most popular machine learning methods namely Convolutional Neural Network (CNN) to detect the breed of the dog. In this article, we will review a full algorithm to detect the breed of the dog using the given Dataset. We will also see how to use a pre-trained ResNet50 model to use it to detect the breed of the dog.

您知道上图中的狗的品种吗? 如果您不这样做,那完全没问题,因为我也不知道。 好吧,我们在街上散步时遇到了许多不同品种的狗,我们想知道的第二件事是他的品种(想知道第一件事是什么!!他的名字!)。 为什么浪费时间,然后让我们从最流行的机器学习方法之一(即卷积神经网络(CNN))中寻求帮助,以检测狗的品种。 在本文中,我们将回顾使用给定的数据集来检测狗的品种的完整算法 我们还将看到如何使用经过预训练的ResNet50模型来检测狗的品种。

一步步! (Step by Step!)

  • Import the Dataset

    导入数据集
  • Detect Humans using CV2

    使用CV2检测人类
  • Detect Dogs

    检测狗
  • Create a CNN to classify Dog Breeds (from Scratch)

    创建CNN对狗的品种进行分类(从头开始)
  • Use a CNN to Classify Dog Breeds (using Transfer Learning)

    使用CNN对狗的品种进行分类(使用转移学习)
  • Create a CNN to Classify Dog Breeds (using Transfer Learning)

    创建CNN对狗的品种进行分类(使用转移学习)
  • Write the Algorithm

    编写算法
  • Test the Algorithm

    测试算法

STEP-1导入数据集 (STEP-1 Import the Dataset)

Our dataset contains 8351 total dog images with 133 different categories of breed.

我们的数据集包含8351张狗图像,其中包含133个不同类别的犬种。

def load_dataset(path):
data = load_files(path)
dog_files = np.array(data['filenames'])
dog_targets = np_utils.to_categorical(np.array(data['target']), 133)
return dog_files, dog_targets

After calling the above function and passing the path of the images where it is stored, the dog_files would contain the path of all the images in the whole dataset and the dog_targets would contain the one-hot encoded 133 variables. Let’s load the train, test, and validation sets using the above function.

调用上述函数并传递存储图像的路径后,dog_files将包含整个数据集中所有图像的路径,而dog_targets将包含一键编码的133个变量。 让我们使用上述功能加载训练,测试和验证集。

train_files, train_targets = load_dataset('../../../data/dog_images/train')
valid_files, valid_targets = load_dataset('../../../data/dog_images/valid')
test_files, test_targets = load_dataset('../../../data/dog_images/test')

步骤2检测人类 (STEP-2 Detect Humans)

To add a feature to our model where any human disguised in a dog’s costume does not fool our classification results, we will detect humans through OpenCV’s implementation of Haar feature-based cascade classifiers. To implement this, the following is the code:

为了在我们的模型中增加一个伪装成狗装的人不会欺骗我们分类结果的功能,我们将通过OpenCV实施基于Haar特征的级联分类器来检测人。 为了实现这一点,下面是代码:

import cv2# extract pre-trained face detector
# cv2.CascadeClassifier is the model for detecting faces

face_cascade = cv2.CascadeClassifier('haarcascades/haarcascade_frontalface_alt.xml')# load color (BGR) image
# cv2.imread(image_file_name) reads an image
img = cv2.imread(human_files[3])# convert BGR image to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)# find faces in image
faces = face_cascade.detectMultiScale(gray)# print number of faces detected in the image
print('Number of faces detected:', len(faces))

You can expect to have something like this:

您可以期望有这样的东西:

Image for post
Image by Author
图片作者

The result on the test data predicted 11% of the dogs to be human faces.

测试数据的结果预测11%的狗是人脸。

STEP-3检测狗 (STEP-3 Detect Dogs

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值