-
大小: 53.54MB文件类型: .zip金币: 1下载: 0 次发布日期: 2022-05-24
- 语言: Python
- 标签: tensorflow mnist python
资源简介
博客:https://blog.csdn.net/weixin_45775701/article/details/109446515
代码片段和文件信息
import os
import glob
import tensorflow as tf
import mnist_inference
import mnist_train
from PIL import Image ImageFilter
import matplotlib.pyplot as plt
import cv2
def image_prepare(pic_name):
# 读取图像,第二个参数是读取方式
img = cv2.imread(pic_name 1)
# 使用全局阈值,降噪
retth1 = cv2.threshold(img127255cv2.THRESH_BINARY)
# 把opencv图像转化为PIL图像
im = Image.fromarray(cv2.cvtColor(th1cv2.COLOR_BGR2RGB))
# 灰度化
im = im.convert(‘L‘)
# 为图片重新指定尺寸
im = im.resize((2828) Image.ANTIALIAS)
# plt.imshow(im)
# plt.show()
# 图像转换为list
im_list = list(im.getdata())
# 图像灰度反转
result = [(255-x)*1.0/255.0 for x in im_list]
return result
def main(argv=None):
# 把要识别的图片放到下面的文件夹中
img_path = ‘picture/‘
imgs = glob.glob(os.path.join(img_path ‘*‘))
for p in imgs:
# 图像处理:降噪、灰度化、修改尺寸以及灰度反转
pic = image_prepare(p)
# 识别图像
evaluate(pic p)
def evaluate(pic pic_name):
with tf.Graph().as_default() as g:
x = tf.placeholder(tf.float32 [None mnist_inference.INPUT_NODE] name=‘x-input‘)
y_ = tf.placeholder(tf.float32 [None mnist_inference.OUTPUT_NODE] name=‘y-input‘)
validate_feed = {x:[pic]}
y = mnist_inference.inference(x None)
result = tf.argmax(y 1)
variable_averages = tf.train.ExponentialMovingAverage(mnist_train.MOVING_AVERAGE_DECAY)
variables_to_restore = variable_averages.variables_to_restore()
saver = tf.train.Saver(variables_to_restore)
with tf.Session() as sess:
ckpt = tf.train.get_checkpoint_state(mnist_train.MODEL_SAVE_PATH)
if ckpt and ckpt.model_checkpoint_path:
saver.restore(sess ckpt.model_checkpoint_path)
global_step = ckpt.model_checkpoint_path.split(‘/‘)[-1].split(‘-‘)[-1]
number = sess.run(result feed_dict=validate_feed)
pic_name = pic_name.split(‘\\‘)[-1]
print(pic_name‘ is :‘number[0])
else:
print(‘No checkpoint file found‘)
return
if __name__ == ‘__main__‘:
main()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2020-11-03 13:06 Handwritten-Numeral-Recognition\
目录 0 2020-11-02 12:07 Handwritten-Numeral-Recognition\MNIST_data\
文件 60008 2020-11-01 10:36 Handwritten-Numeral-Recognition\MNIST_data\train-labels.idx1-ubyte
目录 0 2020-11-03 18:18 __MACOSX\
目录 0 2020-11-03 18:18 __MACOSX\Handwritten-Numeral-Recognition\
目录 0 2020-11-03 18:18 __MACOSX\Handwritten-Numeral-Recognition\MNIST_data\
文件 232 2020-11-01 10:36 __MACOSX\Handwritten-Numeral-Recognition\MNIST_data\._train-labels.idx1-ubyte
文件 47040016 2020-11-01 11:30 Handwritten-Numeral-Recognition\MNIST_data\train-images.idx3-ubyte
文件 232 2020-11-01 11:30 __MACOSX\Handwritten-Numeral-Recognition\MNIST_data\._train-images.idx3-ubyte
文件 10008 2020-11-01 10:35 Handwritten-Numeral-Recognition\MNIST_data\t10k-labels.idx1-ubyte
文件 232 2020-11-01 10:35 __MACOSX\Handwritten-Numeral-Recognition\MNIST_data\._t10k-labels.idx1-ubyte
文件 1648877 2020-11-01 11:41 Handwritten-Numeral-Recognition\MNIST_data\t10k-images-idx3-ubyte.gz
文件 7840016 2020-11-01 10:36 Handwritten-Numeral-Recognition\MNIST_data\t10k-images.idx3-ubyte
文件 232 2020-11-01 10:36 __MACOSX\Handwritten-Numeral-Recognition\MNIST_data\._t10k-images.idx3-ubyte
文件 9912422 2020-11-01 11:37 Handwritten-Numeral-Recognition\MNIST_data\train-images-idx3-ubyte.gz
文件 28881 2020-11-01 11:37 Handwritten-Numeral-Recognition\MNIST_data\train-labels-idx1-ubyte.gz
文件 4542 2020-11-01 11:45 Handwritten-Numeral-Recognition\MNIST_data\t10k-labels-idx1-ubyte.gz
文件 176 2020-11-01 11:45 __MACOSX\Handwritten-Numeral-Recognition\MNIST_data\._t10k-labels-idx1-ubyte.gz
文件 1232 2019-06-05 15:21 Handwritten-Numeral-Recognition\mnist_inference.py
文件 274 2019-06-05 15:21 __MACOSX\Handwritten-Numeral-Recognition\._mnist_inference.py
文件 2683 2020-11-01 11:44 Handwritten-Numeral-Recognition\mnist_train.py
文件 274 2020-11-01 11:44 __MACOSX\Handwritten-Numeral-Recognition\._mnist_train.py
文件 32248 2020-11-01 20:08 Handwritten-Numeral-Recognition\timg.jpeg
文件 176 2020-11-01 20:08 __MACOSX\Handwritten-Numeral-Recognition\._timg.jpeg
文件 10265 2020-11-03 12:37 Handwritten-Numeral-Recognition\as.png
文件 233 2020-11-03 12:37 __MACOSX\Handwritten-Numeral-Recognition\._as.png
文件 14340 2020-11-03 13:06 Handwritten-Numeral-Recognition\.DS_Store
文件 120 2020-11-03 13:06 __MACOSX\Handwritten-Numeral-Recognition\._.DS_Store
目录 0 2020-11-01 19:30 Handwritten-Numeral-Recognition\MNIST_model\
文件 3180084 2020-11-01 19:29 Handwritten-Numeral-Recognition\MNIST_model\mnist_model-6001.data-00000-of-00001
文件 3180084 2019-06-05 14:53 Handwritten-Numeral-Recognition\MNIST_model\mnist_model-28001.data-00000-of-00001
............此处省略116个文件信息
相关资源
- python(numpy scipy matplotlib sklearn)安装
- python2和python3版本可用的OpenCV安装包
- 基于ArcGIS的Python编程秘笈(第2版)
- 21天学通Python高清Pdf+源代码+PPT
- Python-简单快速实时可定制的机器学习
- python爬取漏洞库.zip
- python算法与数据结构三本教材书籍推
- python神经网络中英文代码.zip
- python3面向对象编程 pdf文件
- tensorflow_gpu-1.9.0-cp36-cp36m-win_amd64.whl
- 飞机大战python源码及游戏
- 数据结构与算法:Python语言描述 完整
- Python语言程序设计 梁勇著 李娜译
- python程序设计第二版.pdf
- OpenCV+Python+Dlib面部标定、眨眼和疲劳
- PYTHON数据可视化编程实战以及中文P
- CBIR图像检索系统
- 零基础学PYTHON全彩版完整版PDF2 2-2
- Easy Python Decompiler v1.3.2
- 2015新书-Python高手之路英文原版-完整
- python学习用到的几本书打包
- OpenCV 3.x with Python By Example(2nd) 无水
- Python+Spark 2.0+Hadoop机器学习与大数据实
- Python+Spark 2.0+Hadoop机器学习与大数据实
- python爬虫开发与项目实战
- 面向ArcGIS的Python脚本编程美国Paul A.
- python爬虫项目开发实战+源代码
- python 经典入门+进阶书籍打包 中英文
- 基于Python的人脸识别系统
- 疯狂Python讲义
评论
共有 条评论