本节我们的目标是,在上一篇博文的基础上,我们再来实现几个复杂一点的CNN模型。为下一篇CNN做文本分类打下基础。
inception模型来自谷歌的一篇论文Going Deeper with Convolutions.具体来讲,这里的卷积网络模型可以用下面的图表示:
#!/usr/bin/env python # encoding: utf-8 """ @version: python2.7 @author: Xiangguo Sun @contact: sunxiangguodut@qq.com @site: http://blog.csdn.net/github_36326955 @software: PyCharm @file: inception @time: 17-7-13 下午2:36 [Going Deeper with Convolutions](https://arxiv.org/abs/1409.4842) """ from keras.layers import Conv2D, MaxPooling2D, Input,Concatenate from keras.models import Model from keras.optimizers import SGD from keras.utils import plot_model input_img = Input(shape=(3, 256, 256)) tower_1 = Conv2D(64, (1, 1), padding='same', activation='relu')(input_img) tower_1 = Conv2D(64, (3, 3), padding='same', activation='relu')(tower_1) tower_2 = Conv2D(64, (1, 1), padding='same', activation='relu')(input_img) tower_2 = Conv2D(64, (5, 5), padding='same', activation='relu')(tower_2) tower_3 = MaxPooling2D((3, 3), strides=(1, 1), padding='same')(input_img) tower_3 = Conv2D(64, (1, 1), padding='same', activation='relu')(tower_3) output = Concatenate(axis=1)([tower_1, tower_2, tower_3]) model = Model(inputs=input_img,outputs=output) sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True) model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy']) print(model.summary()) plot_model(model,to_file="./inception.png",show_shapes=True)打印一下模型的结果,看一看结构:
打印结果如下:
《卷积神经网络CNN理论到实践(7)》
Welcome to my blog column: Dive into ML/DL!
I devote myself to dive into typical algorithms on machine learning and deep learning, especially the application in the area of computational personality.My research interests include computational personality, user portrait, online social network, computational society, and ML/DL. In fact you can find the internal connection between these concepts:
In this blog column, I will introduce some typical algorithms about machine learning and deep learning used in OSNs(Online Social Networks), which means we will include NLP, networks community, information diffusion,and individual recommendation system. Apparently, our ultimate target is to dive into user portrait , especially the issues on your personality analysis.
All essays are created by myself, and copyright will be reserved by me. You can use them for non-commercical intention and if you are so kind to donate me, you can scan the QR code below. All donation will be used to the library of charity for children in Lhasa.
附:《春天里,我们的拉萨儿童图书馆,需要大家的帮助》