比较TensorFlow中全连接,简单CNN和ResNet50在二进制图像分类中的性能

In the world of machine learning, there are three models that you can use to perform binary image classification: a fully-connected network, a convolutional neural network, or a pre-trained network like MobileNet with transfer learning applied to it. In my previous stories, I showed how to implement these models to build an image classifier that can classify dandelions and grass and evaluate their performance by computing their accuracy, ROC curves, and AUC score. In this story, I will compare these models side-by-side and compare their performances. If you’d like to follow along the entire training, evaluation, and comparison of these models, follow this notebook. You can run the code by saving your own copy by going to File -> Save a copy.

在机器学习的世界中,您可以使用三种模型来执行二进制图像分类: 完全连接的网络卷积神经网络像MobileNet这样预训练网络,其中应用了转移学习 。 在我以前的故事中,我展示了如何实施这些模型来构建图像分类器,该分类器可以对蒲公英和草进行分类,并通过计算其准确性,ROC曲线和AUC得分来评估其性能。 在这个故事中,我将并排比较这些模型并比较它们的性能。 如果您想按照这些模型进行整个培训,评估和比较,请遵循此笔记本。 您可以通过转到文件->保存副本来保存自己的副本来运行代码。

Which model do you think will perform best?

您认为哪种模型效果最好?

模型架构概述 (Overview of the Model Architectures)

Firstly, let’s take a look at the three model architectures and see how they differ:

首先,让我们看一下三种模型架构,看看它们之间的区别:

FULLY-CONNECTED MODELLayer (type)                 Output Shape              Param #    ================================================================= flatten (Flatten)            (None, 120000)            0          _________________________________________________________________ dense (Dense)                (None, 128)               15360128   _________________________________________________________________ dense_1 (Dense)              (None, 1)                 129        ================================================================= Total params: 15,360,257 Trainable params: 15,360,257 Non-trainable params: 0CONVOLUTIONAL NEURAL NETWORK MODELLayer (type)                 Output Shape              Param #    ================================================================= conv2d (Conv2D)              (None, 198, 198, 16)      448        _________________________________________________________________ max_pooling2d (MaxPooling2D) (None, 99, 99, 16)        0          _________________________________________________________________ conv2d_1 (Conv2D)            (None, 97, 97, 32)        4640       _________________________________________________________________ max_pooling2d_1 (MaxPooling2 (None, 48, 48, 32)        0          _________________________________________________________________ conv2d_2 (Conv2D)            (None, 46, 46, 64)        18496      _________________________________________________________________ max_pooling2d_2 (MaxPooling2 (None, 23, 23, 64)        0          _________________________________________________________________ conv2d_3 (Conv2D)            (None, 21, 21, 64)        36928      _________________________________________________________________ max_pooling2d_3 (MaxPooling2 (None, 10, 10, 64)        0          _________________________________________________________________ conv2d_4 (Conv2D)            (None, 8, 8, 64)          36928      _________________________________________________________________ max_pooling2d_4 (MaxPooling2 (None, 4, 4, 64)          0          _________________________________________________________________ flatten (Flatten)            (None, 1024)              0          _________________________________________________________________ dense (Dense)                (None, 512)               524800     _________________________________________________________________ dense_1 (Dense)              (None, 1)                 513        ================================================================= Total params: 622,753 Trainable params: 622,753 Non-trainable params: 0MOBILENET w/ TRANSFER LEARNINGLayer (type)                 Output Shape              Param #    ================================================================= mobilenetv2_1.00_224 (Model) (None, 7, 7, 1280)        2257984    _________________________________________________________________ global_average_pooling2d (Gl (None, 1280)              0          _________________________________________________________________ dense (Dense)                (None, 1)                 1281       ================================================================= Total params: 2,259,265 Trainable params: 1,281 Non-trainable params: 2,257,984

Notice how the fully-connected model has the highest number of trainable parameters, followed by the CNN model, followed by the MobileNet model. In the FC model, every connection in the Flatten layer is connected to every connection in the Dense layer, resulting in a higher number of parameters. In the CNN, fewer parameters are needed because every convolutional layer reduces the dimensions of the input through the convolution operation. And in contrast to those two models, the MobileNet model uses what is called transfer learning: it doesn’t train on the pre-trained layers and only trains a final Dense layer. It takes advantage of the feature extraction capabilities of the pre-trained layers for training that last layer, so only few parameters are needed to train the model.

请注意,完全连接的模型如何具有最多的可训练参数数量,其次是CNN模型,其次是MobileNet模型。 在FC模型中,Flatten层中的每个连接都与Dense层中的每个连接相连,从而导致更多的参数。 在CNN中,需要较少的参数,因为每个卷积层都会通过卷积操作减小输入的尺寸。 与这两个模型相反,MobileNet模型使用所谓的转移学习:它不在预先训练的层上进行训练,而仅在最终的密集层上进行训练。 它利用了预训练层的特征提取功能来训练最后一层,因此只需很少的参数即可训练模型。

比较精度 (Comparing the Accuracies)

For each model, I used the same dataset and trained the model with 15 epochs. Let’s bring the results together and compare them side-by-side, starting with the accuracies :

对于每个模型,我使用相同的数据集并以15个时期训练模型。 让我们将结果汇总在一起,并从准确性开始并排比较:

FC accuracy: 0.5987
CNN accuracy: 0.7197
MobileNet accuracy: 0.8917

The MobileNet model has the highest accuracy, followed by the CNN model, followed by the fully-connected model.

MobileNet模型具有最高的准确性,其次是CNN模型,其次是全连接模型。

比较ROC曲线和AUC (Comparing the ROC Curves and AUC)

Image for post
combined plot of ROC curves
ROC曲线组合图

Accuracy isn’t the best way to compare model performance. Better metrics for classification tasks include ROC curves and AUC, which measure how much our model is capable of distinguishing between our two classes, dandelions and grass. The higher the AUC, the better our model is at classification. In the plot above, MobileNet scores highest in AUC, followed by CNN, followed by FC.

准确性不是比较模型性能的最佳方法。 更好的分类任务指标包括ROC曲线和AUC,它们衡量了我们的模型能够区分我们的两个类别(蒲公英和草)的能力。 AUC越高,我们的模型在分类上就越好。 在上面的图中,MobileNet在AUC中得分最高,其次是CNN,其次是FC。

Here are the takeaways from these comparisons:

以下是这些比较的要点:

  • The MobileNet model is a superior model in terms of accuracy and ROC curve/AUC, even though it doesn’t have the most parameters. This shows the power of transfer learning over a powerful trained model.

    就其准确性和ROC曲线/ AUC而言,MobileNet模型是一个出色的模型,尽管它没有最多的参数。 这显示了强大的训练模型上的转移学习的力量。
  • The CNN model comes in 2nd. Convolutional Neural Networks perform better than fully-connected networks on binary image classification, with a lot less parameters, because of their shared-weights architecture and translation invariance characteristics.

    CNN模型排在第二位。 卷积神经网络由于具有共享权重架构和平移不变性,因此在二值图像分类方面比全连接网络表现更好,但参数却少得多。
  • The fully-connected model performs better than chance at binary image classification, but it isn’t the optimal model to do so.

    完全连接的模型在二值图像分类中的表现要好于偶然性,但这并不是最佳选择。

翻译自: https://towardsdatascience.com/comparing-the-performance-of-fully-connected-simple-cnn-and-resnet50-for-binary-image-5dae3cea034

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值