Keras中文文档

在ImageNet上预训练过的用于图像分类的模型

image-20230116020157943

模型 大小 Top-1 准确率 Top-5 准确率 参数数量 深度
Xception 88 MB 0.790 0.945 22,910,480 126
VGG16 528 MB 0.713 0.901 138,357,544 23
VGG19 549 MB 0.713 0.900 143,667,240 26
ResNet50 98 MB 0.749 0.921 25,636,712 -
ResNet101 171 MB 0.764 0.928 44,707,176 -
ResNet152 232 MB 0.766 0.931 60,419,944 -
ResNet50V2 98 MB 0.760 0.930 25,613,800 -
ResNet101V2 171 MB 0.772 0.938 44,675,560 -
ResNet152V2 232 MB 0.780 0.942 60,380,648 -
ResNeXt50 96 MB 0.777 0.938 25,097,128 -
ResNeXt101 170 MB 0.787 0.943 44,315,560 -
InceptionV3 92 MB 0.779 0.937 23,851,784 159
InceptionResNetV2 215 MB 0.803 0.953 55,873,736 572
MobileNet 16 MB 0.704 0.895 4,253,864 88
MobileNetV2 14 MB 0.713 0.901 3,538,984 88
DenseNet121 33 MB 0.750 0.923 8,062,504 121
DenseNet169 57 MB 0.762 0.932 14,307,880 169
DenseNet201 80 MB 0.773 0.936 20,242,984 201
NASNetMobile 23 MB 0.744 0.919 5,326,716 -
NASNetLarge 343 MB 0.825 0.960 88,949,818 -

VGG16

1
2
3
4
5
6
7
8
keras.applications.vgg16.VGG16(
include_top=True,
weights='imagenet',
input_tensor=None,
input_shape=None,
pooling=None,
classes=1000
)

重要参数

  • include_top: 是否包括顶层的全连接层。

  • weights: None 代表随机初始化, 'imagenet' 代表加载在 ImageNet 上预训练的权值。

  • input_tensor: 可选,Keras tensor 作为模型的输入(即 layers.Input() 输出的 tensor)。

  • input_shape: 可选,输入尺寸元组,仅当 include_top=False 时有效,否则输入形状必须是 (244, 244, 3)(对于 channels_last 数据格式),或者 (3, 244, 244)(对于 channels_first 数据格式)。它必须拥有 3 个输入通道,且宽高必须不小于 32。例如 (200, 200, 3) 是一个合法的输入尺寸。

  • pooling

    : 可选,当include_top为False时,该参数指定了特征提取时的池化方式。

    • None 代表不池化,直接输出最后一层卷积层的输出,该输出是一个四维张量。
    • 'avg' 代表全局平均池化(GlobalAveragePooling2D),相当于在最后一层卷积层后面再加一层全局平均池化层,输出是一个二维张量。
    • 'max' 代表全局最大池化
  • classes: 可选,图片分类的类别数,仅当 include_top 为 True 并且不加载预训练权值时可用。

VGG16 模型,权值由 ImageNet 训练而来。

该模型可同时构建于 channels_first (通道,高度,宽度) 和 channels_last (高度,宽度,通道)两种输入维度顺序。

模型默认输入尺寸是 224x224。

VGG19

1
2
3
4
5
6
7
8
keras.applications.vgg19.VGG19(
include_top=True,
weights='imagenet',
input_tensor=None,
input_shape=None,
pooling=None,
classes=1000
)

