前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >keras系列︱深度学习五款常用的已训练模型

keras系列︱深度学习五款常用的已训练模型

作者头像
用户7886150
修改于 2021-01-15 09:04:10
修改于 2021-01-15 09:04:10
1.5K0
举报
文章被收录于专栏:bit哲学院bit哲学院

参考链接: Keras中的深度学习模型-探索性数据分析(EDA)

向AI转型的程序员都关注了这个号???

 大数据挖掘DT数据分析  公众号: datadw

  不得不说,这深度学习框架更新太快了尤其到了Keras2.0版本,快到Keras中文版好多都是错的,快到官方文档也有旧的没更新,前路坑太多。 到发文为止,已经有theano/tensorflow/CNTK支持keras,虽然说tensorflow造势很多,但是笔者认为接下来Keras才是正道。 

  笔者先学的caffe,从使用来看,keras比caffe简单超级多,非常好用,特别是重新训练一个模型,但是呢,在fine-tuning的时候,遇到了很多问题,对新手比较棘手。

 中文文档:http://keras-cn.readthedocs.io/en/latest/ 官方文档:https://keras.io/ 文档主要是以keras2.0

 一、Application的五款已训练模型 + H5py简述

 Kera的应用模块Application提供了带有预训练权重的Keras模型,这些模型可以用来进行预测、特征提取和finetune。 后续还有对以下几个模型的参数介绍:

 XceptionVGG16VGG19ResNet50InceptionV3

 所有的这些模型(除了Xception)都兼容Theano和Tensorflow,并会自动基于~/.keras/keras.json的Keras的图像维度进行自动设置。例如,如果你设置data_format=”channel_last”,则加载的模型将按照TensorFlow的维度顺序来构造,即“Width-Height-Depth”的顺序。

 模型的官方下载路径:https://github.com/fchollet/deep-learning-models/releases

 其中: .

 1、th与tf的区别

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

 Keras提供了两套后端,Theano和Tensorflow, th和tf的大部分功能都被backend统一包装起来了,但二者还是存在不小的冲突,有时候你需要特别注意Keras是运行在哪种后端之上,它们的主要冲突有:

 dim_ordering,也就是维度顺序。比方说一张224*224的彩色图片,theano的维度顺序是(3,224,224),即通道维在前。而tf的维度顺序是(224,224,3),即通道维在后。 

 卷积层权重的shape:从无到有训练一个网络,不会有任何问题。但是如果你想把一个th训练出来的卷积层权重载入风格为tf的卷积层……说多了都是泪。我一直觉得这个是个bug,数据的dim_ordering有问题就罢了,为啥卷积层权重的shape还需要变换咧?我迟早要提个PR把这个bug修掉! 

 然后是卷积层kernel的翻转不翻转问题,这个我们说过很多次了,就不再多提。 数据格式的区别,channels_last”对应原本的“tf”,“channels_first”对应原本的“th”。 

 以128x128的RGB图像为例,“channels_first”应将数据组织为(3,128,128),而“channels_last”应将数据组织为(128,128,3)。 

 譬如: vgg16_weights_th_dim_ordering_th_kernels_notop.h5 vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5 .

 2、notop模型是指什么?

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

 是否包含最后的3个全连接层(whether to include the 3 fully-connected layers at the top of the network)。用来做fine-tuning专用,专门开源了这类模型。 .

 3、H5py简述

 ========

 keras的已训练模型是H5PY格式的,不是caffe的.caffemodel h5py.File类似Python的词典对象,因此我们可以查看所有的键值: 读入

 file=h5py.File('.../notop.h5','r')

 f.attrs['nb_layers'],代表f的属性,其中有一个属性为'nb_layers'

 >>> f.keys()

