当前位置:网站首页>TensorFlow加载cifar10数据集
TensorFlow加载cifar10数据集
2022-06-25 15:36:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
加载cifar10数据集
cifar10_dir = 'C:/Users/1/.keras/datasets/cifar-10-batches-py'
(train_images, train_labels), (test_images, test_labels) = load_data(cifar10_dir)注意:在官网下好cifar10数据集后将其解压成下面形式
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)发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/152113.html原文链接:https://javaforall.cn
边栏推荐
- Desktop development (Tauri) opens the first chapter
- golang使用mongo-driver操作——增(进阶)
- Image segmentation based on deep learning: network structure design
- Globally unique key generation strategy - implementation principle of the sender
- 在打新债开户证券安全吗,需要什么准备
- 中国高校首次!全球唯一!同济学子斩获国际大奖
- Jz-065 path in matrix
- 将一个文件写入到另一个文件的标记位置
- Brief introduction to class loading process
- Why is it said that restarting can solve 90% of the problems
猜你喜欢

Differences and solutions of redis cache avalanche, cache penetration and cache breakdown

Source code analysis of nine routing strategies for distributed task scheduling platform XXL job

Websocket (WS) cluster solution

Yadali brick playing game based on deep Q-learning

Several relationships of UML
Why is it said that restarting can solve 90% of the problems
![[paper notes] mcunetv2: memory efficient patch based influence for tiny deep learning](/img/4b/f446bd37057237c0ba4c7b4e38e74f.jpg)
[paper notes] mcunetv2: memory efficient patch based influence for tiny deep learning

Programmer vs hacker thinking | daily anecdotes
After the project is pushed to the remote warehouse, Baota webhook automatically publishes it

If a thread overflows heap memory or stack memory, will other threads continue to work
随机推荐
[golang] leetcode intermediate - find the first and last position of an element in a sorted array & Merge interval
数据类型的内置方法
What is OA
股票开户用什么app最安全?知道的给说一下吧
MySQL transaction characteristics and implementation principle
What is session? How is it different from cookies?
Differences between = = and = = = in JS (detailed explanation)
Cloning and importing DOM nodes
Is it safe to open a stock account through the account opening link of the account manager?
Mapbox map - inconsistent coordinate system when docking GIS layers?
Kali SSH Remote Login
Arthas source code learning-1
Finally, we can figure out whether the binding event in the tag is bracketed or not
不要再「外包」AI 模型了!最新研究发现:有些破坏机器学习模型安全的「后门」无法被检测到
Learning to Measure Changes: Fully Convolutional Siamese Metric Networks for Scene Change Detection
Several relationships of UML
Principle and implementation of MySQL master-slave replication (docker Implementation)
Using reentrantlock and synchronized to implement blocking queue
How to debug grpc by postman
04. binary tree