Tensorflow和预训练模型如何用于特征提取?

Tensorflow是Google提供的一种机器学习框架。它是一个开放源代码框架,可与Python结合使用,以实现算法,深度学习应用程序等等。它用于研究和生产目的。

它具有优化技术,可帮助快速执行复杂的数学运算。

这是因为它使用了NumPy和多维数组。这些多维数组也称为“张量”。该框架支持使用深度神经网络。它具有高度的可扩展性,并附带许多流行的数据集。它使用GPU计算并自动进行资源管理。它带有大量的机器学习库,并且得到了良好的支持和记录。该框架具有运行深度神经网络模型,对其进行训练以及创建可预测各个数据集相关特征的应用程序的能力。

可以使用下面的代码行在Windows上安装'tensorflow'软件包-

pip install tensorflow

Tensor是TensorFlow中使用的数据结构。它有助于连接流程图中的边缘。该流程图称为“数据流程图”。张量不过是多维数组或列表。

Keras在希腊语中的意思是“号角”。Keras被开发为ONEIROS(开放式神经电子智能机器人操作系统)项目研究的一部分。Keras是使用Python编写的深度学习API。它是一个高级API,具有可帮助解决机器学习问题的高效接口。

它在Tensorflow框架之上运行。它旨在帮助快速进行实验。它提供了在开发和封装机器学习解决方案中必不可少的基本抽象和构建块。

它具有高度的可扩展性,并具有跨平台功能。这意味着Keras可以在TPU或GPU集群上运行。Keras模型也可以导出为在Web浏览器或手机中运行。

Keras已经存在于Tensorflow软件包中。可以使用下面的代码行进行访问。

import tensorflow

from tensorflow import keras

我们将使用Keras Sequential API,它有助于构建用于与简单的层堆栈配合使用的顺序模型,其中每一层都具有一个输入张量和一个输出张量。

包含至少一层的神经网络称为卷积层。卷积神经网络通常由以下提到的层的某种组合组成-

  • 卷积层

  • 汇聚层

  • 致密层

卷积神经网络已用于为特定类型的问题(例如图像识别)产生出色的结果。

我们正在使用Google合作实验室来运行以下代码。Google Colab或Colaboratory可以帮助通过浏览器运行Python代码,并且需要零配置和对GPU(图形处理单元)的免费访问。合作已建立在Jupyter Notebook的基础上。

我们将了解如何借助来自预训练网络的转移学习对猫和狗的图像进行分类。

预先训练的模型是一个保存的网络,该网络先前会在大型数据集上进行训练。这个大数据集将是大规模的图像分类任务。可以按需使用预训练的模型,也可以根据需求和模型对它进行定制,并进行迁移学习。

用于图像分类的转移学习背后的直觉是,如果在大型通用数据集上训练模型,则该模型可以有效地用作视觉世界的通用模型。它将学习到功能图,这意味着用户不必通过在大型数据集上训练大型模型而从头开始。

定制模型可以通过两种方式进行预训练-

特征提取-先前网络学习到的表示可用于从新样本中提取有意义的特征。可以添加一个新分类器,该分类器将从头开始进行训练,该分类器将位于预训练模型的顶部。这可用于重新调整先前为数据集学习的特征图的用途。

整个模型不需要重新训练。基本卷积网络将已经具有通常用于对图片进行分类的功能。

但是预训练模型的最终分类部分是针对原始分类任务的。这意味着它特定于训练模型的一组课程。

微调-取消冻结已冻结模型基础的某些顶层,并将新添加的分类器层以及基础模型的最后层一起训练。这将允许用户“微调”基本模型中的高阶特征表示。这有助于使模型与特定任务更加相关。

示例

print("Feature extraction")

base_model.trainable = False

print("The base model architecture")

base_model.summary()

代码信用-https://www.tensorflow.org/tutorials/images/transfer_learning

输出结果

Feature extraction

The base model architecture

Model: "mobilenetv2_1.00_160"

__________________________________________________________________________________________________

Layer (type)                   Output Shape       Param #   Connected to

