转至:Keras中文文档 https://keras.io/zh/applications/

应用 Applications

Keras 的应用模块(keras.applications)提供了带有预训练权值的深度学习模型,这些模型可以用来进行预测、特征提取和微调(fine-tuning)。

当你初始化一个预训练模型时,会自动下载权重到 ~/.keras/models/ 目录下。

可用的模型

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

  • Xception
  • VGG16
  • VGG19
  • ResNet50
  • InceptionV3
  • InceptionResNetV2
  • MobileNet
  • DenseNet
  • NASNet
  • MobileNetV2

所有的这些架构都兼容所有的后端 (TensorFlow, Theano 和 CNTK),并且会在实例化时,根据 Keras 配置文件〜/.keras/keras.json 中设置的图像数据格式构建模型。举个例子,如果你设置 image_data_format=channels_last,则加载的模型将按照 TensorFlow 的维度顺序来构造,即「高度-宽度-深度」(Height-Width-Depth)的顺序。

注意:

  • 对于 Keras < 2.2.0,Xception 模型仅适用于 TensorFlow,因为它依赖于 SeparableConvolution层。
  • 对于 Keras < 2.1.5,MobileNet 模型仅适用于 TensorFlow,因为它依赖于 DepthwiseConvolution层。

图像分类模型的使用示例

使用 ResNet50 进行 ImageNet 分类

from keras.applications.resnet50 import ResNet50
from keras.preprocessing import image
from keras.applications.resnet50 import preprocess_input, decode_predictions
import numpy as npmodel = ResNet50(weights='imagenet')img_path = 'elephant.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)preds = model.predict(x)
# 将结果解码为元组列表 (class, description, probability)
# (一个列表代表批次中的一个样本)
print('Predicted:', decode_predictions(preds, top=3)[0])
# Predicted: [(u'n02504013', u'Indian_elephant', 0.82658225), (u'n01871265', u'tusker', 0.1122357), (u'n02504458', u'African_elephant', 0.061040461)]

使用 VGG16 提取特征

from keras.applications.vgg16 import VGG16
from keras.preprocessing import image
from keras.applications.vgg16 import preprocess_input
import numpy as npmodel = VGG16(weights='imagenet', include_top=False)#include_top=False 去掉最后3层的全连接层img_path = 'elephant.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)features = model.predict(x)

从VGG19 的任意中间层中抽取特征

from keras.applications.vgg19 import VGG19
from keras.preprocessing import image
from keras.applications.vgg19 import preprocess_input
from keras.models import Model
import numpy as npbase_model = VGG19(weights='imagenet')
model = Model(inputs=base_model.input, outputs=base_model.get_layer('block4_pool').output)img_path = 'elephant.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)block4_pool_features = model.predict(x)

在新类上微调 InceptionV3

from keras.applications.inception_v3 import InceptionV3
from keras.preprocessing import image
from keras.models import Model
from keras.layers import Dense, GlobalAveragePooling2D
from keras import backend as K# 构建不带分类器的预训练模型
base_model = InceptionV3(weights='imagenet', include_top=False)# 添加全局平均池化层
x = base_model.output
x = GlobalAveragePooling2D()(x)# 添加一个全连接层
x = Dense(1024, activation='relu')(x)# 添加一个分类器,假设我们有200个类
predictions = Dense(200, activation='softmax')(x)# 构建我们需要训练的完整模型
model = Model(inputs=base_model.input, outputs=predictions)# 首先,我们只训练顶部的几层(随机初始化的层)
# 锁住所有 InceptionV3 的卷积层
for layer in base_model.layers:layer.trainable = False# 编译模型(一定要在锁层以后操作)
model.compile(optimizer='rmsprop', loss='categorical_crossentropy')# 在新的数据集上训练几代
model.fit_generator(...)# 现在顶层应该训练好了,让我们开始微调 Inception V3 的卷积层。
# 我们会锁住底下的几层,然后训练其余的顶层。# 让我们看看每一层的名字和层号,看看我们应该锁多少层呢:
for i, layer in enumerate(base_model.layers):print(i, layer.name)# 我们选择训练最上面的两个 Inception block
# 也就是说锁住前面249层,然后放开之后的层。
for layer in model.layers[:249]:layer.trainable = False
for layer in model.layers[249:]:layer.trainable = True# 我们需要重新编译模型,才能使上面的修改生效
# 让我们设置一个很低的学习率,使用 SGD 来微调
from keras.optimizers import SGD
model.compile(optimizer=SGD(lr=0.0001, momentum=0.9), loss='categorical_crossentropy')# 我们继续训练模型,这次我们训练最后两个 Inception block
# 和两个全连接层
model.fit_generator(...)

