#from google.colab import drive
#drive.mount('/content/drive')
from __future__ import absolute_import, division, print_function, unicode_literals
import matplotlib.pyplot as plt;
import matplotlib.cm as cm
import numpy as np
# 安装 TensorFlow
try:
# Colab only
%tensorflow_version 2.x
except Exception:
pass
import tensorflow as tf
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
print(y_train[0])
plt.figure(1) #图像显示
plt.imshow(x_train[0],cmap=cm.gray)
plt.show()
x_train, x_test = x_train / 255.0, x_test / 255.0
print(x_train.shape)
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
//模型训练
model.fit(x_train, y_train, epochs=5)
//模型估计
model.evaluate(x_test, y_test, verbose=2)
//模型预测
image_raw = tf.io.read_file('../1.png','rb')
print(image_raw.shape)
img_data_png = tf.io.decode_png(image_raw)
print(img_data_png.shape)
print(type(img_data_png))
img_data_png_gray = tf.image.rgb_to_grayscale(
img_data_png, name=None
)
imageScaled= tf.image.resize(img_data_png_gray, (28,28))
imageScaled = tf.image.adjust_contrast(imageScaled, 10)
imageScaled = 255.0 - imageScaled
print(imageScaled.shape)
squeezed = np.squeeze(imageScaled)
print(squeezed.shape)
#squeezed_float = np.array(squeezed)/255.0f
squeezed = squeezed/255.0
print(squeezed.shape)
result = model.predict(np.array([squeezed]))
print(result)
print(type(squeezed))
print(squeezed.shape)
plt.figure(1) #图像显示
plt.imshow(squeezed,cmap=cm.gray)
plt.show()
分享到:
相关推荐
tensorflow-mnist-VAE, MNIST变分自动编码器的Tensorflow实现 用于MNIST的变分本文介绍了一种用于 MNIST descripbed的变分自动编码器( VAE )的实现方法:基于等的自动编码变分贝叶斯。结果复制训练良好的VAE必须能够...
用卷积神经网络来完成MNIST手写数字算法的详细说明,及对conv2d及max_pool的详细说明
基于TensorFlow深度学习的Minist手写数字识别技术.pdf
Tensorflow MINIST数据模型源码,文章地址 https://blog.csdn.net/cc_want/article/details/83824439
用于学习谷歌的TensorFlow 55000 组 图片和标签, 用于训练。 5000 组 图片和标签, 用于迭代验证训练的准确性。 10000 组 图片和标签, 用于最终测试训练的准确性。
GAN 的基本例程,能够很好的帮助你理解生成对抗网络
1990 年代提出的LeNet-5使卷积神经网络在当时成功商用,下图是 LeNet-5 的网络结构图,它接受32 × 32大小的数字、字符图片,这次将LeNet-5模型用来识别MINIST数据集中的数字,并在测试集中计算其识别准确率。...
Tensorflow官网基本Minist识别,改成windows下python3版本
TensorFlow利用卷积神经网络识别手写数据集MNIST,使用2个卷积层,1个全连接隐藏层,1个输出层
tensorflow 的官方样例 手写数字识别的minist数据集,官网下载的,给有需要的朋友
MNIST分类的多层感知器训练客观的该项目旨在使用numpy在MNIST数据集上训练多层感知器(MLP)深层神经网络。 手写数字具有784个输入(每个图像中的像素值)和10个表示数字0-9的输出类别。 此外,您可以从获取数据: ...
1、该资源内项目代码经过严格调试,下载即用确保可以运行!...基于Python3.6+tensorflow1.6的实践和应用源码(包括线性模型,minist数据集分类,Tensorboard,CNN,LSTM,图像识别网络inception-v3等).zip
深度学习入门经典数据集MNIST的图片格式,共包含42000张训练图像。
官网的MNIST例子,包含数据包,因为官网的例子上没办法下载数据包,所以分享给大家。
这个资源是经典的Fishion-MNIST数据集。如果你是深度学习小白新手,在学习之初想用一些单间的数据集来进行训练,可以使用这个经典的Fishion-MINIST数据集。
训练MINIST数据集
TensorFlow2.0进行Minist手写体识别
用logistic和softmax进行MINIST数据的0,1的二分类和0-9的多分类
初步实现K均值算法,并上穿minist数据集供参考
tensorflow分类应用(MNIST手写数字识别)的jupyter笔记