[u'block1_conv1', u'block1_conv2', u'block1_pool', u'block2_conv1', u'block2_conv2', u'block2_pool', u'block3_conv1', u'block3_conv2', u'block3_conv3', u'block3_pool', u'block4_conv1', u'block4_conv2', u'block4_conv3', u'block4_pool', u'block5_conv1', u'block5_conv2', u'block5_conv3', u'block5_pool']

 可以看到f中各个层内有些什么。

 for name in f:

    print(name)    # 类似f.keys()

 .

 4、官方案例——利用ResNet50网络进行ImageNet分类

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

 rom keras.applications.resnet50 import ResNet50

from keras.preprocessing import image

from keras.applications.resnet50 import preprocess_input, decode_predictionsimport numpy as np

model = 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)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)]

 还有的案例可见Keras官方文档

 http://keras-cn.readthedocs.io/en/latest/other/application/

  利用VGG16提取特征、从VGG19的任意中间层中抽取特征、在定制的输入tensor上构建InceptionV3

 .

 5、调用参数解释

 ========

 以下几类,因为调用好像都是从网站下载权重,所以可以自己修改一下源码,让其可以读取本地H5文件。

 Xception模型

 ImageNet上,该模型取得了验证集top1 0.790和top5 0.945的正确率; ,该模型目前仅能以TensorFlow为后端使用,由于它依赖于”SeparableConvolution”层,目前该模型只支持channels_last的维度顺序(width, height, channels)

 默认输入图片大小为299x299

 keras.applications.xception.Xception(include_top=True, weights='imagenet',

                                    input_tensor=None, input_shape=None,

                                    pooling=None, classes=1000)

 VGG16模型

 VGG16模型,权重由ImageNet训练而来

 该模型再Theano和TensorFlow后端均可使用,并接受channels_first和channels_last两种输入维度顺序

 模型的默认输入尺寸时224x224

 keras.applications.vgg16.VGG16(include_top=True, weights='imagenet',

                                input_tensor=None, input_shape=None,

                                pooling=None,

                                classes=1000)

 VGG19模型

 VGG19模型,权重由ImageNet训练而来

 该模型在Theano和TensorFlow后端均可使用,并接受channels_first和channels_last两种输入维度顺序

 模型的默认输入尺寸时224x224

 keras.applications.vgg19.VGG19(include_top=True, weights='imagenet',

                                input_tensor=None, input_shape=None,

                                pooling=None,

                                classes=1000)

 ResNet50模型

 50层残差网络模型,权重训练自ImageNet

 该模型在Theano和TensorFlow后端均可使用,并接受channels_first和channels_last两种输入维度顺序

 模型的默认输入尺寸时224x224

 keras.applications.resnet50.ResNet50(include_top=True, weights='imagenet',

                                input_tensor=None, input_shape=None,

                                pooling=None,

                                classes=1000)

 InceptionV3模型

 InceptionV3网络,权重训练自ImageNet

 该模型在Theano和TensorFlow后端均可使用,并接受channels_first和channels_last两种输入维度顺序

 模型的默认输入尺寸时299x299

 keras.applications.inception_v3.InceptionV3(include_top=True,

 weights='imagenet',

 input_tensor=None,

 input_shape=None,

 pooling=None,

classes=1000)

 二、 keras-applications-VGG16解读——函数式

 .py文件来源于:

 https://github.com/fchollet/deep-learning-models/blob/master/vgg16.py 

 VGG16默认的输入数据格式应该是:channels_last

 # -*- coding: utf-8 -*-'''VGG16 model for Keras.

# Reference:

