八、Inception V1的网络结构代码实现

前文

数据生成器+数据部分展示

# 读取数据
from keras.preprocessing.image import ImageDataGenerator

IMSIZE = 224
train_generator = ImageDataGenerator(rescale=1. / 255).flow_from_directory('../../data/data_inception/train',
                                                                           target_size=(IMSIZE, IMSIZE),
                                                                           batch_size=100,
                                                                           class_mode='categorical'
                                                                           )

validation_generator = ImageDataGenerator(rescale=1. / 255).flow_from_directory('../../data/data_inception/test',
                                                                                target_size=(IMSIZE, IMSIZE),
                                                                                batch_size=100,
                                                                                class_mode='categorical')

在这里插入图片描述

# 展示数据
from matplotlib import pyplot as plt

plt.figure()
fig, ax = plt.subplots(2, 5)
fig.set_figheight(7)
fig.set_figwidth(15)
ax = ax.flatten()
X, Y = next(train_generator)
for i in range(10): ax[i].imshow(X[i, :, :,: ])

在这里插入图片描述

Inception V1

#相比于之前,这里需要导入concatenate函数
from keras.layers import Conv2D, BatchNormalization, MaxPooling2D
from keras.layers import Flatten, Dropout, Dense, Input, concatenate
from keras import Model

input_layer = Input([IMSIZE, IMSIZE, 3])
x = input_layer
x = Conv2D(64, (7, 7), strides=(2, 2), padding='same', activation='relu')(x)
x = BatchNormalization(axis=3)(x)
x = MaxPooling2D(pool_size=(3, 3), strides=(2, 2), padding='same')(x)

x = Conv2D(192, (3, 3), strides=(1, 1), padding='same', activation='relu')(x)
x = BatchNormalization(axis=3)(x)  #para=4*192=768
x = MaxPooling2D(pool_size=(3, 3), strides=(2, 2), padding='same')(x)
x

在这里插入图片描述

for i in range(9):
    brach1x1 = Conv2D(64, (1, 1), strides=(1, 1), padding='same', activation='relu')(x)
    brach1x1 = BatchNormalization(axis=3)(brach1x1)
    brach3x3 = Conv2D(96, (1, 1), strides=(1, 1), padding='same', activation='relu')(x)
    brach3x3 = BatchNormalization(axis=3)(brach3x3)

    brach3x3 = Conv2D(128, (3, 3), strides=(1, 1), padding='same', activation='relu')(brach3x3)
    brach3x3 = BatchNormalization(axis=3)(brach3x3)

    brach5x5 = Conv2D(16, (1, 1), strides=(1, 1), padding='same', activation='relu')(x)
    brach5x5 = BatchNormalization(axis=3)(brach5x5)

    brach5x5 = Conv2D(32, (3, 3), strides=(1, 1), padding='same', activation='relu')(brach5x5)
    brach5x5 = BatchNormalization(axis=3)(brach5x5)

    branchpool = MaxPooling2D(pool_size=(3, 3), strides=(1, 1), padding='same')(x)
    branchpool = Conv2D(32, (1, 1), strides=(1, 1), padding='same', activation='relu')(branchpool)
    branchpool = BatchNormalization(axis=3)(branchpool)
    x = concatenate([brach1x1, brach3x3, brach5x5, branchpool], axis=3)
    x = MaxPooling2D(pool_size=(3, 3), strides=(2, 2), padding='same')(x)

x = Dropout(0.4)(x)
x = Flatten()(x)
x = Dense(17, activation='softmax')(x)
output_layer = x
model = Model(input_layer, output_layer)
model.summary()

在这里插入图片描述

Inception V1模型编译与拟合

#运行
from keras.optimizers import Adam

model.compile(loss='categorical_crossentropy', optimizer=Adam(lr=0.001), metrics=['accuracy'])
model.fit_generator(train_generator, epochs=20, validation_data=validation_generator)

在这里插入图片描述

GitHub下载地址:

Tensorflow1.15深度学习

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李好秀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值