cnn分类学习率技巧_CNN转移学习的犬种分类

cnn分类学习率技巧

Transfer learning make use of the knowledge gained while solving one problem and applying it to a different but related problem. They utilize knowledge acquired for one task to solve related ones.

贸易交接学习化妆运用所学知识在解决一个问题,并把它应用到一个不同但相关的问题得到。 他们利用一项任务获得的知识来解决相关任务。

The project is divided into seven steps and I am going to walk you through each of these steps.

该项目分为七个步骤,我将逐步指导您完成这些步骤。

1.导入数据集 (1. Importing the Datasets)

Dog Data Set

狗数据集

The dog data set is divided and loaded into train, validation and test groups. There are a total of 8351 images each belonging to one of the 133 dog breeds. The division for the train, validation and test set are made in the ratio of 80:10:10 .

狗数据集被划分并加载到训练,验证和测试组中。 共有8351张图片,每张图片都属于133个犬种之一。 训练,验证和测试集的划分比例为80:10:10。

Human Data Set

人数据集

There are a total of 13233 human images loaded into an array.

总共将13233个人图像加载到一个数组中。

2.检测人类 (2. Detecting Humans)

In this step we make use of the Haar feature-based cascade classifiers for detecting the human face in the images. We make use of a pre-trained model from OpenCV, haarcascades for the face detection.

在这一步中,我们利用基于Haar特征的级联分类器来检测图像中的人脸。 我们使用来自OpenCV经过预先训练的模型(人ar)来进行人脸检测。

Image for post
A sample output of the face detection model used in this project
该项目中使用的面部检测模型的样本输出

We then assess this face detector by passing in images of human and dogs. The model is able to detect human faces with a probability of 100% however when we pass an image of the dog the model detects the face only 11% of time.

然后,我们通过传递人和狗的图像来评估该面部检测器。 该模型能够以100%的概率检测人脸,但是当我们传递狗的图像时,该模型仅11%的时间会检测到人脸。

3.检测狗 (3. Detecting dogs)

Now we move on to making a detector for dogs. We make use of the pre-trained ResNet-50 model for this prediction. Using this model for prediction we see that the model perform fairly well in identifying dogs with a probability of 100% whereas it does not identify a human’s image as a dog.

现在我们继续制作狗的探测器。 我们使用预训练的ResNet-50模型进行此预测。 使用该模型进行预测,我们可以看到该模型在识别狗方面的性能相当好,概率为100%,而不能将人的图像识别为狗。

So for a predicting a dog breed closest to the human’s face this model fails.

因此,对于预测最接近人脸的犬种,此模型将失败。

4.创建CNN以对狗的品种进行分类 (4. Creating a CNN for classifying the Dog’s Breed)

Now we try to develop a CNN model for prediction.

现在,我们尝试开发CNN模型进行预测。

Image for post
The Architecture used for the CNN model
CNN模型使用的架构

It is really difficult to distinguish between breeds as they share similar characteristics, for this reason I decided to use Convolutional Layers in order to identify increasingly complex patterns with the hinted architecture as a base. The three convolutional layers should be able to capture most of the features

由于它们具有相似的特征,因此很难区分它们,因此,我决定使用卷积层,以便以提示的体系结构为基础来识别日益复杂的模式。 三个卷积层应该能够捕获大多数特征

  • The first convolutional layer with 16 filters identifies lower level features such as edges or lines. The input_shape is (224, 224, 3).

    具有16个滤镜的第一卷积层标识较低级别的特征,例如边缘或线条。 input_shape为(224、224、3)。
  • The second convolutional layer with 32 filters identifies more complex features such as shapes.

    具有32个滤镜的第二个卷积层识别更复杂的特征,例如形状。
  • The third convolutional layer with 64 filters identifies high level features.

    具有64个滤镜的第三卷积层可识别高级特征。
  • The MaxPooling layer after each converlutional layer reduces the size of the representation by 50% for height and width.

    每个融合层之后的MaxPooling层将表示形式的高度和宽度减小50%。
  • The GlableAveragePooling layer changes the size of height and width to one, then feed it to the last dense layer.

    GlableAveragePooling层将高度和宽度的大小更改为1,然后将其输入到最后一个密集层。
  • The Dense layer with 133 nodes and the softmax function classifies the image into one of the 133 dog breeds.

    具有133个节点的密集层和softmax函数将图像分类为133个犬种之一。

