Ai
2 Star 0 Fork 0

mirrors_lepy/Machine-Learning-with-Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mnist-deep-learning.py 941 Bytes
一键复制 编辑 原始数据 按行查看 历史
Amogh Singhal 提交于 2018-05-09 17:16 +08:00 . Adding mnist-deep-learning.py
from keras.datasets import mnist
(train_images, train_labels), (test_images, test_labels) = mnist.load_data()
# 1. Prepare the Data
from keras.utils import to_categorical
train_images = train_images.reshape((60000, 28 * 28)).astype('float32') / 255
test_images = test_images.reshape((10000, 28 * 28)).astype('float32') / 255
train_labels = to_categorical(train_labels)
test_labels = to_categorical(test_labels)
# 2. Set up network architecture
from keras import models, layers
network = models.Sequential()
network.add(layers.Dense(512, activation='relu', input_shape=(28 * 28,)))
network.add(layers.Dense(10, activation='softmax'))
# 3/4. Pick Optimizer and Loss
network.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy'])
network.fit(train_images, train_labels, epochs=5, batch_size=128)
# 5. Measure on test
test_loss, test_acc = network.evaluate(test_images, test_labels)
print('test_acc:', test_acc)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_lepy/Machine-Learning-with-Python.git
git@gitee.com:mirrors_lepy/Machine-Learning-with-Python.git
mirrors_lepy
Machine-Learning-with-Python
Machine-Learning-with-Python
master

搜索帮助