==================================================================================================

input_1 (InputLayer)         [(None, 160, 160, 3)             0

__________________________________________________________________________________________________

Conv1 (Conv2D)              (None, 80, 80, 32)      864       input_1[0][0]

__________________________________________________________________________________________________

bn_Conv1 (BatchNormalization) (None, 80, 80, 32)   128         Conv1[0][0]

__________________________________________________________________________________________________

Conv1_relu (ReLU)           (None, 80, 80, 32)       0       bn_Conv1[0][0]

__________________________________________________________________________________________________

expanded_conv_depthwise (Depthw (None, 80, 80, 32)   288         Conv1_relu[0][0]

__________________________________________________________________________________________________

expanded_conv_depthwise_BN (Bat (None, 80, 80, 32)   128       expanded_conv_depthwise[0][0]

__________________________________________________________________________________________________

expanded_conv_depthwise_relu (R (None, 80, 80, 32)    0       expanded_conv_depthwise_BN[0][0]

__________________________________________________________________________________________________

expanded_conv_project (Conv2D)  (None, 80, 80, 16)   512           expanded_conv_depthwise_relu[0][0

__________________________________________________________________________________________________

expanded_conv_project_BN (Batch (None, 80, 80, 16)      64       expanded_conv_project[0][0]

__________________________________________________________________________________________________

block_1_expand (Conv2D)    (None, 80, 80, 96)         1536         expanded_conv_project_BN[0][0]

__________________________________________________________________________________________________

block_1_expand_BN (BatchNormali  (None, 80, 80, 96)     384            block_1_expand[0][0]

__________________________________________________________________________________________________

block_1_expand_relu (ReLU)  (None, 80, 80, 96)        0            block_1_expand_BN[0][0]

__________________________________________________________________________________________________

block_1_pad (ZeroPadding2D)  (None, 81, 81, 96)     0            block_1_expand_relu[0][0]

__________________________________________________________________________________________________

block_1_depthwise (DepthwiseCon (None, 40, 40, 96)   864           block_1_pad[0][0]

__________________________________________________________________________________________________

block_1_depthwise_BN (BatchNorm (None, 40, 40, 96)   384          block_1_depthwise[0][0]

__________________________________________________________________________________________________

block_1_depthwise_relu (ReLU)   (None, 40, 40, 96)   0             block_1_depthwise_BN[0][0]

__________________________________________________________________________________________________

block_1_project (Conv2D)     (None, 40, 40, 24)    2304           block_1_depthwise_relu[0][0]

__________________________________________________________________________________________________

block_1_project_BN (BatchNormal  (None, 40, 40, 24)   96          block_1_project[0][0]

__________________________________________________________________________________________________

block_2_expand (Conv2D) (None, 40, 40, 144)    3456           block_1_project_BN[0][0]

__________________________________________________________________________________________________

block_2_expand_BN (BatchNormali (None, 40, 40, 144)   576          block_2_expand[0][0]

__________________________________________________________________________________________________

block_2_expand_relu (ReLU) (None, 40, 40, 144)     0           block_2_expand_BN[0][0]

__________________________________________________________________________________________________

block_2_depthwise (DepthwiseCon (None, 40, 40, 144)   1296       block_2_expand_relu[0][0]

__________________________________________________________________________________________________

block_2_depthwise_BN (BatchNorm (None, 40, 40, 144)   576      block_2_depthwise[0][0]

__________________________________________________________________________________________________

block_2_depthwise_relu (ReLU) (None, 40, 40, 144)    0        block_2_depthwise_BN[0][0]

__________________________________________________________________________________________________

block_2_project (Conv2D)   (None, 40, 40, 24)      3456      block_2_depthwise_relu[0][0]

__________________________________________________________________________________________________

block_2_project_BN (BatchNormal (None, 40, 40, 24)    96          block_2_project[0][0]

__________________________________________________________________________________________________

block_2_add (Add)        (None, 40, 40, 24)         0         block_1_project_BN[0][0]

block_2_project_BN[0][0]

__________________________________________________________________________________________________

block_3_expand (Conv2D)      (None, 40, 40, 144)     3456         block_2_add[0][0]

__________________________________________________________________________________________________

block_3_expand_BN (BatchNormali (None, 40, 40, 144)    576       block_3_expand[0][0]

__________________________________________________________________________________________________

block_3_expand_relu (ReLU) (None, 40, 40, 144)        0       block_3_expand_BN[0][0]

__________________________________________________________________________________________________

block_3_pad (ZeroPadding2D) (None, 41, 41, 144)   0          block_3_expand_relu[0][0]

__________________________________________________________________________________________________

block_3_depthwise (DepthwiseCon (None, 20, 20, 144)  1296         block_3_pad[0][0]

__________________________________________________________________________________________________

block_3_depthwise_BN (BatchNorm (None, 20, 20, 144)   576    block_3_depthwise[0][0]

__________________________________________________________________________________________________

block_3_depthwise_relu (ReLU)   (None, 20, 20, 144)   0         block_3_depthwise_BN[0][0]

__________________________________________________________________________________________________

block_3_project (Conv2D)   (None, 20, 20, 32)      4608          block_3_depthwise_relu[0][0]

__________________________________________________________________________________________________

block_3_project_BN (BatchNormal  (None, 20, 20, 32)  128      block_3_project[0][0]

__________________________________________________________________________________________________

block_4_expand (Conv2D)   (None, 20, 20, 192)     6144         block_3_project_BN[0][0]

__________________________________________________________________________________________________

block_4_expand_BN (BatchNormali (None, 20, 20, 192)   768       block_4_expand[0][0]

__________________________________________________________________________________________________

block_4_expand_relu (ReLU)   (None, 20, 20, 192)    0        block_4_expand_BN[0][0]

__________________________________________________________________________________________________

block_4_depthwise (DepthwiseCon (None, 20, 20, 192)   1728       block_4_expand_relu[0][0]

__________________________________________________________________________________________________

block_4_depthwise_BN (BatchNorm   (None, 20, 20, 192)    768       block_4_depthwise[0][0]

__________________________________________________________________________________________________

block_4_depthwise_relu (ReLU)   (None, 20, 20, 192)     0         block_4_depthwise_BN[0][0]

__________________________________________________________________________________________________

block_4_project (Conv2D)   (None, 20, 20, 32)        6144      block_4_depthwise_relu[0][0]

__________________________________________________________________________________________________

block_4_project_BN (BatchNormal  (None, 20, 20, 32)   128        block_4_project[0][0]

__________________________________________________________________________________________________

block_4_add (Add)         (None, 20, 20, 32)       0        block_3_project_BN[0][0]

block_4_project_BN[0][0]

__________________________________________________________________________________________________

block_5_expand (Conv2D)   (None, 20, 20, 192)      6144            block_4_add[0][0]

__________________________________________________________________________________________________

block_5_expand_BN (BatchNormali (None, 20, 20, 192)   768         block_5_expand[0][0]

__________________________________________________________________________________________________

block_5_expand_relu (ReLU) (None, 20, 20, 192)          0        block_5_expand_BN[0][0]

__________________________________________________________________________________________________

block_5_depthwise (DepthwiseCon  (None, 20, 20, 192)   1728      block_5_expand_relu[0][0]

__________________________________________________________________________________________________

block_5_depthwise_BN (BatchNorm (None, 20, 20, 192)   768       block_5_depthwise[0][0]

__________________________________________________________________________________________________

block_5_depthwise_relu (ReLU)   (None, 20, 20, 192)      0       block_5_depthwise_BN[0][0]

__________________________________________________________________________________________________

block_5_project (Conv2D)   (None, 20, 20, 32)         6144    block_5_depthwise_relu[0][0]

__________________________________________________________________________________________________

block_5_project_BN (BatchNormal  (None, 20, 20, 32)   128       block_5_project[0][0]

__________________________________________________________________________________________________

block_5_add (Add)           (None, 20, 20, 32)      0       block_4_add[0][0]

block_5_project_BN[0][0]

__________________________________________________________________________________________________

block_6_expand (Conv2D)     (None, 20, 20, 192)     6144          block_5_add[0][0]

__________________________________________________________________________________________________

block_6_expand_BN (BatchNormali (None, 20, 20, 192)   768     block_6_expand[0][0]

__________________________________________________________________________________________________

block_6_expand_relu (ReLU)   (None, 20, 20, 192)    0      block_6_expand_BN[0][0]

__________________________________________________________________________________________________

block_6_pad (ZeroPadding2D)  (None, 21, 21, 192)   0       block_6_expand_relu[0][0]

__________________________________________________________________________________________________

block_6_depthwise (DepthwiseCon (None, 10, 10, 192)   1728       block_6_pad[0][0]

__________________________________________________________________________________________________

block_6_depthwise_BN (BatchNorm (None, 10, 10, 192)   768         block_6_depthwise[0][0]

__________________________________________________________________________________________________

block_6_depthwise_relu (ReLU) (None, 10, 10, 192)   0    block_6_depthwise_BN[0][0]

__________________________________________________________________________________________________

block_6_project (Conv2D) (None, 10, 10, 64)  12288         block_6_depthwise_relu[0][0]

__________________________________________________________________________________________________

block_6_project_BN (BatchNormal (None, 10, 10, 64)   256        block_6_project[0][0]

__________________________________________________________________________________________________

block_7_expand (Conv2D) (None, 10, 10, 384)        24576        block_6_project_BN[0][0]

__________________________________________________________________________________________________

block_7_expand_BN (BatchNormali (None, 10, 10, 384)  1536        block_7_expand[0][0]

__________________________________________________________________________________________________

block_7_expand_relu (ReLU) (None, 10, 10, 384)      0         block_7_expand_BN[0][0]

__________________________________________________________________________________________________

block_7_depthwise (DepthwiseCon (None, 10, 10, 384)  3456       block_7_expand_relu[0][0]

__________________________________________________________________________________________________

block_7_depthwise_BN (BatchNorm (None, 10, 10, 384)  1536          block_7_depthwise[0][0]

__________________________________________________________________________________________________

block_7_depthwise_relu (ReLU) (None, 10, 10, 384)    0            block_7_depthwise_BN[0][0]

__________________________________________________________________________________________________

block_7_project (Conv2D) (None, 10, 10, 64)     24576          block_7_depthwise_relu[0][0]

__________________________________________________________________________________________________

block_7_project_BN (BatchNormal (None, 10, 10, 64)   256            block_7_project[0][0]

__________________________________________________________________________________________________

block_7_add (Add) (None, 10, 10, 64)          0               block_6_project_BN[0][0]

block_7_project_BN[0][0]

__________________________________________________________________________________________________

block_8_expand (Conv2D) (None, 10, 10, 384) 24576 block_7_add[0][0]

__________________________________________________________________________________________________

block_8_expand_BN (BatchNormali (None, 10, 10, 384) 1536 block_8_expand[0][0]

__________________________________________________________________________________________________

block_8_expand_relu (ReLU) (None, 10, 10, 384) 0 block_8_expand_BN[0][0]

__________________________________________________________________________________________________

block_8_depthwise (DepthwiseCon (None, 10, 10, 384) 3456 block_8_expand_relu[0][0]

__________________________________________________________________________________________________

block_8_depthwise_BN (BatchNorm (None, 10, 10, 384) 1536 block_8_depthwise[0][0]

__________________________________________________________________________________________________

block_8_depthwise_relu (ReLU) (None, 10, 10, 384) 0 block_8_depthwise_BN[0][0]

__________________________________________________________________________________________________

block_8_project (Conv2D) (None, 10, 10, 64) 24576 block_8_depthwise_relu[0][0]

__________________________________________________________________________________________________

block_8_project_BN (BatchNormal (None, 10, 10, 64) 256 block_8_project[0][0]

__________________________________________________________________________________________________

block_8_add (Add) (None, 10, 10, 64) 0 block_7_add[0][0]

block_8_project_BN[0][0]

__________________________________________________________________________________________________

block_9_expand (Conv2D) (None, 10, 10, 384) 24576 block_8_add[0][0]

__________________________________________________________________________________________________

block_9_expand_BN (BatchNormali (None, 10, 10, 384) 1536 block_9_expand[0][0]

__________________________________________________________________________________________________

block_9_expand_relu (ReLU) (None, 10, 10, 384) 0 block_9_expand_BN[0][0]

__________________________________________________________________________________________________

block_9_depthwise (DepthwiseCon (None, 10, 10, 384) 3456 block_9_expand_relu[0][0]

__________________________________________________________________________________________________

block_9_depthwise_BN (BatchNorm (None, 10, 10, 384) 1536 block_9_depthwise[0][0]

__________________________________________________________________________________________________

block_9_depthwise_relu (ReLU) (None, 10, 10, 384) 0 block_9_depthwise_BN[0][0]

__________________________________________________________________________________________________

block_9_project (Conv2D) (None, 10, 10, 64) 24576 block_9_depthwise_relu[0][0]

__________________________________________________________________________________________________

block_9_project_BN (BatchNormal (None, 10, 10, 64) 256 block_9_project[0][0]

__________________________________________________________________________________________________

block_9_add (Add) (None, 10, 10, 64) 0 block_8_add[0][0]

block_9_project_BN[0][0]

__________________________________________________________________________________________________

block_10_expand (Conv2D) (None, 10, 10, 384) 24576 block_9_add[0][0]

__________________________________________________________________________________________________

block_10_expand_BN (BatchNormal (None, 10, 10, 384) 1536 block_10_expand[0][0]

__________________________________________________________________________________________________

block_10_expand_relu (ReLU) (None, 10, 10, 384) 0 block_10_expand_BN[0][0]

__________________________________________________________________________________________________

block_10_depthwise (DepthwiseCo (None, 10, 10, 384) 3456 block_10_expand_relu[0][0]

__________________________________________________________________________________________________

block_10_depthwise_BN (BatchNor (None, 10, 10, 384) 1536 block_10_depthwise[0][0]

__________________________________________________________________________________________________

block_10_depthwise_relu (ReLU) (None, 10, 10, 384) 0 block_10_depthwise_BN[0][0]

__________________________________________________________________________________________________

block_10_project (Conv2D) (None, 10, 10, 96) 36864 block_10_depthwise_relu[0][0]

__________________________________________________________________________________________________

block_10_project_BN (BatchNorma (None, 10, 10, 96) 384 block_10_project[0][0]

__________________________________________________________________________________________________

block_11_expand (Conv2D) (None, 10, 10, 576) 55296 block_10_project_BN[0][0]

__________________________________________________________________________________________________

block_11_expand_BN (BatchNormal (None, 10, 10, 576) 2304 block_11_expand[0][0]

__________________________________________________________________________________________________

block_11_expand_relu (ReLU) (None, 10, 10, 576) 0 block_11_expand_BN[0][0]

__________________________________________________________________________________________________

block_11_depthwise (DepthwiseCo (None, 10, 10, 576) 5184 block_11_expand_relu[0][0]

__________________________________________________________________________________________________

block_11_depthwise_BN (BatchNor (None, 10, 10, 576) 2304 block_11_depthwise[0][0]

__________________________________________________________________________________________________

block_11_depthwise_relu (ReLU) (None, 10, 10, 576) 0 block_11_depthwise_BN[0][0]

__________________________________________________________________________________________________

block_11_project (Conv2D) (None, 10, 10, 96) 55296 block_11_depthwise_relu[0][0]

__________________________________________________________________________________________________

block_11_project_BN (BatchNorma (None, 10, 10, 96) 384 block_11_project[0][0]

__________________________________________________________________________________________________

block_11_add (Add) (None, 10, 10, 96) 0 block_10_project_BN[0][0]

block_11_project_BN[0][0]

__________________________________________________________________________________________________

block_12_expand (Conv2D) (None, 10, 10, 576) 55296 block_11_add[0][0]

__________________________________________________________________________________________________

block_12_expand_BN (BatchNormal (None, 10, 10, 576) 2304 block_12_expand[0][0]

__________________________________________________________________________________________________

block_12_expand_relu (ReLU) (None, 10, 10, 576) 0 block_12_expand_BN[0][0]

__________________________________________________________________________________________________

block_12_depthwise (DepthwiseCo (None, 10, 10, 576) 5184 block_12_expand_relu[0][0]

__________________________________________________________________________________________________

block_12_depthwise_BN (BatchNor (None, 10, 10, 576) 2304 block_12_depthwise[0][0]

__________________________________________________________________________________________________

block_12_depthwise_relu (ReLU) (None, 10, 10, 576) 0 block_12_depthwise_BN[0][0]

__________________________________________________________________________________________________

block_12_project (Conv2D) (None, 10, 10, 96) 55296 block_12_depthwise_relu[0][0]

__________________________________________________________________________________________________

block_12_project_BN (BatchNorma (None, 10, 10, 96) 384 block_12_project[0][0]

__________________________________________________________________________________________________

block_12_add (Add) (None, 10, 10, 96) 0 block_11_add[0][0]

block_12_project_BN[0][0]

__________________________________________________________________________________________________

block_13_expand (Conv2D) (None, 10, 10, 576) 55296 block_12_add[0][0]

__________________________________________________________________________________________________

block_13_expand_BN (BatchNormal (None, 10, 10, 576) 2304 block_13_expand[0][0]

__________________________________________________________________________________________________

block_13_expand_relu (ReLU) (None, 10, 10, 576) 0 block_13_expand_BN[0][0]

__________________________________________________________________________________________________

block_13_pad (ZeroPadding2D) (None, 11, 11, 576) 0 block_13_expand_relu[0][0]

__________________________________________________________________________________________________

block_13_depthwise (DepthwiseCo (None, 5, 5, 576)   5184       block_13_pad[0][0]

__________________________________________________________________________________________________

block_13_depthwise_BN (BatchNor (None, 5, 5, 576)   2304     block_13_depthwise[0][0]

__________________________________________________________________________________________________

block_13_depthwise_relu (ReLU) (None, 5, 5, 576)   0        block_13_depthwise_BN[0][0]

__________________________________________________________________________________________________

block_13_project (Conv2D) (None, 5, 5, 160)        92160   block_13_depthwise_relu[0][0]

__________________________________________________________________________________________________

block_13_project_BN (BatchNorma (None, 5, 5, 160)   640      block_13_project[0][0]

__________________________________________________________________________________________________

block_14_expand (Conv2D) (None, 5, 5, 960)     153600       block_13_project_BN[0][0]

__________________________________________________________________________________________________

block_14_expand_BN (BatchNormal (None, 5, 5, 960)   3840     block_14_expand[0][0]

__________________________________________________________________________________________________

block_14_expand_relu (ReLU) (None, 5, 5, 960)    0          block_14_expand_BN[0][0]

__________________________________________________________________________________________________

block_14_depthwise (DepthwiseCo (None, 5, 5, 960)  8640    block_14_expand_relu[0][0]

__________________________________________________________________________________________________

block_14_depthwise_BN (BatchNor (None, 5, 5, 960)  3840    block_14_depthwise[0][0]

__________________________________________________________________________________________________

block_14_depthwise_relu (ReLU) (None, 5, 5, 960)   0          block_14_depthwise_BN[0][0]

__________________________________________________________________________________________________

block_14_project (Conv2D) (None, 5, 5, 160)     153600       block_14_depthwise_relu[0][0]

__________________________________________________________________________________________________

block_14_project_BN (BatchNorma (None, 5, 5, 160)   640    block_14_project[0][0]

__________________________________________________________________________________________________

block_14_add (Add) (None, 5, 5, 160)         0             block_13_project_BN[0][0]

block_14_project_BN[0][0]

__________________________________________________________________________________________________

block_15_expand (Conv2D) (None, 5, 5, 960)     153600        block_14_add[0][0]

__________________________________________________________________________________________________

block_15_expand_BN (BatchNormal (None, 5, 5, 960)   3840      block_15_expand[0][0]

__________________________________________________________________________________________________

block_15_expand_relu (ReLU) (None, 5, 5, 960)   0       block_15_expand_BN[0][0]

__________________________________________________________________________________________________

block_15_depthwise (DepthwiseCo (None, 5, 5, 960)   8640      block_15_expand_relu[0][0]

__________________________________________________________________________________________________

block_15_depthwise_BN (BatchNor (None, 5, 5, 960)   3840      block_15_depthwise[0][0]

__________________________________________________________________________________________________

block_15_depthwise_relu (ReLU) (None, 5, 5, 960)    0       block_15_depthwise_BN[0][0]

__________________________________________________________________________________________________

block_15_project (Conv2D) (None, 5, 5, 160)    153600     block_15_depthwise_relu[0][0]

__________________________________________________________________________________________________

block_15_project_BN (BatchNorma (None, 5, 5, 160)   640      block_15_project[0][0]

__________________________________________________________________________________________________

block_15_add (Add) (None, 5, 5, 160) 0 block_14_add[0][0]

block_15_project_BN[0][0]

__________________________________________________________________________________________________

block_16_expand (Conv2D) (None, 5, 5, 960)   153600     block_15_add[0][0]

__________________________________________________________________________________________________

block_16_expand_BN (BatchNormal (None, 5, 5, 960)   3840     block_16_expand[0][0]

__________________________________________________________________________________________________

block_16_expand_relu (ReLU) (None, 5, 5, 960)    0      block_16_expand_BN[0][0]

__________________________________________________________________________________________________

block_16_depthwise (DepthwiseCo (None, 5, 5, 960)   8640       block_16_expand_relu[0][0]

__________________________________________________________________________________________________

block_16_depthwise_BN (BatchNor (None, 5, 5, 960)   3840     block_16_depthwise[0][0]

__________________________________________________________________________________________________

block_16_depthwise_relu (ReLU) (None, 5, 5, 960)    0   block_16_depthwise_BN[0][0]

__________________________________________________________________________________________________

block_16_project (Conv2D) (None, 5, 5, 320)         307200        block_16_depthwise_relu[0][0]

__________________________________________________________________________________________________

block_16_project_BN (BatchNorma (None, 5, 5, 320)         1280        block_16_project[0][0]

__________________________________________________________________________________________________

Conv_1 (Conv2D) (None, 5, 5, 1280)           409600           block_16_project_BN[0][0]

__________________________________________________________________________________________________

Conv_1_bn (BatchNormalization) (None, 5, 5, 1280)      5120          Conv_1[0][0]

__________________________________________________________________________________________________

out_relu (ReLU)        (None, 5, 5, 1280)        0            Conv_1_bn[0][0]

==================================================================================================

Total params: 2,257,984

Trainable params: 0

Non-trainable params: 2,257,984

_________________________________________________________________________

解释

  • 从上一步创建的卷积基础将被冻结,并用作特征提取器。

  • 在其顶部添加分类器,以训练顶级分类器。

  • 冻结是通过设置layer.trainable= False完成的。

  • 此步骤可避免训练期间更新图层中的权重。

  • MobileNet V2具有许多层,因此将模型的整个可训练标记设置为False将会冻结所有层。

  • 当layer.trainable= False时,BatchNormalization层以推理模式运行,并且不会更新均值和方差统计信息。

  • 取消冻结模型时,它包含BatchNormalization层以进行微调。

  • 可以通过在调用基本模型时传递训练= False来完成。

  • 否则,应用于不可训练权重的更新将破坏模型学到的知识。

以上是 Tensorflow和预训练模型如何用于特征提取? 的全部内容, 来源链接: utcz.com/z/342729.html

回到顶部