-
Notifications
You must be signed in to change notification settings - Fork 5
MNIST
JunX edited this page Dec 5, 2018
·
1 revision
MNIST是一个入门级的计算机视觉数据集,它包含各种手写数字图片.
- http://tensorfly.cn/tfdoc/tutorials/mnist_beginners.html
- http://colah.github.io/posts/2014-10-Visualizing-MNIST/
- THE MNIST DATABASE of handwritten digits
- Notebook: Get Started with TensorFlow - mnist
- Fashion-MNIST
(x_train, y_train), (x_test, y_test) = mnist.load_data()
Download the mnist dataset and load the train data & test data
load_data(): tensorflow/python/keras/datasets/mnist.py
Build the tf.keras model by stacking layers. Select an optimizer and loss function used for training:
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(512, activation=tf.nn.relu),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10, activation=tf.nn.softmax)
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
- Flatten
- Dense
- relu
- softmax
- Dropout
N.B. relu & softmax 为激活函数
Flatten层用来将输入“压平”,即把多维的输入一维化,常用在从卷积层到全连接层的过渡。Flatten不影响batch的大小。
Dense就是常用的全连接层,所实现的运算是output = activation(dot(input, kernel)+bias)。其中activation是逐元素计算的激活函数,kernel是本层的权值矩阵,bias为偏置向量,只有当use_bias=True才会添加。
为输入数据施加Dropout。Dropout将在训练过程中每次更新参数时按一定概率(rate)随机断开输入神经元,Dropout层用于防止过拟合。
Step-3 complie model
compile 接收三个参数:
- 优化器 optimizer。它可以是现有优化器的字符串标识符,如 rmsprop 或 adagrad,也可以是 Optimizer 类的实例。
- 损失函数 loss,模型试图最小化的目标函数。它可以是现有损失函数的字符串标识符,如 categorical_crossentropy 或 mse,也可以是一个目标函数。
- 评估标准 metrics。对于任何分类问题,你都希望将其设置为 metrics = ['accuracy']。评估标准可以是现有的标准的字符串标识符,也可以是自定义的评估标准函数。
Step-4 Train and evaluate model
model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test)
- fit() 以固定数量的轮次(数据集上的迭代)训练模型。
- evaluate() 在测试模式,返回误差值和评估标准值。计算逐批次进行。
Test with this mnist_cnn.py with mnist_cnn.ipynb
Epoch 1/12
60000/60000 [==============================] - 176s 3ms/step - loss: 0.2684 - acc: 0.9177 - val_loss: 0.0554 - val_acc: 0.9832
Epoch 1/12
60000/60000 [==============================] - 10s 174us/step - loss: 0.2744 - acc: 0.9141 - val_loss: 0.0543 - val_acc: 0.9823
- Docker
-
Yocto
- devtool
- Raspberry PI
- Install raspbian
- Raspberrypi Samba
- Boot from USB drive
- shadowsocks setup
- Markdown 语法
- ML/TL/DL/RL
- MNIST
- 吴恩达机器学习课程
- 吴恩达深度学习课程
- Tensorflow
- Hub
- Models
-
Movidius™ Neural Compute Stick
- ncsdk
- ncappzoo