没有合适的资源?快使用搜索试试~ 我知道了~
cifar10-100 读取方法 python
需积分: 50 52 下载量 165 浏览量
2017-04-24
17:26:43
上传
评论
收藏 3KB TXT 举报
温馨提示
试读
4页
cifar10读取
资源推荐
资源详情
资源评论
import numpy as np
import os
import cPickle as pickle
import glob
import matplotlib.pyplot as plt
you_dir='C:\cifar-10-batches-py'
class_names_cifar10 = np.load(os.path.join(you_dir, "batches.meta"))
#class_names_cifar100 = np.load(os.path.join(you_dir, "meta"))
def one_hot(x, n):
"""
convert index representation to one-hot representation
"""
x = np.array(x)
assert x.ndim == 1
return np.eye(n)[x]
def _load_batch_cifar10(filename, dtype='float64'):
"""
load a batch in the CIFAR-10 format
"""
path = os.path.join(you_dir, filename)
batch = np.load(path)
data = batch['data'] / 255.0 # scale between [0, 1]
labels = one_hot(batch['labels'], n=10) # convert labels to one-hot representation
return data.astype(dtype), labels.astype(dtype)
def _grayscale(a):
print a.reshape(a.shape[0], 3, 32, 32).mean(1).reshape(a.shape[0], -1)
return a.reshape(a.shape[0], 3, 32, 32).mean(1).reshape(a.shape[0], -1)
import os
import cPickle as pickle
import glob
import matplotlib.pyplot as plt
you_dir='C:\cifar-10-batches-py'
class_names_cifar10 = np.load(os.path.join(you_dir, "batches.meta"))
#class_names_cifar100 = np.load(os.path.join(you_dir, "meta"))
def one_hot(x, n):
"""
convert index representation to one-hot representation
"""
x = np.array(x)
assert x.ndim == 1
return np.eye(n)[x]
def _load_batch_cifar10(filename, dtype='float64'):
"""
load a batch in the CIFAR-10 format
"""
path = os.path.join(you_dir, filename)
batch = np.load(path)
data = batch['data'] / 255.0 # scale between [0, 1]
labels = one_hot(batch['labels'], n=10) # convert labels to one-hot representation
return data.astype(dtype), labels.astype(dtype)
def _grayscale(a):
print a.reshape(a.shape[0], 3, 32, 32).mean(1).reshape(a.shape[0], -1)
return a.reshape(a.shape[0], 3, 32, 32).mean(1).reshape(a.shape[0], -1)
资源评论
appron
- 粉丝: 73
- 资源: 45
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功