当前位置:网站首页>Load local cifar10 dataset
Load local cifar10 dataset
2022-06-25 15:50:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
Because we use official import cifar10 data Set method failed , In the know cifar10 In the case of a local path to a dataset , You can import through the following methods :
import tensorflow as tf
import numpy as np
import math
from six.moves import cPickle as pickle
import os
import platform
from subprocess import check_output
classes = ('plane', 'car', 'bird', 'cat',
'deer', 'dog', 'frog', 'horse', 'ship', 'truck')
def load_pickle(f):
version = platform.python_version_tuple()
if version[0] == '2':
return pickle.load(f)
elif version[0] == '3':
return pickle.load(f, encoding='latin1')
raise ValueError("invalid python version: {}".format(version))
def load_CIFAR_batch(filename):
""" load single batch of cifar """
with open(filename, 'rb') as f:
datadict = load_pickle(f)
X = datadict['data']
Y = datadict['labels']
X = X.reshape(10000,3072)
Y = np.array(Y)
return X, Y
def load_CIFAR10(ROOT):
""" load all of cifar """
xs = []
ys = []
for b in range(1,6):
f = os.path.join(ROOT, 'data_batch_%d' % (b, ))
X, Y = load_CIFAR_batch(f)
xs.append(X)
ys.append(Y)
Xtr = np.concatenate(xs)
Ytr = np.concatenate(ys)
del X, Y
Xte, Yte = load_CIFAR_batch(os.path.join(ROOT, 'test_batch'))
return Xtr, Ytr, Xte, Yte
def get_CIFAR10_data(num_training=49000, num_validation=1000, num_test=10000):
# Load the raw CIFAR-10 data
cifar10_dir = '../input/cifar-10-batches-py/'
X_train, y_train, X_test, y_test = load_CIFAR10(cifar10_dir)
# Subsample the data
mask = range(num_training, num_training + num_validation)
X_val = X_train[mask]
y_val = y_train[mask]
mask = range(num_training)
X_train = X_train[mask]
y_train = y_train[mask]
mask = range(num_test)
X_test = X_test[mask]
y_test = y_test[mask]
x_train = X_train.astype('float32')
x_test = X_test.astype('float32')
x_train /= 255
x_test /= 255
return x_train, y_train, X_val, y_val, x_test, y_test
# Invoke the above function to get our data.
x_train, y_train, x_val, y_val, x_test, y_test = get_CIFAR10_data()
print('Train data shape: ', x_train.shape)
print('Train labels shape: ', y_train.shape)
print('Validation data shape: ', x_val.shape)
print('Validation labels shape: ', y_val.shape)
print('Test data shape: ', x_test.shape)
print('Test labels shape: ', y_test.shape)Reference resources :
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/152110.html Link to the original text :https://javaforall.cn
边栏推荐
- What is OA
- Day01: learning notes
- Internal class learning notes
- 深度学习 pytorch cifar10数据集训练「建议收藏」
- For the first time in Chinese universities! Unique in the world! Tongji students win international awards
- 中国高校首次!全球唯一!同济学子斩获国际大奖
- Client development (electron) system level API usage 2
- 剑指 Offer 06. 从尾到头打印链表
- 什么是oa
- Why is it said that restarting can solve 90% of the problems
猜你喜欢
Desktop development (Tauri) opens the first chapter

Sword finger offer 09 Implementing queues with two stacks

MySQL performance optimization - index optimization

JVM memory region details
Inter thread synchronization semaphore control

合宙Air32F103CBT6开发板上手报告

VectorDraw Developer Framework 10.1001 Crack
How to convert a recorded DOM to a video file
Practice of geospatial data in Nepal graph
Why is it said that restarting can solve 90% of the problems
随机推荐
基于神经标签搜索,中科院&微软亚研零样本多语言抽取式摘要入选ACL 2022
QC, QA, IPQC, JQE, DQA, SQE, DQC, MQC, IQC, FQC, OQC
在国信金太阳开股票账户安全吗?
Mark the same items in the Li list in red
基于深度Q学习的雅达利打砖块游戏博弈
How to convert a recorded DOM to a video file
剑指 Offer 05. 替换空格
Internal class learning notes
Gold three silver four, an article to solve the resume and interview
Inter thread synchronization semaphore control
js 给元素添加自定义属性
Thread - learning notes
Start using markdown
Brief object memory layout
LeCun预言AGI:大模型和强化学习都是斜道!我的「世界模型」才是新路
The situation and suggestions of a software engineering associate graduate who failed in the postgraduate entrance examination
合宙Air32F103CBT6開發板上手報告
原生js动态添加元素
[issue 24] one year experience of golang to develop futu
Report on Hezhou air32f103cbt6 development board