重要参数

  • include_top: 是否包括顶层的全连接层。

  • weights: None 代表随机初始化, 'imagenet' 代表加载在 ImageNet 上预训练的权值。

  • input_tensor: 可选,Keras tensor 作为模型的输入(即 layers.Input() 输出的 tensor)。

  • input_shape: 可选,输入尺寸元组,仅当 include_top=False 时有效,否则输入形状必须是 (244, 244, 3)(对于 channels_last 数据格式),或者 (3, 244, 244)(对于 channels_first 数据格式)。它必须拥有 3 个输入通道,且宽高必须不小于 32。例如 (200, 200, 3) 是一个合法的输入尺寸。

  • pooling

    : 可选,当include_top为False时,该参数指定了特征提取时的池化方式。

    • None 代表不池化,直接输出最后一层卷积层的输出,该输出是一个四维张量。
    • 'avg' 代表全局平均池化(GlobalAveragePooling2D),相当于在最后一层卷积层后面再加一层全局平均池化层,输出是一个二维张量。
    • 'max' 代表全局最大池化
  • classes: 可选,图片分类的类别数,仅当 include_top 为 True 并且不加载预训练权值时可用。

VGG19 模型,权值由 ImageNet 训练而来。

该模型可同时构建于 channels_first (通道,高度,宽度) 和 channels_last(高度,宽度,通道)两种输入维度顺序。

模型默认输入尺寸是 224x224。

ResNet50

残差网络来设计的模型

