当前位置:网站首页>转换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
边栏推荐
- Kali SSH Remote Login
- Install Kali extension 1: (kali resolution problem)
- Share the code technology points and software usage of socket multi client communication
- MySQL performance optimization - index optimization
- Is it safe to open a stock account through the account opening link of the account manager?
- Netlogo learning
- Start using markdown
- Distributed transaction solution
- 什么是NFT数字藏品?
- 中国高校首次!全球唯一!同济学子斩获国际大奖
猜你喜欢
随机推荐
Startup and shutdown of appium service
TFIDF and BM25
MySQL field truncation principle and source code analysis
Desktop development (Tauri) opens the first chapter
Golang uses Mongo driver operation - increase (Advanced)
剑指 Offer 07. 重建二叉树
Is it safe to open a stock account through the account opening link of the account manager?
Highly concurrent optimized Lua + openresty+redis +mysql (multi-level cache implementation) + current limit +canal synchronization solution
Go language modifies / removes multiple line breaks in strings
TFIDF与BM25
Client development (electron) system level API usage 2
将一个文件写入到另一个文件的标记位置
Yadali brick playing game based on deep Q-learning
剑指 Offer II 091. 粉刷房子
国信金太阳靠谱吗?是否合法?开股票账户安全吗?
客户经理给的开户链接办理股票开户安全吗?我想开个户
Why is it said that restarting can solve 90% of the problems
Agent and classloader
Is it safe to open a stock account in Guoxin golden sun?
Markdown learning








