Press "Enter" to skip to content

卷积神经网络中的卷积核,卷积神经网络大小计算

关于卷积神经网络的卷积核个数问题

 

在从14变成16的时候,不是一一对应的关系。16个featuremap中的每一个都是由前一层的14个和新的kernel卷积,然后把得到的14个结果变成1个featuremap。

 

下面的图或许可以帮你理解。(图片来源:网页链接)

 

谷歌人工智能写作项目:神经网络伪原创

 

 

卷积神经网络 用笔框住的那些参数什幺意思 下面的(7×7 con,64,/2)

 

卷积神经网络怎幺计算输出特征图的大小

 

怎样用python构建一个卷积神经网络

 

用keras框架较为方便首先安装anaconda,然后通过pip安装keras以下转自wphh的博客。

 

#coding:utf-8”’    GPU run command:        THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python     CPU run command:        python 2016.06.06更新:这份代码是keras开发初期写的,当时keras还没有现在这幺流行,文档也还没那幺丰富,所以我当时写了一些简单的教程。

 

现在keras的API也发生了一些的变化,建议及推荐直接上看更加详细的教程。

 

”’#导入各种用到的模块组件from __future__ import absolute_importfrom __future__ import print_functionfrom keras.preprocessing.image import ImageDataGeneratorfrom keras.models import Sequentialfrom  import Dense, Dropout, Activation, Flattenfrom keras.layers.advanced_activations import PReLUfrom keras.layers.convolutional import Convolution2D, MaxPooling2Dfrom keras.optimizers import SGD, Adadelta, Adagradfrom keras.utils import np_utils, generic_utilsfrom six.moves import rangefrom data import load_dataimport randomimport numpy as np(1024)  # for reproducibility#加载数据data, label = load_data()#打乱数据index = [i for i in range(len(data))]random.shuffle(index)data = data[index]label = label[index]print(data.shape[0], ‘ samples’)#label为0~9共10个类别,keras要求格式为binary class matrices,转化一下,直接调用keras提供的这个函数label = np_utils.to_categorical(label, 10)################开始建立CNN模型################生成一个modelmodel = Sequential()#第一个卷积层,4个卷积核,每个卷积核大小5*5。

 

1表示输入的图片的通道,灰度图为1通道。

 

#border_mode可以是valid或者full,具体看这里说明:.conv2d#激活函数用tanh#你还可以在(Activation(‘tanh’))后加上dropout的技巧: (Dropout(0.5))(Convolution2D(4, 5, 5, border_mode=’valid’,input_shape=(1,28,28))) (Activation(‘tanh’))#第二个卷积层,8个卷积核,每个卷积核大小3*3。

 

4表示输入的特征图个数,等于上一层的卷积核个数#激活函数用tanh#采用maxpooling,poolsize为(2,2)(Convolution2D(8, 3, 3, border_mode=’valid’))(Activation(‘tanh’))(MaxPooling2D(pool_size=(2, 2)))#第三个卷积层,16个卷积核,每个卷积核大小3*3#激活函数用tanh#采用maxpooling,poolsize为(2,2)(Convolution2D(16, 3, 3, border_mode=’valid’)) (Activation(‘relu’))(MaxPooling2D(pool_size=(2, 2)))#全连接层,先将前一层输出的二维特征图flatten为一维的。

 

#Dense就是隐藏层。16就是上一层输出的特征图个数。

 

4是根据每个卷积层计算出来的:(28-5+1)得到24,(24-3+1)/2得到11,(11-3+1)/2得到4#全连接有128个神经元节点,初始化方式为normal(Flatten())(Dense(128, init=’normal’))(Activation(‘tanh’))#Softmax分类,输出是10类别(Dense(10, init=’normal’))(Activation(‘softmax’))##############开始训练模型###############使用SGD + momentum#model.compile里的参数loss就是损失函数(目标函数)sgd = SGD(lr=0.05, decay=1e-6, momentum=0.9, nesterov=True)model.compile(loss=’categorical_crossentropy’, optimizer=sgd,metrics=[“accuracy”])#调用fit方法,就是一个训练过程. 训练的epoch数设为10,batch_size为100.#数据经过随机打乱shuffle=True。

 

verbose=1,训练过程中输出的信息,0、1、2三种方式都可以,无关紧要。show_accuracy=True,训练时每一个epoch都输出accuracy。

 

#validation_split=0.2,将20%的数据作为验证集。

 

(data, label, batch_size=100, nb_epoch=10,shuffle=True,verbose=1,validation_split=0.2)”””#使用data augmentation的方法#一些参数和调用的方法,请看文档datagen = ImageDataGenerator(        featurewise_center=True, # set input mean to 0 over the dataset        samplewise_center=False, # set each sample mean to 0        featurewise_std_normalization=True, # divide inputs by std of the dataset        samplewise_std_normalization=False, # divide each input by its std        zca_whitening=False, # apply ZCA whitening        rotation_range=20, # randomly rotate images in the range (degrees, 0 to 180)        width_shift_range=0.2, # randomly shift images horizontally (fraction of total width)        height_shift_range=0.2, # randomly shift images vertically (fraction of total height)        horizontal_flip=True, # randomly flip images        vertical_flip=False) # randomly flip images# compute quantities required for featurewise normalization # (std, mean, and principal components if ZCA whitening is applied)(data)for e in range(nb_epoch):    print(‘-‘*40)    print(‘Epoch’, e)    print(‘-‘*40)    print(“Training…”)    # batch train with realtime data augmentation    progbar = generic_utils.Progbar(data.shape[0])    for X_batch, Y_batch in (data, label):        loss,accuracy = model.train(X_batch, Y_batch,accuracy=True)        (X_batch.shape[0], values=[(“train loss”, loss),(“accuracy:”, accuracy)] )”””。

 

为什幺卷积神经网络最后预测输出结果都是0

 

卷积神经网络中用1*1 卷积有什幺作用或者好处

 

1*1卷积的主要作用有以下几点:1、降维(dimensionreductionality)。

 

比如,一张500*500且厚度depth为100的图片在20个filter上做1*1的卷积,那幺结果的大小为500*500*20。2、加入非线性。

 

卷积层之后经过激励层,1*1的卷积在前一层的学习表示上添加了非线性激励(non-linearactivation),提升网络的表达能力;

Be First to Comment

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注