通过自定义输入张量构建 InceptionV3

from keras.applications.inception_v3 import InceptionV3
from keras.layers import Input# 这也可能是不同的 Keras 模型或层的输出
input_tensor = Input(shape=(224, 224, 3))  # 假定 K.image_data_format() == 'channels_last'model = InceptionV3(input_tensor=input_tensor, weights='imagenet', include_top=True)

模型概览

模型 大小 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 99 MB 0.749 0.921 25,636,712 168
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 -

Top-1 准确率和 Top-5 准确率都是在 ImageNet 验证集上的结果。

Xception

keras.applications.xception.Xception(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)

在 ImageNet 上预训练的 Xception V1 模型。

在 ImageNet 上,该模型取得了验证集 top1 0.790 和 top5 0.945 的准确率。

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

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

参数

  • include_top: 是否包括顶层的全连接层。
  • weightsNone 代表随机初始化, '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 并且不加载预训练权值时可用。

返回值

一个 Keras Model 对象.

参考文献

  • Xception: Deep Learning with Depthwise Separable Convolutions

License

预训练权值由我们自己训练而来,基于 MIT license 发布。

VGG16

keras.applications.vgg16.VGG16(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)

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

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

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

参数

  • include_top: 是否包括顶层的全连接层。
  • weightsNone 代表随机初始化, '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 并且不加载预训练权值时可用。

返回值

一个 Keras Model 对象。

参考文献

  • Very Deep Convolutional Networks for Large-Scale Image Recognition:如果在研究中使用了VGG,请引用该论文。

License

预训练权值由 VGG at Oxford 发布的预训练权值移植而来,基于 Creative Commons Attribution License。

VGG19

keras.applications.vgg19.VGG19(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)

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

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

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

参数

  • include_top: 是否包括顶层的全连接层。
  • weightsNone 代表随机初始化, '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 并且不加载预训练权值时可用。

返回值

一个 Keras Model 对象。

参考文献

  • Very Deep Convolutional Networks for Large-Scale Image Recognition:如果在研究中使用了VGG,请引用该论文。

License

预训练权值由 VGG at Oxford 发布的预训练权值移植而来,基于 Creative Commons Attribution License。

ResNet50

keras.applications.resnet50.ResNet50(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)

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

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

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

参数

  • include_top: 是否包括顶层的全连接层。
  • weightsNone 代表随机初始化, '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 并且不加载预训练权值时可用。

返回值

一个 Keras Model 对象。

参考文献

  • Deep Residual Learning for Image Recognition

License

预训练权值由 Kaiming He 发布的预训练权值移植而来,基于 MIT license。

InceptionV3

keras.applications.inception_v3.InceptionV3(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)

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

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

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

参数

  • include_top: 是否包括顶层的全连接层。
  • weightsNone 代表随机初始化, '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 并且不加载预训练权值时可用。

返回值

一个 Keras Model 对象。

参考文献

  • Rethinking the Inception Architecture for Computer Vision

License

预训练权值基于 Apache License。

InceptionResNetV2

keras.applications.inception_resnet_v2.InceptionResNetV2(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)

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

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

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

参数

  • include_top: 是否包括顶层的全连接层。
  • weightsNone 代表随机初始化, '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 并且不加载预训练权值时可用。

返回值

一个 Keras Model 对象。

参考文献

  • Inception-v4, Inception-ResNet and the Impact of Residual Connections on Learning

License

预训练权值基于 Apache License。

MobileNet

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)

在 ImageNet 上预训练的 MobileNet 模型。

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

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

参数

  • 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: 是否包括顶层的全连接层。
  • weightsNone 代表随机初始化, 'imagenet' 代表加载在 ImageNet 上预训练的权值。
  • input_tensor: 可选,Keras tensor 作为模型的输入(比如 layers.Input() 输出的 tensor)。
  • pooling: 可选,当 include_top 为 False 时,该参数指定了特征提取时的池化方式。
    • None 代表不池化,直接输出最后一层卷积层的输出,该输出是一个四维张量。
    • 'avg' 代表全局平均池化(GlobalAveragePooling2D),相当于在最后一层卷积层后面再加一层全局平均池化层,输出是一个二维张量。
    • 'max' 代表全局最大池化
  • classes: 可选,图片分类的类别数,仅当 include_top 为 True 并且不加载预训练权值时可用。

