【问题标题】:Cifar - 10 / UnpickleCifar - 10 / Unpickle
【发布时间】:2018-04-11 18:39:06
【问题描述】:

当我尝试解开 cifar-10 数据集时出现以下错误。我需要训练一个模型,但我什至无法为我的操作获取数据。我该如何解决这个问题

dict=cPickle.load(fo)

UnpicklingError: 无效的加载键,'\x06'。

import tensorflow as tf
import os
import numpy as np
import dataset_class
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import glob
from PIL import Image
from scipy.spatial.distance import pdist


def cifar_10_reshape(batch_arg):
    output=np.reshape(batch_arg,(10000,3,32,32)).transpose(0,2,3,1)
    return output

def unpickle(file):
    import _pickle as cPickle
    fo=open(file,'rb')
    dict=cPickle.load(fo)
    fo.close()
    return dict




#Loading cifar-10 data and reshaping it to be batch_sizex32x32x3
batch1=unpickle('cifar-10-batches-py/data_batch_1.bin')
batch2=unpickle('cifar-10-batches-py/data_batch_2.bin')
batch3=unpickle('cifar-10-batches-py/data_batch_3.bin')
batch4=unpickle('cifar-10-batches-py/data_batch_4.bin')
batch5=unpickle('cifar-10-batches-py/data_batch_5.bin')



batch1_data=cifar_10_reshape(batch1['data'])
batch2_data=cifar_10_reshape(batch2['data'])
batch3_data=cifar_10_reshape(batch3['data'])
batch4_data=cifar_10_reshape(batch4['data'])
batch5_data=cifar_10_reshape(batch5['data'])

batch1_labels=batch1['labels']
batch2_labels=batch2['labels']
batch3_labels=batch3['labels']
batch4_labels=batch4['labels']
batch5_labels=batch5['labels']

test_batch=unpickle('cifar-10-batches-py/test_batch')
test_images=cifar_10_reshape(test_batch['data'])
test_labels_data=test_batch['labels']


train_images=np.concatenate((batch1_data,batch2_data,batch3_data,batch4_data,batch5_data),axis=0)
train_labels_data=np.concatenate((batch1_labels,batch2_labels,batch3_labels,batch4_labels,batch5_labels),axis=0)

【问题讨论】:

标签: python tensorflow deep-learning pickle


【解决方案1】:

根据我对 CIFAR-10 数据集的了解,您尝试取消提取的版本是二进制格式,而您没有向“取消提取器”提供​​有关编码的任何信息。尝试 CIFAR-10 网站 (https://www.cs.toronto.edu/~kriz/cifar.html) 上为 python 3.x 提供的加载功能可能会更幸运:

def unpickle(file):
    import pickle
    with open(file, 'rb') as fo:
        dict = pickle.load(fo, encoding='bytes')
    return dict

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-05
    • 1970-01-01
    • 2020-03-10
    • 2018-03-26
    • 1970-01-01
    • 1970-01-01
    • 2016-04-16
    • 2020-10-14
    相关资源
    最近更新 更多