当前位置:网站首页>Tensorflow loading cifar10 dataset
Tensorflow loading cifar10 dataset
2022-06-25 15:51:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
load cifar10 data Set
cifar10_dir = 'C:/Users/1/.keras/datasets/cifar-10-batches-py'
(train_images, train_labels), (test_images, test_labels) = load_data(cifar10_dir)Be careful : Under the official website cifar10 Decompress the data set into the following form
load_local_cifar10.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import sys
import numpy as np
from six.moves import cPickle
from tensorflow.keras import backend as K
def load_batch(fpath, label_key='labels'):
"""Internal utility for parsing CIFAR data. # Arguments fpath: path the file to parse. label_key: key for label data in the retrieve dictionary. # Returns A tuple `(data, labels)`. """
with open(fpath, 'rb') as f:
if sys.version_info < (3,):
d = cPickle.load(f)
else:
d = cPickle.load(f, encoding='bytes')
# decode utf8
d_decoded = {
}
for k, v in d.items():
d_decoded[k.decode('utf8')] = v
d = d_decoded
data = d['data']
labels = d[label_key]
data = data.reshape(data.shape[0], 3, 32, 32)
return data, labels
def load_data(ROOT):
"""Loads CIFAR10 dataset. # Returns Tuple of Numpy arrays: `(x_train, y_train), (x_test, y_test)`. """
# dirname = 'cifar-10-batches-py'
# origin = 'https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz'
# path = get_file(dirname, origin=origin, untar=True)
path = ROOT
num_train_samples = 50000
x_train = np.empty((num_train_samples, 3, 32, 32), dtype='uint8')
y_train = np.empty((num_train_samples,), dtype='uint8')
for i in range(1, 6):
fpath = os.path.join(path, 'data_batch_' + str(i))
(x_train[(i - 1) * 10000: i * 10000, :, :, :],
y_train[(i - 1) * 10000: i * 10000]) = load_batch(fpath)
fpath = os.path.join(path, 'test_batch')
x_test, y_test = load_batch(fpath)
y_train = np.reshape(y_train, (len(y_train), 1))
y_test = np.reshape(y_test, (len(y_test), 1))
if K.image_data_format() == 'channels_last':
x_train = x_train.transpose(0, 2, 3, 1)
x_test = x_test.transpose(0, 2, 3, 1)
return (x_train, y_train), (x_test, y_test)Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/152113.html Link to the original text :https://javaforall.cn
边栏推荐
- 面试官:你简历上说精通mysql,那你说下聚簇/联合/覆盖索引、回表、索引下推
- Traversal and branch judgment of JS (case on June 24, 2022)
- What is OA
- Time wheel and implementation analysis of time wheel in go zero
- 客户经理给的开户链接办理股票开户安全吗?我想开个户
- Popular cross domain
- VectorDraw Developer Framework 10.1001 Crack
- 双目3D感知(一):双目初步认识
- Prototype mode
- NFT元宇宙发展能做什么?
猜你喜欢

中国高校首次!全球唯一!同济学子斩获国际大奖

The style of the mall can also change a lot. DIY can learn about it!
Golang open source streaming media audio and video network transmission service -lal
MySQL installation tutorial

04. binary tree

Brief introduction to class loading process
Cloning and importing DOM nodes

剑指 Offer 04. 二维数组中的查找
Why is it said that restarting can solve 90% of the problems

免费送书啦!火遍全网的AI给老照片上色,这里有一份详细教程!
随机推荐
What are the reasons why the game industry needs high defense servers?
到底要不要去外包公司?这篇带你全面了解外包那些坑!
The situation and suggestions of a software engineering associate graduate who failed in the postgraduate entrance examination
免费送书啦!火遍全网的AI给老照片上色,这里有一份详细教程!
leetcode-8. 字符串转换整数 (atoi)
Binocular 3D perception (I): preliminary understanding of binocular
Principle and implementation of MySQL master-slave replication (docker Implementation)
Traversal and branch judgment of JS (case on June 24, 2022)
[issue 24] one year experience of golang to develop futu
Popular cross domain
How to reload the win10 app store?
Startup and shutdown of appium service
MySQL修改字段語句
TFIDF与BM25
TensorFlow加载cifar10数据集
Asynchronous processing of error prone points
剑指 Offer 03. 数组中重复的数字
Sword finger offer II 091 Paint the house
在国信金太阳开股票账户安全吗?
MySQL installation tutorial