返回

一个 Keras Model 对象。

参考文献

  • MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications

License

预训练权值基于 Apache License。

DenseNet

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)

在 ImageNet 上预训练的 DenseNet 模型。

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

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

参数

  • blocks: 四个 Dense Layers 的 block 数量。
  • include_top: 是否包括顶层的全连接层。
  • weightsNone 代表随机初始化, '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 并且不加载预训练权值时可用。

返回

一个 Keras Model 对象。

参考文献

  • Densely Connected Convolutional Networks (CVPR 2017 Best Paper Award)

Licence

预训练权值基于 BSD 3-clause License。

NASNet

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)

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

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

参数

  • 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: 是否包括顶层的全连接层。
  • weightsNone 代表随机初始化, 'imagenet' 代表加载在 ImageNet 上预训练的权值。
  • input_tensor: 可选,Keras tensor 作为模型的输入(比如 layers.Input() 输出的 tensor)。
  • pooling: 可选,当 include_top 为 False 时,该参数指定了特征提取时的池化方式。
    • None 代表不池化,直接输出最后一层卷积层的输出,该输出是一个四维张量。
    • 'avg' 代表全局平均池化(GlobalAveragePooling2D),相当于在最后一层卷积层后面再加一层全局平均池化层,输出是一个二维张量。
    • 'max' 代表全局最大池化
  • classes: 可选,图片分类的类别数,仅当 include_top 为 True 并且不加载预训练权值时可用。

返回

一个 Keras Model 实例。

参考文献

  • Learning Transferable Architectures for Scalable Image Recognition

License

预训练权值基于 Apache License。

MobileNetV2

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)

在 ImageNet 上预训练的 MobileNetV2 模型。

请注意,该模型仅支持 'channels_last' 数据格式(高度,宽度,通道)。

模型默认输出尺寸为 224x224。

参数

  • 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: 是否包括顶层的全连接层。
  • weightsNone 代表随机初始化,'imagenet' 代表加载在 ImageNet 上预训练的权值。
  • input_tensor: 可选,Keras tensor 作为模型的输入(即 layers.Input() 输出的 tensor)。
  • pooling: 可选,当 include_top 为 False 时,该参数指定了特征提取时的池化方式。
    • None 代表不池化,直接输出最后一层卷积层的输出,该输出是一个四维张量。
    • 'avg' 代表全局平均池化(GlobalAveragePooling2D),相当于在最后一层卷积层后面再加一层全局平均池化层,输出是一个二维张量。
    • 'max' 代表全局最大池化
  • classes: 可选,图片分类的类别数,仅当 include_top 为 True 并且不加载预训练权值时可用。

返回

一个 Keras model 实例。

异常

ValueError: 如果 weights 参数非法,或非法的输入尺寸,或者当 weights='imagenet' 时,非法的 depth_multiplier, alpha, rows。

参考文献

  • MobileNetV2: Inverted Residuals and Linear Bottlenecks

License

预训练权值基于 Apache License.

