tensorflow 读取cifar_如何在Tensorflow中读取CIFAR-10数据集?

请看下面的github页,我在那里做了这些。如果上面的链接失败,请按照kgeorge.github.io上的线索,查看笔记本tf_cifar.ipynb。我尝试使用小步骤加载cifar-10数据。请查找函数load_and_preprocess_input

该代码中的以下函数接受数据作为(nsamples,32x32x3)float32的np数组,并将其标记为nsamples int32的np数组,并预处理tensorflow训练要使用的数据。image_depth=3

image_height=32

image_width=32

#data = (nsamples, 32x32x3) float32

#labels = (nsamples) int32

def prepare_input(data=None, labels=None):

global image_height, image_width, image_depth

assert(data.shape[1] == image_height * image_width * image_depth)

assert(data.shape[0] == labels.shape[0])

#do mean normaization across all samples

mu = np.mean(data, axis=0)

mu = mu.reshape(1,-1)

sigma = np.std(data, axis=0)

sigma = sigma.reshape(1, -1)

data = data - mu

data = data / sigma

is_nan = np.isnan(data)

is_inf = np.isinf(data)

if np.any(is_nan) or np.any(is_inf):

print('data is not well-formed : is_nan {n}, is_inf: {i}'.format(n= np.any(is_nan), i=np.any(is_inf)))

#data is transformed from (no_of_samples, 3072) to (no_of_samples , image_height, image_width, image_depth)

#make sure the type of the data is no.float32

data = data.reshape([-1,image_depth, image_height, image_width])

data = data.transpose([0, 2, 3, 1])

data = data.astype(np.float32)

return data, labels

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值