保存cifar-10 数据集 图片 python3

#用于将cifar10的数据可视化
import pickle as p
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as plimg
from PIL import Image
def load_CIFAR_batch(filename):
with open(filename, 'rb')as f:
# datadict = p.load(f)
datadict = p.load(f,encoding='latin1')
X = datadict['data']
Y = datadict['labels']
X = X.reshape(10000, 3, 32, 32)
Y = np.array(Y)
return X, Y def load_CIFAR_Labels(filename):
with open(filename, 'rb') as f:
lines = [x for x in f.readlines()]
print(lines) if __name__ == "__main__":
load_CIFAR_Labels("./cifar-10-batches-py/batches.meta")
imgX, imgY = load_CIFAR_batch("./cifar-10-batches-py/data_batch_1")
print(imgX.shape)
print("正在保存图片:")
# for i in range(imgX.shape[0]):
for i in range(10):#值输出10张图片,用来做演示
# imgs = imgX[i - 1]#?
imgs = imgX[i]
img0 = imgs[0]
img1 = imgs[1]
img2 = imgs[2]
i0 = Image.fromarray(img0)#从数据,生成image对象
i1 = Image.fromarray(img1)
i2 = Image.fromarray(img2)
img = Image.merge("RGB",(i0,i1,i2))
name = "img" + str(i)+".png"
img.save("./cifar10_images/"+name,"png")#文件夹下是RGB融合后的图像 for j in range(imgs.shape[0]):
# img = imgs[j - 1]
img = imgs[j]
name = "img" + str(i) + str(j) + ".png"
print("正在保存图片" + name)
plimg.imsave("./cifar10_images/" + name, img)#文件夹下是RGB分离的图像 print("保存完毕.")

cifar-10下载链接:http://www.cs.toronto.edu/~kriz/cifar.html

cifar-10 图片可视化的更多相关文章

  1. 【翻译】TensorFlow卷积神经网络识别CIFAR 10Convolutional Neural Network (CNN)| CIFAR 10 TensorFlow

    原网址:https://data-flair.training/blogs/cnn-tensorflow-cifar-10/ by DataFlair Team · Published May 21, ...

  2. 基于.NetCore开发博客项目 StarBlog - (10) 图片瀑布流

    系列文章 基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客? 基于.NetCore开发博客项目 StarBlog - (2) 环境准备和创建项目 基于.NetC ...

  3. DL Practice:Cifar 10分类

    Step 1:数据加载和处理 一般使用深度学习框架会经过下面几个流程: 模型定义(包括损失函数的选择)——>数据处理和加载——>训练(可能包括训练过程可视化)——>测试 所以自己写代 ...

  4. 【神经网络与深度学习】基于Windows+Caffe的Minst和CIFAR—10训练过程说明

    Minst训练 我的路径:G:\Caffe\Caffe For Windows\examples\mnist  对于新手来说,初步完成环境的配置后,一脸茫然.不知如何跑Demo,有么有!那么接下来的教 ...

  5. windows 10 安装可视化mycat

    前提: 1.安装配置好JDK环境 2.安装配置好mysql 3.安装配置好Navicat 一.下载mycat git:https://github.com/MyCATApache/Mycat-down ...

  6. 10min系列之二日志可视化进阶

    10min系列之二日志可视化进阶(作者原创,同步发布在github) 本文需要有一定的python和前端基础,如果没基础的,请关注我后续的基础教程系列博客 本文所有的demo,都是浏览器下展示的 原创 ...

  7. Python 网络爬虫(图片采集脚本)

    ===============爬虫原理================== 通过Python访问网站,获取网站的HTML代码,通过正则表达式获取特定的img标签中src的图片地址. 之后再访问图片地址 ...

  8. JavaScript校验图片格式及大小

    <!DOCTYPE html> <html> <head> <title>JavaScript校验图片格式及大小</title> <s ...

  9. iOS,图片处理

    1.旋转图片 2.缩放图片 3.截取图片指定区域 4.祛除图片白色背景,弄成透明png 5.将UIView转化为UIImage,并转化为data和base64 6.将视频一帧(CMSampleBuff ...

随机推荐

  1. Linux —— 压缩命令

    压缩与解压命令 .zip格式 压缩文件: zip 压缩文件名 原文件名 (压缩目录添加 -r) 解压缩文件/目录: unzip .zip压缩包 .gz格式 压缩文件: gzip 原文件名称 压缩文件为 ...

  2. 102 Binary Tree Level Order Traversal 二叉树的层次遍历

    给定一个二叉树,返回其按层次遍历的节点值. (即zhu'ceng'de,从左到右访问).例如:给定二叉树: [3,9,20,null,null,15,7],    3   / \  9  20    ...

  3. [在读]web前端黑客技术揭秘

  4. vue http请求 vue-resource使用方法

    1.安装vue-resource扩展: npm install vue-resource 2.在main.js中引入 import http from 'vue-resource' 3.使用方法 // ...

  5. vue.js2.0实战填坑记录

    访https://github.com/bailicangdu/vue2-elm的PC商城 在创建的 router 对象中,如果不配置 mode,就会使用默认的 hash 模式,该模式下会将路径格式化 ...

  6. puppeteer 中国区的使用

    puppeteer 中国区的使用 [issues]https://github.com/GoogleChrome/puppeteer/issues/1426 两种方案 使用 cnpm .npmrc 中 ...

  7. Flask 学习系列(一) -登录

    Flask是一个使用 Python 编写的轻量级 Web 应用框架.其 WSGI 工具箱采用 Werkzeug ,模板引擎则使用 Jinja2 .Flask使用 BSD 授权. Flask也被称为 “ ...

  8. React项目搭建(脚手架)

    首先我们需要安装node环境:download nodejs:https://i.cnblogs.com/EditPosts.aspx?opt=1 找到你需要的版本和系统安装包下载并安装. 这时候你可 ...

  9. 如何找到SAP Cloud for Customer标准培训和认证方面的信息

    有一些朋友询问我如何在SAP官网上找到和SAP Cloud for Customer相关的标准培训信息,我这里把步骤写出来: 登录SAP官网https://training.sap.com 输入和Cl ...

  10. Kruskal与Prim

    一.最小生成树 在无向图中,连通且不含圈的图称为树(Tree).给定无向图G=(V,E),连接G中所有点,且边集是E的子集的树称为G的生成树(Spanning Tree),而权值最小的生成树称为最小生 ...