tensorflow学习笔记(MNIST-2)

# -*- 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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值