Tensorflow 自己的手写数字实践与数据集制作

本文介绍了如何使用TensorFlow进行手写数字识别,重点讲解了数据集的制作过程,包括如何创建tfrecords文件以及如何解析这些文件。通过将手写数字图片转换为特定格式并利用tfrecords提高内存利用率,实现高效的数据读取。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前面学习了关于使用MNIST数据集中的数据进行训练和测试。现在要用自己的手写数字进行识别

使用自己的手写数字进行识别

主要部分如下

def application():
    testNum = int(input("input the number of test pictures:"))
    for i in range(testNum):
        testPic = input("the path of test picture:")
        testPicArr = pre_pic(testPic)
        preValue = restore_model(testPicArr)
        print("prediction num is",preValue)

整体代码如下

1、先是导包

import tensorflow as tf
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
import mnist_backward
import mnist_forward

2、模型加载

def restore_model(testPicArr):
    with tf.Graph().as_default() as tg:
        x = tf.placeholder(tf.float32,[None,mnist_forward.INPUT_NODE])
        y = mnist_forward.forward(x,None)
        preValue = tf.argmax(y,1)
        
        variable_averages = tf.train.ExponentialMovingAverage(mnist_backward.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_backward.MODEL_SAVE_PATH)
            if (ckpt and ckpt.model_checkpoint_path):
                saver.restore(sess,ckpt.model_checkpoint_path)
                preValue = sess.run(preValue, feed_dict={x:testPicArr})
      
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值