当前位置:网站首页>转换Cifar10数据集
转换Cifar10数据集
2022-06-25 15:36:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
Cifar10数据集不讲了吧,入门必备,下载地址: https://www.cs.toronto.edu/~kriz/cifar.html 官方提供三种形式的下载:
可以看出是不提供图片形式的下载的,需要进行数据转换,虽然可以直接读成ndarray,但是对于初学者可能读图更直观点
自己写了个转换程序(将bytes形式的文件转换为图片并分类存储):
def recover_cifar10(cifar10_dir):
"""Save cifar 10 data(only training data) to files. Args: cifar10_dir: cifar 10 dataset path(python version). Returns: """
save_dir = './data/cifar10'
def save_batch(path):
with open(path, 'rb') as fo:
batch_data = pickle.load(fo, encoding='bytes')
X, Y, N = batch_data[b'data'], batch_data[b'labels'], batch_data[b'filenames']
batch_size = X.shape[0]
for x in range(0, batch_size):
sample = X[x].reshape((3, 32, 32))
r, g, b = sample[0], sample[1], sample[2]
r0, g0, b0 = Image.fromarray(r), Image.fromarray(g), Image.fromarray(b)
sample_rgb = Image.merge('RGB', (r0, g0, b0))
sample_label = bytes.decode(label_names[Y[x]]) # image label
sample_name = bytes.decode(N[x])
cat_dir = join(save_dir, sample_label)
if not os.path.exists(cat_dir):
os.makedirs(cat_dir)
sample_save_path = join(cat_dir, sample_name)
sample_rgb.save(sample_save_path)
with open(join(cifar10_dir, 'batches.meta'), 'rb') as fo:
meta_data = pickle.load(fo, encoding='bytes')
label_names = meta_data[b'label_names']
for x in range(1, 6):
path = join(cifar10_dir, 'data_batch_%s' % str(x))
save_batch(path)有需要的拿走,可以直接用
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/152107.html原文链接:https://javaforall.cn
边栏推荐
- Using reentrantlock and synchronized to implement blocking queue
- Brief introduction to class loading process
- Lombok common notes
- Startup and shutdown of appium service
- Popular cross domain
- 镁光256Gb NAND Flash芯片介绍
- Yadali brick playing game based on deep Q-learning
- Install Kali extension 1: (kali resolution problem)
- CPU over high diagnosis and troubleshooting
- 在打新债开户证券安全吗,需要什么准备
猜你喜欢
Super comprehensive custom deep copy function

Continuous integration of aspnetcore & cloud flow

剑指 Offer 03. 数组中重复的数字

剑指 Offer 10- I. 斐波那契数列

Talk about the creation process of JVM objects
How to convert a recorded DOM to a video file

Arthas source code learning-1

Optimization of lazyagg query rewriting in parsing data warehouse

异步处理容易出错的点

Principle and implementation of MySQL master-slave replication (docker Implementation)
随机推荐
Ten routing strategies for distributed task scheduling platform XXL job
Image segmentation based on deep learning: network structure design
Distributed transaction solution
JVM memory region details
合宙Air32F103CBT6开发板上手报告
Programmer vs hacker thinking | daily anecdotes
[paper notes] street view change detection with deconvolutional networks
Detailed summary of reasons why alertmanager fails to send alarm messages at specified intervals / irregularly
到底要不要去外包公司?这篇带你全面了解外包那些坑!
Error com mysql. cj. jdbc. exceptions. Communicationsexception: solutions to communications link failure
Highly concurrent optimized Lua + openresty+redis +mysql (multi-level cache implementation) + current limit +canal synchronization solution
Talk about the creation process of JVM objects
What is OA
Sword finger offer 04 Find in 2D array
基于神经标签搜索,中科院&微软亚研零样本多语言抽取式摘要入选ACL 2022
Go build reports an error missing go sum entry for module providing package ... to add:
If a thread overflows heap memory or stack memory, will other threads continue to work
Super comprehensive custom deep copy function
How GC determines whether an object can be recycled
分享自己平时使用的socket多客户端通信的代码技术点和软件使用