- [Very Deep Convolutional Networks for Large-Scale Image Recognition](https://arxiv.org/abs/1409.1556)

'''from __future__ import print_functionimport numpy as npimport warningsfrom keras.models import Modelfrom keras.layers import Flattenfrom keras.layers import Densefrom keras.layers import Inputfrom keras.layers import Conv2Dfrom keras.layers import MaxPooling2Dfrom keras.layers import GlobalMaxPooling2Dfrom keras.layers import GlobalAveragePooling2Dfrom keras.preprocessing import imagefrom keras.utils import layer_utilsfrom keras.utils.data_utils import get_filefrom keras import backend as Kfrom keras.applications.imagenet_utils import decode_predictions# decode_predictions 输出5个最高概率:(类名, 语义概念, 预测概率) decode_predictions(y_pred) from keras.applications.imagenet_utils import preprocess_input#  预处理 图像编码服从规定,譬如,RGB,GBR这一类的,preprocess_input(x)  from keras.applications.imagenet_utils import _obtain_input_shape# 确定适当的输入形状,相当于opencv中的read.img,将图像变为数组from keras.engine.topology import get_source_inputs

WEIGHTS_PATH = 'https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg16_weights_tf_dim_ordering_tf_kernels.h5'WEIGHTS_PATH_NO_TOP = 'https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5'def VGG16(include_top=True, weights='imagenet',

          input_tensor=None, input_shape=None,

          pooling=None,

          classes=1000):

    # 检查weight与分类设置是否正确

    if weights not in {'imagenet', None}:        raise ValueError('The `weights` argument should be either '

                         '`None` (random initialization) or `imagenet` '

                         '(pre-training on ImageNet).')     if weights == 'imagenet' and include_top and classes !=   1000:        raise ValueError('If using `weights` as imagenet with `include_top`'

                         ' as true, `classes` should be 1000')      # 设置图像尺寸,类似caffe中的transform

    # Determine proper input shape

    input_shape = _obtain_input_shape(input_shape,

                                      default_size=224,

                                      min_size=48,                                          # 模型所能接受的最小长宽

      data_format=K.image_data_format(),       include_top=include_top)                                      #是否通过一个Flatten层再连接到分类器

    # 数据简单处理,resize

    if input_tensor is None:

        img_input = Input(shape=input_shape)         # 这里的Input是keras的格式,可以用于转换

    else:        if not K.is_keras_tensor(input_tensor):

            img_input = Input(tensor=input_tensor,  shape=input_shape)        else:

            img_input = input_tensor          # 如果是tensor的数据格式,需要两步走:

        # 先判断是否是keras指定的数据类型,is_keras_tensor

        # 然后get_source_inputs(input_tensor)

    # 编写网络结构,prototxt

    # Block 1

    x = Conv2D(64, (3, 3), activation='relu', padding='same', name='block1_conv1')(img_input)

    x = Conv2D(64, (3, 3), activation='relu', padding='same', name='block1_conv2')(x)

    x = MaxPooling2D((2, 2), strides=(2, 2), name='block1_pool')(x)    # Block 2

    x = Conv2D(128, (3, 3), activation='relu', padding='same', name='block2_conv1')(x)

    x = Conv2D(128, (3, 3), activation='relu', padding='same', name='block2_conv2')(x)

    x = MaxPooling2D((2, 2), strides=(2, 2), name='block2_pool')(x)    # Block 3

    x = Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv1')(x)

    x = Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv2')(x)

    x = Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv3')(x)

    x = MaxPooling2D((2, 2), strides=(2, 2), name='block3_pool')(x)    # Block 4

    x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv1')(x)

    x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv2')(x)

    x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv3')(x)

    x = MaxPooling2D((2, 2), strides=(2, 2), name='block4_pool')(x)    # Block 5

    x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv1')(x)

    x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv2')(x)

    x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv3')(x)

    x = MaxPooling2D((2, 2), strides=(2, 2), name='block5_pool')(x)    if include_top:        # Classification block

        x = Flatten(name='flatten')(x)

        x = Dense(4096, activation='relu', name='fc1')(x)

        x = Dense(4096, activation='relu', name='fc2')(x)

        x = Dense(classes, activation='softmax', name='predictions')(x)    else:        if pooling == 'avg':

            x = GlobalAveragePooling2D()(x)        elif pooling == 'max':

            x = GlobalMaxPooling2D()(x)    # 调整数据      

    # Ensure that the model takes into account

    # any potential predecessors of `input_tensor`.

    if input_tensor is not None:

        inputs = get_source_inputs(input_tensor)        # get_source_inputs 返回计算需要的数据列表,List of input tensors.

        # 如果是tensor的数据格式,需要两步走:

        # 先判断是否是keras指定的数据类型,is_keras_tensor

        # 然后get_source_inputs(input_tensor)

    else:

        inputs = img_input    # 创建模型

    # Create model.

    model = Model(inputs, x, name='vgg16')    # 加载权重

    # load weights

    if weights == 'imagenet':        if include_top:

            weights_path = get_file('vgg16_weights_tf_dim_ordering_tf_kernels.h5',

                                    WEIGHTS_PATH,

                                    cache_subdir='models')        else:

            weights_path = get_file('vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5',

                                    WEIGHTS_PATH_NO_TOP,

                                    cache_subdir='models')

        model.load_weights(weights_path)        if K.backend() == 'theano':

            layer_utils.convert_all_kernels_in_model(model)        if K.image_data_format() == 'channels_first':            if include_top:

                maxpool = model.get_layer(name='block5_pool')

                shape = maxpool.output_shape[1:]

                dense = model.get_layer(name='fc1')

                layer_utils.convert_dense_weights_data_format(dense, shape, 'channels_first')            if K.backend() == 'tensorflow':

                warnings.warn('You are using the TensorFlow backend, yet you '

                              'are using the Theano '

                              'image data format convention '

                              '(`image_data_format="channels_first"`). '

                              'For best performance, set '

                              '`image_data_format="channels_last"` in '

                              'your Keras config '

                              'at ~/.keras/keras.json.')    return modelif __name__ == '__main__':

    model = VGG16(include_top=True, 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)

    print('Input image shape:', x.shape)

    preds = model.predict(x)

    print('Predicted:', decode_predictions(preds))         # decode_predictions 输出5个最高概率:(类名, 语义概念, 预测概率)

 其中: .

 1、如何已经把模型下载到本地

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

 模型已经下载,不再每次从网站进行加载,可以修改以下内容。

 WEIGHTS_PATH = 'https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg16_weights_tf_dim_ordering_tf_kernels.h5'WEIGHTS_PATH_NO_TOP = 'https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5'

  weights_path = get_file('vgg16_weights_tf_dim_ordering_tf_kernels.h5',

                          WEIGHTS_PATH,

                          cache_subdir='models')

            weights_path = get_file('vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5',

                                    WEIGHTS_PATH_NO_TOP,

                                    cache_subdir='models')

 .

 2、几个layer中的新用法

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

 from keras.applications.imagenet_utils import decode_predictions

decode_predictions #输出5个最高概率:(类名, 语义概念, 预测概率) #decode_predictions(y_pred)

from keras.applications.imagenet_utils import preprocess_input

预处理 图像编码服从规定,譬如,RGB,GBR这一类的,preprocess_input(x)  

from keras.applications.imagenet_utils import _obtain_input_shape 

#确定适当的输入形状,相当于opencv中的read.img,将图像变为数组

 (1)decode_predictions用在最后输出结果上,比较好用【print(‘Predicted:’, decode_predictions(preds))】; (2)preprocess_input,改变编码,【preprocess_input(x)】; (3)_obtain_input_shape 相当于caffe中的transform,在预测的时候,需要对预测的图片进行一定的预处理。

  input_shape = _obtain_input_shape(input_shape,

                                       default_size=224,

                                        min_size=48,                                         # 模型所能接受的最小长宽

                                         data_format=K.image_data_format(),                                      # 数据的使用格式

                                          include_top=include_top)

 .

 3、当include_top=True时

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

 fc_model = VGG16(include_top=True)notop_model = VGG16(include_top=False)

 之前提到过用VGG16做fine-tuning的时候,得到的notop_model就是没有全连接层的模型。然后再去添加自己的层。 

 当时健全的网络结构的时候,fc_model需要添加以下的内容以补全网络结构:

 x = Flatten(name='flatten')(x)

x = Dense(4096, activation='relu', name='fc1')(x)

x = Dense(4096, activation='relu', name='fc2')(x)

x = Dense(classes, activation='softmax', name='predictions')(x)

 pool层之后接一个flatten层,修改数据格式,然后接两个dense层,最后有softmax的Dense层。 .

 4、如果输入的数据格式是channels_first?

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

 如果input的格式是’channels_first’,fc_model还需要修改一下格式,因为VGG16源码是以’channels_last’定义的,所以需要转换一下输出格式。

  maxpool = model.get_layer(name='block5_pool')  # model.get_layer()依据层名或下标获得层对象

 shape = maxpool.output_shape[1:]  # 获取block5_pool层输出的数据格式

 dense = model.get_layer(name='fc1')

 layer_utils.convert_dense_weights_data_format(dense, shape, 'channels_first')

 其中layer_utils.convert_dense_weights_data_format的作用很特殊,官方文档中没有说明,本质用来修改数据格式,因为层中有Flatter层把数据格式换了,所以需要再修改一下。 原文:

  When porting the weights of a convnet from one data format to the other,if the convnet includes a Flatten layer (applied to the last convolutional feature map) followed by a Dense layer, the weights of that Dense layer should be updated to reflect the new dimension ordering.

 三、keras-Sequential-VGG16源码解读:序列式

 本节节选自Keras中文文档《CNN眼中的世界:利用Keras解释CNN的滤波器》

 http://keras-cn.readthedocs.io/en/latest/blog/cnn_see_world/

 已训练好VGG16和VGG19模型的权重: 国外:https://gist.github.com/baraldilorenzo/07d7802847aaad0a35d3 国内:http://files.heuritech.com/weights/vgg16_weights.h5

 前面是VGG16架构的函数式模型的结构,那么在官方文档这个案例中,也有VGG16架构的序列式,都拿来比对一下比较好。 .

 1、VGG16的Sequential-网络结构

 首先,我们在Keras中定义VGG网络的结构:

 from keras.models import Sequentialfrom keras.layers import Convolution2D, ZeroPadding2D, MaxPooling2D

img_width, img_height = 128, 128# build the VGG16 networkmodel = Sequential()

model.add(ZeroPadding2D((1, 1), batch_input_shape=(1, 3,  img_width, img_height)))

first_layer = model.layers[-1] # this is a placeholder tensor that will contain our generated imagesinput_img = first_layer.input# build the rest of the networkmodel.add(Convolution2D(64, 3, 3, activation='relu', name='conv1_1'))

model.add(ZeroPadding2D((1, 1)))

model.add(Convolution2D(64, 3, 3, activation='relu', name='conv1_2'))

model.add(MaxPooling2D((2, 2), strides=(2, 2)))

model.add(ZeroPadding2D((1, 1)))

model.add(Convolution2D(128, 3, 3, activation='relu', name='conv2_1'))

model.add(ZeroPadding2D((1, 1)))

model.add(Convolution2D(128, 3, 3, activation='relu', name='conv2_2'))

model.add(MaxPooling2D((2, 2), strides=(2, 2)))

model.add(ZeroPadding2D((1, 1)))

model.add(Convolution2D(256, 3, 3, activation='relu', name='conv3_1'))

model.add(ZeroPadding2D((1, 1)))

model.add(Convolution2D(256, 3, 3, activation='relu', name='conv3_2'))

model.add(ZeroPadding2D((1, 1)))

model.add(Convolution2D(256, 3, 3, activation='relu', name='conv3_3'))

model.add(MaxPooling2D((2, 2), strides=(2, 2)))

model.add(ZeroPadding2D((1, 1)))

model.add(Convolution2D(512, 3, 3, activation='relu', name='conv4_1'))

model.add(ZeroPadding2D((1, 1)))

model.add(Convolution2D(512, 3, 3, activation='relu', name='conv4_2'))

model.add(ZeroPadding2D((1, 1)))

model.add(Convolution2D(512, 3, 3, activation='relu', name='conv4_3'))

model.add(MaxPooling2D((2, 2), strides=(2, 2)))

model.add(ZeroPadding2D((1, 1)))

model.add(Convolution2D(512, 3, 3, activation='relu', name='conv5_1'))

model.add(ZeroPadding2D((1, 1)))

model.add(Convolution2D(512, 3, 3, activation='relu', name='conv5_2'))

model.add(ZeroPadding2D((1, 1)))

model.add(Convolution2D(512, 3, 3, activation='relu', name='conv5_3'))

model.add(MaxPooling2D((2, 2), strides=(2, 2))) # get the symbolic outputs of each "key" layer (we gave them unique names).layer_dict = dict([(layer.name, layer) for layer in model.layers])

 从使用Convolution2D来看,是比较早的版本写的。 .

 2、Sequential模型如何部分layer载入权重

 下面,我们将预训练好的权重载入模型,一般而言我们可以通过model.load_weights()载入,但这种办法是载入全部的权重,并不适用。 之前所看到的No_top模型就是用来应付此时的。 这里我们只载入一部分参数,用的是set_weights()函数,所以我们需要手工载入:

 import h5py

weights_path = '.../vgg16_weights.h5'f = h5py.File(weights_path)for k in range(f.attrs['nb_layers']):    if k >= len(model.layers):        break

    g = f['layer_{}'.format(k)]

    weights = [g['param_{}'.format(p)] for p in range(g.attrs['nb_params'])]

    model.layers[k].set_weights(weights)

f.close()

print('Model loaded.')

 笔者在实践过程中,并没有实践出来,因为我载入的.h5,不知道为什么没有属性f.attrs[‘nb_layers’]也没有属性g.attrs[‘nb_params’]) 

 在寻找答案的过程中,看到有前人也跟我一样的问题,

 可见([keras]猫狗大战的总结):

 http://blog.csdn.net/smuevian/article/details/60333974

 Q1.f.attrs[‘nb_layers’]是什么意思?我看h5py中没有’nb_layers’的属性啊?attrs是指向f中的属性,点击右键可以看见这个属性(在HDF5-viewer)Q2.g= f[‘layer_{}’.format(k)]的含义,.format的作用 format是格式化的意思,输出g就是format(k)填充到{}上Q3.weights = [g[‘param_{}’.format(p)] for p inrange(g.attrs[‘nb_params’])]的含义 得到的是layer下param_0、param_1等 这里用到的是set_weights(weights),weights设置的大小应与该层网络大小一致,否则会报错。

 人工智能大数据深度学习

 搜索添加微信公众号:weic2c

 长按图片,识别二维码,点关注

 大数据挖掘DT数据分析

 搜索添加微信公众号:datadw

 教你机器学习,教你数据挖掘

 长按图片,识别二维码,点关注

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
keras中文文档之:CNN眼中的世界:利用Keras解释CNN的滤波器
本文有代码; 本文作者:Francois Chollet 使用Keras探索卷积网络的滤波器 本文中我们将利用Keras观察CNN到底在学些什么,它是如何理解我们送入的训练图片的。我们将使用Keras
CreateAMind
2018/07/20
7950
AI 技术讲座精选:菜鸟学深度学习(二)
【AI100 导读】如何才能创建出自己的卷积神经网络呢?在本篇文章中我们会一起来探讨一下这个问题。我们将会继续处理在该系列第一部分谈到的图像分割问题。 可用来创建卷积神经网络的深度学习库有很多。我们
AI科技大本营
2018/04/26
6690
AI 技术讲座精选:菜鸟学深度学习(二)
ResNet34_keras dropout
其中在网络搭建的过程中分为4个stage,蓝色箭头是在Unet中要进行合并的层。注意:前向的运算encoder过程一共经过了5次降采样,包括刚开始的 7 ∗ 7 7*7 7∗7卷积 stride,所以decoder过程要有5次上采样的过程,但是跨层连接(encoder 与 decoder之间)只有4次,如下图所示,以输入图像大小224×224为例:
全栈程序员站长
2022/11/08
9300
ResNet34_keras dropout
【连载14】VGG、MSRANet和Highway Networks
在论文《Very Deep Convolutional Networks for Large-Scale Image Recognition》中提出,通过缩小卷积核大小来构建更深的网络。
lujohn3li
2020/03/05
1.4K0
【连载14】VGG、MSRANet和Highway Networks
【自然语言处理】--视觉问答(Visual Question Answering,VQA)从初始到应用
视觉问答(Visual Question Answering,VQA),是一种涉及计算机视觉和自然语言处理的学习任务。这一任务的定义如下: A VQA system takes as input an image and a free-form, open-ended, natural-language question about the image and produces a natural-language answer as the output[1]。 翻译为中文:一个VQA系统以一张图片和一个关于这张图片形式自由、开放式的自然语言问题作为输入,以生成一条自然语言答案作为输出。简单来说,VQA就是给定的图片进行问答。
LhWorld哥陪你聊算法
2018/09/13
1.7K0
【自然语言处理】--视觉问答(Visual Question Answering,VQA)从初始到应用
如何生成一幅艺术作品
假设我们有一幅大师的画作了,我们怎么能够提取出“大师作品”中的纹理和颜色这些细节让我们的计算机知道,而不是只看到画的整体造型呢?
zhuanxu
2018/08/23
4730
如何生成一幅艺术作品
R语言基于Keras的小数据集深度学习图像分类
您有时会听到深度学习仅在有大量数据可用时才有效。这部分是有效的:深度学习的一个基本特征是它可以自己在训练数据中找到有趣的特征,而不需要手动特征工程,这只有在有大量训练样例可用时才能实现。对于输入样本非常高维的问题(如图像)尤其如此。
拓端
2020/11/19
8560
R语言基于Keras的小数据集深度学习图像分类
憨批的语义分割3——unet模型详解以及训练自己的unet模型(划分斑马线)[通俗易懂]
在这一个BLOG里,我会跟大家讲一下什么是unet模型,以及如何训练自己的unet模型,其训练与上一篇的segnet模型差距不大,但是结构上有一定的差距。如果想要先有语义分割的基础,可以看我的博文憨批的语义分割2——训练自己的segnet模型(划分斑马线)
全栈程序员站长
2022/07/05
8.3K0
憨批的语义分割3——unet模型详解以及训练自己的unet模型(划分斑马线)[通俗易懂]
深度学习-使用预设计的模型预测
通常对于神经网络来说,如果自己训练将会非常的费时间,有一种方法就是用别人在大样本上训练好的数据,然后使用在自己的网络上,比如,我们的分类目标是猫和狗的分类,如果存在一种大数据的动物分类器,那么就可以实现我们猫和狗分类的目的 有两种方式实现
火星娃统计
2020/09/15
7100
深度学习-使用预设计的模型预测
[开发技巧]·安卓手机开发深度学习简易教程(基于Keras)
本教程基于安卓手机平台,在PyDroid3软件上,使用Python3语言配合Keras框架开发深度学习。本文章主要涉及在手机上开发环境的搭建,以及简单的示例代码,如果想深入研究开发,还需要读者自己花些功夫了。不废话,开始教程。。
小宋是呢
2019/06/27
9150
[开发技巧]·安卓手机开发深度学习简易教程(基于Keras)
深度学习模型系列(1) | VGG16 Keras实现
VGGNet是牛津大学视觉几何组(Visual Geometry Group)提出的模型,该模型在2014ImageNet图像分类与定位挑战赛 ILSVRC-2014中取得在分类任务第二,定位任务第一的优异成绩。VGGNet突出的贡献是证明了很小的卷积,通过增加网络深度可以有效提高性能。
机器学习学研社
2019/09/19
4.7K0
深度学习模型系列(1) | VGG16 Keras实现
keras TensorFlow_tensorflow 安装
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
全栈程序员站长
2022/11/10
8070
【Keras】Keras入门指南
在用了一段时间的Keras后感觉真的很爽,所以特意祭出此文与我们公众号的粉丝分享。 Keras是一个非常方便的深度学习框架,它以TensorFlow或Theano为后端。用它可以快速地搭建深度网络,灵活地选取训练参数来进行网路训练。总之就是:灵活+快速!
keloli
2018/09/13
2K0
keras 基础入门整理
在进行自然语言处理之前,需要对文本进行处理。 本文介绍keras提供的预处理包keras.preproceing下的text与序列处理模块sequence模块
学到老
2019/01/25
1.5K0
基于Keras进行迁移学习
机器学习中的迁移学习问题,关注如何保存解决一个问题时获得的知识,并将其应用于另一个相关的不同问题。
崔庆才
2019/09/04
1.8K0
基于Keras进行迁移学习
自己写个 Prisma
本文介绍了如何通过使用TensorFlow和Keras库实现一个简单的生成对抗网络(GAN),用于生成类似于Prisma的图像。作者使用VGG16作为生成器和判别器,通过反向传播算法训练模型,并利用限制-内存优化算法进行超参数调整,最终生成高质量的图像。
MachineLP
2018/01/09
6640
自己写个 Prisma
keras系列︱图像多分类训练与利用bottleneck features进行微调(三)
该文摘要总结:利用卷积神经网络来对图像进行特征提取和分类,使用预训练的VGG16网络作为基础网络,通过修改网络结构以适应自己的数据集,并使用合成数据集进行训练。在训练过程中,使用了数据增强技术,包括旋转、翻转和水平翻转等,以提高模型的性能。最终,该模型在测试集上获得了85.43%的准确率,表现良好。
悟乙己
2018/01/02
4.4K0
keras系列︱图像多分类训练与利用bottleneck features进行微调(三)
一文总览CNN网络架构演进:从LeNet到DenseNet
卷积神经网络可谓是现在深度学习领域中大红大紫的网络框架,尤其在计算机视觉领域更是一枝独秀。CNN从90年代的LeNet开始,21世纪初沉寂了10年,直到12年AlexNet开始又再焕发第二春,从ZF Net到VGG,GoogLeNet再到ResNet和最近的DenseNet,网络越来越深,架构越来越复杂,解决反向传播时梯度消失的方法也越来越巧妙。新年有假期,就好好总结一波CNN的各种经典架构吧,领略一下CNN的发展历程中各路大神之间的智慧碰撞之美。
小草AI
2019/05/29
8530
如何从零开发一个复杂深度学习模型
深度学习框架中涉及很多参数,如果一些基本的参数如果不了解,那么你去看任何一个深度学习框架是都会觉得很困难,下面介绍几个新手常问的几个参数。 batch 深度学习的优化算法,说白了就是梯度下降。每次的参数更新有两种方式。 第一种,遍历全部数据集算一次损失函数,然后算函数对各个参数的梯度,更新梯度。这种方法每更新一次参数都要把数据集里的所有样本都看一遍,计算量开销大,计算速度慢,不支持在线学习,这称为Batch gradient descent,批梯度下降。 另一种,每看一个数据就算一下损失函数,然后求梯度更新
朱晓霞
2018/04/18
3.2K0
如何从零开发一个复杂深度学习模型
keras doc 10终结篇 激活函数 回调函数 正则项 约束项 预训练模型
激活函数可以通过设置单独的激活层实现,也可以在构造层对象时通过传递activation参数实现。
CreateAMind
2018/07/25
2.3K0
keras doc 10终结篇 激活函数 回调函数 正则项 约束项 预训练模型
推荐阅读
相关推荐
keras中文文档之:CNN眼中的世界:利用Keras解释CNN的滤波器
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文