1
2
3
4
5
6
7
8
keras.applications.resnet.ResNet50(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.resnet.ResNet101(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.resnet.ResNet152(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.resnet_v2.ResNet50V2(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.resnet_v2.ResNet101V2(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.resnet_v2.ResNet152V2(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.resnext.ResNeXt50(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.resnext.ResNeXt101(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)

重要参数

  • include_top: 是否包括顶层的全连接层。
  • weights: None 代表随机初始化, 'imagenet' 代表加载在 ImageNet 上预训练的权值。
  • input_tensor: 可选,Keras tensor 作为模型的输入(即 layers.Input() 输出的 tensor)。
  • input_shape: 可选,输入尺寸元组,仅当 include_top=False 时有效,否则输入形状必须是 (244, 244, 3)(对于 channels_last 数据格式),或者 (3, 244, 244)(对于 channels_first 数据格式)。它必须拥有 3 个输入通道,且宽高必须不小于 32。例如 (200, 200, 3) 是一个合法的输入尺寸。
  • pooling: 可选,当include_top为False时,该参数指定了特征提取时的池化方式。
    • None 代表不池化,直接输出最后一层卷积层的输出,该输出是一个四维张量。
    • 'avg' 代表全局平均池化(GlobalAveragePooling2D),相当于在最后一层卷积层后面再加一层全局平均池化层,输出是一个二维张量。
    • 'max' 代表全局最大池化
  • classes: 可选,图片分类的类别数,仅当 include_top 为 True 并且不加载预训练权值时可用。

ResNet, ResNetV2, ResNeXt 模型,权值由 ImageNet 训练而来。

该模型可同时构建于 channels_first (通道,高度,宽度) 和 channels_last(高度,宽度,通道)两种输入维度顺序。

模型默认输入尺寸是 224x224。

InceptionV3

1
2
3
4
5
6
7
8
keras.applications.inception_v3.InceptionV3(
include_top=True,
weights='imagenet',
input_tensor=None,
input_shape=None,
pooling=None,
classes=1000
)

重要参数

  • include_top: 是否包括顶层的全连接层。
  • weights: None 代表随机初始化, 'imagenet' 代表加载在 ImageNet 上预训练的权值。
  • input_tensor: 可选,Keras tensor 作为模型的输入(即 layers.Input() 输出的 tensor)。
  • input_shape: 可选,输入尺寸元组,仅当 include_top=False 时有效,否则输入形状必须是 (299, 299, 3)(对于 channels_last 数据格式),或者 (3, 299, 299)(对于 channels_first 数据格式)。它必须拥有 3 个输入通道,且宽高必须不小于 139。例如 (150, 150, 3) 是一个合法的输入尺寸。
  • pooling: 可选,当include_top为False时,该参数指定了特征提取时的池化方式。
    • None 代表不池化,直接输出最后一层卷积层的输出,该输出是一个四维张量。
    • 'avg' 代表全局平均池化(GlobalAveragePooling2D),相当于在最后一层卷积层后面再加一层全局平均池化层,输出是一个二维张量。
    • 'max' 代表全局最大池化
  • classes: 可选,图片分类的类别数,仅当 include_top 为 True 并且不加载预训练权值时可用。

Inception V3 模型,权值由 ImageNet 训练而来。

该模型可同时构建于 channels_first (通道,高度,宽度) 和 channels_last(高度,宽度,通道)两种输入维度顺序。

模型默认输入尺寸是 299x299。

InceptionResNetV2

1
2
3
4
5
6
7
8
keras.applications.inception_resnet_v2.InceptionResNetV2(
include_top=True,
weights='imagenet',
input_tensor=None,
input_shape=None,
pooling=None,
classes=1000
)

重要参数

  • include_top: 是否包括顶层的全连接层。
  • weights: None 代表随机初始化, 'imagenet' 代表加载在 ImageNet 上预训练的权值。
  • input_tensor: 可选,Keras tensor 作为模型的输入(即 layers.Input() 输出的 tensor)。
  • input_shape: 可选,输入尺寸元组,仅当 include_top=False 时有效,否则输入形状必须是 (299, 299, 3)(对于 channels_last 数据格式),或者 (3, 299, 299)(对于 channels_first 数据格式)。它必须拥有 3 个输入通道,且宽高必须不小于 139。例如 (150, 150, 3) 是一个合法的输入尺寸。
  • pooling: 可选,当include_top为False时,该参数指定了特征提取时的池化方式。
    • None 代表不池化,直接输出最后一层卷积层的输出,该输出是一个四维张量。
    • 'avg' 代表全局平均池化(GlobalAveragePooling2D),相当于在最后一层卷积层后面再加一层全局平均池化层,输出是一个二维张量。
    • 'max' 代表全局最大池化
  • classes: 可选,图片分类的类别数,仅当 include_top 为 True 并且不加载预训练权值时可用。

Inception-ResNet V2 模型,权值由 ImageNet 训练而来。

该模型可同时构建于 channels_first (通道,高度,宽度) 和 channels_last(高度,宽度,通道)两种输入维度顺序。

模型默认输入尺寸是 299x299。

Xception

1
2
3
4
5
6
7
8
tf.keras.applications.xception.Xception(
include_top=True,
weights='imagenet',
input_tensor=None,
input_shape=None,
pooling=None,
classes=1000
)

重要参数

  • include_top: 是否包括顶层的全连接层。

  • weights: None 代表随机初始化, imagenet 代表加载在 ImageNet 上预 训练的权值。

  • input_tensor: 可选,Keras tensor 作为模型的输入(即 layers.Input() 输出的 tensor)。

  • input_shape: 可选,输入尺寸元组,仅当 include_top=False 时有效(否则 输入形状必须是 (299, 299, 3),因为预训练模型是以这个大小训练的)。它 必须拥有 3 个输入通道,且宽高必须不小于 71。例如 (150, 150, 3) 是一个 合法的输入尺寸。

  • pooling: 可选, 当 include_top 为 False 时,该参数指定了特征提取时的池化方式。

    • None 代表不池化,直接输出最后一层卷积层的输出,该输出是一个 4D 张量。
    • avg 代表全局平均池化(GlobalAveragePooling2D),相当于在最后一层 卷积层后面再加一层全局平均池化层,输出是一个 2D 张量。
    • max代表全局最大池化。
  • classes: 可选,图片分类的类别数,仅当 include_top 为 True 并且不加载预训练权值时可用。

在 ImageNet 上预训练的 Xception V1 模型,在 ImageNet 上, 该模型取得了验证集 top1 0.790 和 top5 0.945 的准确率。 注意该模型只支持 channels_last 的维度顺序(高度、宽度、通 道)。 模型默认输入尺寸是 299x299。

MobileNet

1
2
3
4
5
6
7
8
9
10
11
12
keras.applications.mobilenet.MobileNet(
input_shape=None,
alpha=1.0,
depth_multiplier=1,
dropout=1e-3,
include_top=True,
weights='imagenet',
input_tensor=None,
pooling=None,
classes=1000
)

重要参数

  • input_shape: 可选,输入尺寸元组,仅当 include_top=False 时有效,否则输入形状必须是 (224, 224, 3)(channels_last 格式)或 (3, 224, 224)(channels_first 格式)。它必须为 3 个输入通道,且宽高必须不小于 32,比如 (200, 200, 3) 是一个合法的输入尺寸。

  • alpha

    : 控制网络的宽度:

    • 如果 alpha < 1.0,则同比例减少每层的滤波器个数。
    • 如果 alpha > 1.0,则同比例增加每层的滤波器个数。
    • 如果 alpha = 1,使用论文默认的滤波器个数
  • depth_multiplier: depthwise卷积的深度乘子,也称为(分辨率乘子)

  • dropout: dropout 概率

  • include_top: 是否包括顶层的全连接层。

  • weights: None 代表随机初始化, 'imagenet' 代表加载在 ImageNet 上预训练的权值。

  • input_tensor: 可选,Keras tensor 作为模型的输入(比如 layers.Input() 输出的 tensor)。

  • pooling: 可选,当include_top为False 时,该参数指定了特征提取时的池化方式。

    • None 代表不池化,直接输出最后一层卷积层的输出,该输出是一个四维张量。
    • 'avg' 代表全局平均池化(GlobalAveragePooling2D),相当于在最后一层卷积层后面再加一层全局平均池化层,输出是一个二维张量。
    • 'max' 代表全局最大池化
  • classes: 可选,图片分类的类别数,仅当 include_top 为 True 并且不加载预训练权值时可用。

在 ImageNet 上预训练的 MobileNet 模型。

注意,该模型目前只支持 channels_last 的维度顺序(高度、宽度、通道)。

模型默认输入尺寸是 224x224。

MobileNetV2

1
2
3
4
5
6
7
8
9
10
keras.applications.mobilenet_v2.MobileNetV2(
input_shape=None,
alpha=1.0,
depth_multiplier=1,
include_top=True,
weights='imagenet',
input_tensor=None,
pooling=None,
classes=1000
)

重要参数

  • input_shape: optional shape tuple, to be specified if you would like to use a model with an input img resolution that is not (224, 224, 3). It should have exactly 3 inputs channels (224, 224, 3). You can also omit this option if you would like to infer input_shape from an input_tensor. If you choose to include both input_tensor and input_shape then input_shape will be used if they match, if the shapes do not match then we will throw an error. E.g. (160, 160, 3) would be one valid value.

  • alpha

    : 控制网络的宽度。这在 MobileNetV2 论文中被称作宽度乘子。

    • 如果 alpha < 1.0,则同比例减少每层的滤波器个数。
    • 如果 alpha > 1.0,则同比例增加每层的滤波器个数。
    • 如果 alpha = 1,使用论文默认的滤波器个数。
  • depth_multiplier: depthwise 卷积的深度乘子,也称为(分辨率乘子)

  • include_top: 是否包括顶层的全连接层。

  • weights: None 代表随机初始化,'imagenet' 代表加载在 ImageNet 上预训练的权值。

  • input_tensor: 可选,Keras tensor 作为模型的输入(即 layers.Input() 输出的 tensor)。

  • pooling: 可选,当 include_top 为 False时,该参数指定了特征提取时的池化方式。

    • None 代表不池化,直接输出最后一层卷积层的输出,该输出是一个四维张量。

    • 'avg' 代表全局平均池化(GlobalAveragePooling2D),相当于在最后一层卷积层后面再加一层全局平均池化层,输出是一个二维张量。

    • 'max' 代表全局最大池化

  • classes: 可选,图片分类的类别数,仅当 include_top 为 True 并且不加载预训练权值时可用。

在 ImageNet 上预训练的 MobileNetV2 模型。

请注意,该模型仅支持 'channels_last'

数据格式(高度,宽度,通道)。模型默认输出尺寸为 224x224。

DenseNet

1
2
3
keras.applications.densenet.DenseNet121(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.densenet.DenseNet169(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.densenet.DenseNet201(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)

重要参数

  • blocks: 四个 Dense Layers 的 block 数量。
  • include_top: 是否包括顶层的全连接层。
  • weights: None 代表随机初始化, 'imagenet' 代表加载在 ImageNet 上预训练的权值。
  • input_tensor: 可选,Keras tensor 作为模型的输入(比如 layers.Input() 输出的 tensor)。
  • input_shape: 可选,输入尺寸元组,仅当 include_top=False 时有效(不然输入形状必须是 (224, 224, 3) (channels_last 格式)或 (3, 224, 224) (channels_first 格式),因为预训练模型是以这个大小训练的)。它必须为 3 个输入通道,且宽高必须不小于 32,比如 (200, 200, 3) 是一个合法的输入尺寸。
  • pooling: 可选,当include_top为 False时,该参数指定了特征提取时的池化方式。
    • None 代表不池化,直接输出最后一层卷积层的输出,该输出是一个四维张量。
    • 'avg' 代表全局平均池化(GlobalAveragePooling2D),相当于在最后一层卷积层后面再加一层全局平均池化层,输出是一个二维张量。
    • 'max' 代表全局最大池化.
  • classes: 可选,图片分类的类别数,仅当 include_top 为 True 并且不加载预训练权值时可用。

在 ImageNet 上预训练的 DenseNet 模型。

该模型可同时构建于 channels_first (通道,高度,宽度) 和 channels_last(高度,宽度,通道)两种输入维度顺序。

模型默认输入尺寸是 224x224。

NASNet

1
2
keras.applications.nasnet.NASNetLarge(input_shape=None, include_top=True, weights='imagenet', input_tensor=None, pooling=None, classes=1000)
keras.applications.nasnet.NASNetMobile(input_shape=None, include_top=True, weights='imagenet', input_tensor=None, pooling=None, classes=1000)

重要参数

  • input_shape: 可选,输入尺寸元组,仅当 include_top=False 时有效,否则对于 NASNetMobile 模型来说,输入形状必须是 (224, 224, 3)(channels_last 格式)或 (3, 224, 224)(channels_first 格式),对于 NASNetLarge 来说,输入形状必须是 (331, 331, 3) (channels_last 格式)或 (3, 331, 331)(channels_first 格式)。它必须为 3 个输入通道,且宽高必须不小于 32,比如 (200, 200, 3) 是一个合法的输入尺寸。
  • include_top: 是否包括顶层的全连接层。
  • weights: None 代表随机初始化, 'imagenet' 代表加载在 ImageNet 上预训练的权值。
  • input_tensor: 可选,Keras tensor 作为模型的输入(比如 layers.Input() 输出的 tensor)。
  • pooling: 可选,当include_top为False时,该参数指定了特征提取时的池化方式。
    • None 代表不池化,直接输出最后一层卷积层的输出,该输出是一个四维张量。
    • 'avg' 代表全局平均池化(GlobalAveragePooling2D),相当于在最后一层卷积层后面再加一层全局平均池化层,输出是一个二维张量。
    • 'max' 代表全局最大池化
  • classes: 可选,图片分类的类别数,仅当 include_top 为 True 并且不加载预训练权值时可用。

在 ImageNet 上预训练的神经结构搜索网络模型(NASNet)。

NASNetLarge 模型默认的输入尺寸是 331x331,NASNetMobile 模型默认的输入尺寸是 224x224。