Keras 的预训练权值模型用来进行预测、特征提取和微调(fine-tuning)相关推荐

  1. 基于Keras预训练词向量模型的文本分类方法

    本文语料仍然是上篇所用的搜狗新闻语料,采用中文预训练词向量模型对词进行向量表示.上篇文章将文本分词之后,采用了TF-IDF的特征提取方式对文本进行向量化表示,所产生的文本表示矩阵是一个稀疏矩阵,本篇采 ...

  2. 使用预训练的 ImageNet 模型进行图像分类

    在这篇文章中,我们将学习如何使用预训练的 ImageNet 模型来执行图像分类.我们已经看到了如何训练一个简单的神经网络来对 CIFAR-10 数据集中的图像进行分类,但这是一个相对简单的任务,因为只 ...

  3. Tensorflow基于pb模型进行预训练(pb模型转CKPT模型)

    Tensorflow基于pb模型进行预训练(pb模型转CKPT模型) 在网上看到很多教程都是tensorflow基于pb模型进行推理,而不是进行预训练.最近在在做项目的过程中发现之前的大哥只有一个pb ...

  4. 【深度学习】预训练的卷积模型比Transformer更好?

    引言 这篇文章就是当下很火的用预训练CNN刷爆Transformer的文章,LeCun对这篇文章做出了很有深意的评论:"Hmmm".本文在预训练微调范式下对基于卷积的Seq2Seq ...

  5. TensorFlow 调用预训练好的模型—— Python 实现

    1. 准备预训练好的模型 TensorFlow 预训练好的模型被保存为以下四个文件 data 文件是训练好的参数值,meta 文件是定义的神经网络图,checkpoint 文件是所有模型的保存路径,如 ...

  6. 在 C/C++ 中使用 TensorFlow 预训练好的模型—— 直接调用 C++ 接口实现

    现在的深度学习框架一般都是基于 Python 来实现,构建.训练.保存和调用模型都可以很容易地在 Python 下完成.但有时候,我们在实际应用这些模型的时候可能需要在其他编程语言下进行,本文将通过直 ...

  7. 【Pytorch】加载torchvision中预训练好的模型并修改默认下载路径(使用models.__dict__[model_name]()读取)

    说明 使用torchvision.model加载预训练好的模型时,发现默认下载路径在系统盘下面的用户目录下(这个你执行的时候就会发现),即C:\用户名\.cache\torch\.checkpoint ...

  8. MICCAI 2020 | 基于3D监督预训练的全身病灶检测SOTA(预训练代码和模型已公开)...

    关注公众号,发现CV技术之美 ▊ 研究背景介绍 由于深度学习任务往往依赖于大量的标注数据,医疗图像的样本标注又会涉及到较多的专业知识,标注人员需要对病灶的大小.形状.边缘等信息进行准确的判断,甚至需要 ...

  9. PromptCLUE:大规模多任务Prompt预训练中文开源模型

    简介 PromptCLUE:大规模多任务Prompt预训练中文开源模型. 中文上的三大统一:统一模型框架,统一任务形式,统一应用方式.支持几十个不同类型的任务,具有较好的零样本学习能力和少样本学习能力 ...

最新文章

  1. Silverlight学习笔记之使用TranslateTransform控制对象位置
  2. 打jar时包含所有依赖(maven-assembly-plugin)
  3. linux系统一下剪贴板在哪里,Linux的最佳剪贴板管理器
  4. 通过MyBatis查找一张表的数据,某些字段的值为空
  5. Python中爬虫框架或模块的区别!
  6. 1.通俗解释分布式系统
  7. 大话 JavaScript 动画
  8. 中国电信:5G 手机可实现不换卡号;新西兰否认禁用华为;Visual Studio 2019 正式发布!| 极客头条...
  9. 311. Sparse Matrix Multiplication
  10. mark制图软件_绘图软件有哪些?
  11. java导出ppt_POI之PPT导出最简单实例
  12. 力士乐电源模块故障代码_REXROTH DRIVE博士力士乐伺服驱动器故障代码大全
  13. python怎么循环播放_如何用pyaudio循环播放音频?
  14. MySQL Shell 安装与基本使用
  15. Proximal Algorithms 1 介绍
  16. 扫地机器人拖实木地板_扫地机器人会不会损坏高档木地板
  17. rpm、yum、编译安装轻松解决centos7程序包安装
  18. uni-app服务器端搭建
  19. 修复迅雷看看xmp.rmvb视频文件错误关联
  20. <table> | HTML表格标签的定义与用法

热门文章

  1. fopen文件路径怎么写_PHP文件上传
  2. STM32那点事(2)_时钟树(中)
  3. pythont提示AttributeError: module ‘scipy.misc‘ has no attribute ‘imsave‘或‘imread‘
  4. pycharm引入其他目录的包报错,import报错
  5. Eclipce Luna 离线安装ADT23
  6. lnmp修改mysql上传大小限制_安装Linux+Nginx+MySQL+PHP(LNMP)集成环境,解除上传文件大小限制...
  7. layui弹出层:使用icon图标小结
  8. css背景图background - 多背景定义
  9. mysql 性能拐点_性能压测及分析调优实践
  10. python软件菜单如何设计_佩服!我用Python设计了一个签名软件