gpt4 book ai didi

python pickle UnicodeDecodeError

转载 作者:太空狗 更新时间:2023-10-29 17:40:41 25 4
gpt4 key购买 nike

我正在尝试加载 mnist 字符数据集(遵循此处概述的教程:http://neuralnetworksanddeeplearning.com/chap1.html)

当我运行 load_data_wrapper 函数时出现错误。

UnicodeDecodeError: 'ascii' codec can't decode byte 0x90 in position 614: ordinal not in range(128)

运行的代码是:

import numpy as np
import gzip


def load_data():
f = gzip.open('../data/mnist.pkl.gz', 'rb')
training_data, validation_data, test_data = pickle.load(f)
f.close()
return (training_data, validation_data, test_data)

def load_data_wrapper():
tr_d, va_d, te_d = load_data()
training_inputs = [np.reshape(x, (784,1)) for x in tr_d[0]]
training_results = [vectorized_result(y) for y in tr_d[1]]
training_data = zip(training_inputs, training_results)
validation_inputs = [np.reshape(x,(784, 1))for x in va_d[0]]
validation_data = zip(validation_inputs, va_d[1])
test_inputs = [np.reshape(x, (784, 1)) for x in te_d[0]]
test_data = zip(test_inputs, te_d[1])
return(training_data, validation_data, test_data)

def vectorized_result(j):
e = np.zeros((10,1))
e[j] = 1.0
return e

更新:问题似乎是我正在尝试用 python 2.x pickle 的 python 3.6 取消 pickle 。

最佳答案

如前所述,主要问题是 python 2.x cPickle 和 python 3.x pickle 之间的不兼容。

将编码设置为“latin-1”似乎可行。

training_data, validation_data, test_data = pickle.load(f, encoding='latin1')

这里的回答很有帮助:Pickle incompatability of numpy arrays between Python 2 and 3

关于python pickle UnicodeDecodeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40493856/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com