from keras.models import Sequential
from keras.layers import Conv2D, MaxPool2D, Flatten, Dense
import numpy as np
# 设置随机种子
np.random.seed(1447)

def build_model():
    '''
    在Begin-End段中构建出如下结构的卷积神经网络
    1. 64个5*5的卷积核组成的卷积层,激活函数为relu
    2. 最大池化层,池化核大小为2*2
    3. 扁平化
    4. 128个神经元的全连接层,激活函数为relu
    5. 10个神经元的全连接层,激活函数为softmax
    :return: 构建好的模型
    '''
    model = Sequential()
    model.add(Conv2D(32, (5, 5), activation='relu', input_shape=[28, 28, 1]))
    #********* Begin *********#
    model.add(Conv2D(64, (5, 5), activation='relu'))
    model.add(MaxPool2D(pool_size=(2, 2)))
    model.add(Flatten())
    model.add(Dense(128, activation='relu'))
    model.add(Dense(10, activation='softmax'))
    #********* End *********#
    return model
Keras 卷积神经网络模型构建:手写数字识别

原文地址: https://www.cveoy.top/t/topic/oe06 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录