Since the data set is relatively small the performance of the model is pretty mediocre and achieves a test accuracy of only about 4.3%.

由于数据集相对较小,因此模型的性能相当中等,并且仅达到约4.3%的测试精度。

5.使用预训练的VGG16通过转移学习对狗进行分类 (5. Using a pre-trained VGG16 for Dog Classification using Transfer Learning)

First we obtain the bottleneck features for the model. These bottleneck features are the ones which aid in the transfer learning. In this section we use a VGG16 model for the classification task.

首先,我们获得模型的瓶颈特征。 这些瓶颈特征是有助于转移学习的特征。 在本节中,我们将VGG16模型用于分类任务。

VGG16 Architecture
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
global_average_pooling2d_2 ( (None, 512) 0
_________________________________________________________________
dense_2 (Dense) (None, 133) 68229
=================================================================
Total params: 68,229
Trainable params: 68,229
Non-trainable params: 0
_________________________________________________________________

This model achieves a test accuracy of 46.29%. Though a decent improvement from the previous model trained from scratch the accuracy is still not very satisfying to used for a real world application.

该模型的测试精度达到46.29%。 尽管相对于从头开始训练的先前模型进行了相当大的改进,但对于实际应用而言,准确性仍然不是很令人满意。

6.使用预训练的Xception模型通过转移学习对狗的品种进行分类 (6. Using a pretrained Xception model for classifying Dog’s Breed using Transfer Learning)

In this section Xception model is used for the classification task. Transfer learning is used by importing the train, validation and test bottleneck features.

在本节中,Xception模型用于分类任务。 通过导入训练,验证和测试瓶颈功能来使用转移学习。

Xception Model Architecture
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
global_average_pooling2d_3 ( (None, 2048) 0
_________________________________________________________________
dense_3 (Dense) (None, 256) 524544
_________________________________________________________________
dropout_1 (Dropout) (None, 256) 0
_________________________________________________________________
dense_4 (Dense) (None, 133) 34181
=================================================================
Total params: 558,725
Trainable params: 558,725
Non-trainable params: 0
_________________________________________________________________

This model achieves a test accuracy of 84.92% which is impressive considering the difficulty in identifying dog’s breeds considering how difficult it is even for a user to distinguish some similar breeds.

该模型实现了84.92%的测试准确度,考虑到识别狗的品种的难度,甚至考虑到用户区分一些相似品种的难度,这一结果令人印象深刻。

7.在算法中使用Xception模型进行预测 (7. Using the Xception model in an Algorithm for making the Predictions)

Some of the sample predictions from the algorithm are shown below.

该算法的一些样本预测如下所示。

Image for post
Dog which is a Welsh_springer_spaniel. 狗是威尔士史宾格犬。
Image for post
Human looking similar to a Australian_shepherd. 看起来像澳大利亚牧羊犬的人。
Image for post
Dog which is a Labrador_retriever. 狗是拉布拉多犬。
Image for post
No Dog or Human found in the image 在图像中找不到狗或人
Image for post
Dog which is a Brittany. 狗是布列塔尼。
Image for post
Human looking similar to a Afghan_hound. 与Afghan_hound相似的人类。

结果 (Results)

We can see that the prediction accuracy is acceptable and the model also performs well on identifying a breed close to a human.

我们可以看到预测准确性是可以接受的,并且该模型在识别接近人类的品种上也表现良好。

Link to the GitHub project

链接到GitHub项目

翻译自: https://medium.com/analytics-vidhya/dog-breeds-classification-with-cnn-transfer-learning-5b992d58ee85

cnn分类学习率技巧

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值