MNIST 数据处理
来源:互联网 发布:网络转换器辐射大吗 编辑:程序博客网 时间:2024/05/23 02:03
# -*- coding: utf-8 -*-"""Created on Tue Mar 01 15:29:30 2016@author: wzhao"""import osos.getcwd()os.chdir("D:\\Workspace")import numpy as npimport structimport matplotlib.pyplot as plt """读入训练集, 60000"""filename = 'D:\\Workspace\\train-images.idx3-ubyte'binfile = open(filename , 'rb')buf = binfile.read() index = 0magic, numImages , numRows , numColumns = struct.unpack_from('>IIII' , buf , index)index += struct.calcsize('>IIII')images= [[0 for col in range(numImages)] for row in range(numRows*numColumns)]type(images) # listimages=np.array(images)images=images.reshape(numImages, numRows*numColumns)images.shape # (60000, 784)i=0while i<numImages: images[i,] = struct.unpack_from('>784B' ,buf, index) print i,index index += struct.calcsize('>784B') i+=1binfile.close()np.save("Train_Images.npy", images)"""读入训练集Label, 60000"""filename = 'D:\\Workspace\\train-labels.idx1-ubyte'binfile = open(filename , 'rb')buf = binfile.read()index = 0magic, numImages = struct.unpack_from('>II' , buf , index)index += struct.calcsize('>II')labels= [[0] for col in range(numImages) ]labels=np.array(labels)labels=labels.reshape(numImages, 1)labels.shape # (60000, 1)i=0while i<numImages: labels[i,] = struct.unpack_from('>1B' ,buf, index) print i,index index += struct.calcsize('>1B') i+=1 binfile.close()"""label_out=[[0 for col in range(60000)] for row in range(10)]label_out=np.array(label_out)label_out=label_out.reshape(60000, 10)label_out.shape # (60000, 10)i=0while i<numImages: label_out[i, labels[i]]=1 i+=1"""# labels[:5]# label_out[:5,]np.save("Train_Labels.npy", labels)"""# 读入文件结束""""""## 导出数据到文件np.save("MNIST.npy", images)# c = np.load( "MNIST.npy" )images.tofile("MNIST.bin")images.dtype # dtype('int32')b = np.fromfile("MNIST.bin", dtype=np.int32)type(b)b.shapeb=b.reshape(numImages, 784)""""""# 打印图形,查看是否正确导入文件"""fig = plt.figure()plotwindow = fig.add_subplot(111)plt.imshow(im , cmap='gray')plt.show()
0 0
- MNIST 数据处理
- 【TensorFlow】数据处理(将MNIST转为TFRecord)
- mnist
- mnist
- mnist
- MNIST
- 数据处理
- 数据处理
- 数据处理
- 数据处理
- 数据处理
- 数据处理
- 数据处理
- 数据处理
- 数据处理
- 数据处理
- 数据处理
- 数据处理
- 测试-性能测试
- linux内核线程死锁或死循环(soft lockup)之后如何让系统宕机重启
- CentOS下安装JDK1.8
- Andrew NG机器学习课程笔记系列之——机器学习之神经网络模型-下(Neural Networks: Representation)
- Palindrome Linked List
- MNIST 数据处理
- 2016蓝桥杯算法提高——十进制转数转八进制数
- M2_PERO
- LeetCode 4. Median of Two Sorted Arrays
- maven之间不能查看源码 the jar file M2_REPO has no source attachment
- Python Multinomial Logistics 实现MNIST分类
- 一致性哈希算法
- Android Toolbar使用ActionMode
- C++第一次上机报告 1-2