# -*- coding:utf-8 -*-
# "-*- coding:utf-8 -*-" 定义源代码的编码格式,#
from tensorflow.python.platform import gfile
from tensorflow.contrib.learn.python.learn.datasets.mnist import extract_images
from tensorflow.contrib.learn.python.learn.datasets.mnist import extract_labels
from tensorflow.contrib.learn.python.learn.datasets.mnist import DataSet
from tensorflow.contrib.learn.python.learn.datasets import base
import numpy as np
import pandas as pd
import tensorflow as tf
def input_data_from_local():
# train_x,train_y,test_x,test_y的文件路径
TRAIN_IMAGES = 'train-images-idx3-ubyte.gz'
TRAIN_LABELS = 'train-labels-idx1-ubyte.gz'
TEST_IMAGES = 't10k-images-idx3-ubyte.gz'
TEST_LABELS = 't10k-labels-idx1-ubyte.gz'
# 打开文件使用with操作,使用结束后自动关闭文件
with gfile.Open(TRAIN_IMAGES,'rb') as f:
train_images=extract_images(f)
#print (train_images.shape)
# 读取labels时one-hot=True,可以将[1,2,3]转化为[[0,1,0,0,0,0,0,0,0,0],[0,0,1,0,0,0,0,0,0,0,0],[0,0,0,1,0,0,0,0,0,0]]
with gfile.Open(TRAIN_LABELS,'rb') as f:
train_labels=extract_labels(f,one_hot=True)
#print (train_labels.shape)
with gfile.Open(TEST_IMAGES,'rb') as f:
test_images=extract_images(f)
#print (test_images.shape)
with gfile.Open(TEST_LABELS,'rb') as f
tensorflow学习笔记(MNIST-2)
最新推荐文章于 2020-12-09 13:17:37 发布
这篇博客介绍了如何使用TensorFlow从本地文件中加载MNIST数据集,并通过两个不同的神经网络模型进行手写数字识别。首先,通过GradientDescentOptimizer训练了一个简单的单层神经网络,然后使用卷积神经网络(CNN)模型进一步提高识别精度。每个模型都包含了训练、验证和测试的步骤。
摘要由CSDN通过智能技术生成