zoukankan      html  css  js  c++  java
  • keras手写数字识别

    import keras
    import time
    from keras.utils import np_utils

    start = time.time()
    (x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
    SHAPE = 28 * 28
    CLASSES = 10
    x_train = x_train.reshape(x_train.shape[0], SHAPE)
    x_test = x_test.reshape(x_test.shape[0], SHAPE)
    y_train = np_utils.to_categorical(y_train, CLASSES)
    y_test = np_utils.to_categorical(y_test, CLASSES)

    x_train = x_train.astype("float32")
    x_test = x_test.astype("float32")
    x_train /= 255
    x_test /= 255

    model = keras.models.Sequential([
    keras.layers.Dense(128, activation='relu'),
    keras.layers.Dropout(0.2),
    keras.layers.Dense(128, activation='relu'),
    keras.layers.Dropout(0.2),
    keras.layers.Dense(128, activation='relu'),
    keras.layers.Dropout(0.2),
    keras.layers.Dense(10, activation='softmax')
    ])

    model.compile(optimizer='adam',
    loss='categorical_crossentropy',
    metrics=['accuracy'])
    model.fit(x_train, y_train, batch_size=1000, epochs=50)
    evaluate = model.evaluate(x_test, y_test)
    print(evaluate)
    print("elapsed: ", time.time() - start)
  • 相关阅读:
    Tomcat配置
    Tomcat介绍和jbk安装
    nginx企业级优化
    linux 部署lnmp平台
    linux nginx服务
    linux rsync
    openssh远程连接及tcpwrappers防护
    linux 日志文件系统
    linux 解析文件系统原理
    linux 安全配置二
  • 原文地址:https://www.cnblogs.com/yytxdy/p/11660033.html
Copyright © 2011-2022 走看看