Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Как открыть cifar на 3м питоне? #41

Open
od2elf opened this issue Nov 23, 2016 · 2 comments
Open

Как открыть cifar на 3м питоне? #41

od2elf opened this issue Nov 23, 2016 · 2 comments

Comments

@od2elf
Copy link

od2elf commented Nov 23, 2016

На 3м питоне функция load_CIFAR_batch

def load_CIFAR_batch(filename):
    """ load single batch of cifar """
    with open(filename, 'rb') as f:
        datadict = pickle.loads(f, fix_imports=True, encoding="bytes", errors="strict")
        X = datadict['data']
        Y = datadict['labels']
        X = X.reshape(10000, 3, 32, 32).transpose(0,2,3,1).astype("float")
        Y = np.array(Y)
    return (X, Y)

выдает ошибку 'ascii' codec can't decode byte 0x8b in position 6: ordinal not in range(128)
Что делать?

@mponty
Copy link

mponty commented Nov 23, 2016

поменяй на datadict = pickle.load(f,encoding = 'latin1')
А еще хорошо X.reshape(10000, 3, 32, 32).transpose(0,2,3,1).astype("float") изменить на lasagne.utils.floatX( X.reshape(10000, 3, 32, 32) )

@od2elf
Copy link
Author

od2elf commented Nov 25, 2016

Спасибо за ответ, но похоже дело не в этом.
Вставил энкодинг='latin1', упростил код до вот такого:

import os
import _pickle as pickle

data_folder = './cifar10/cifar-10-batches-py'
batch1_filename = os.path.join(data_folder, 'data_batch_1')#%d' % (b, ))

def upickle(filename):
with open(filename) as f:
datadict = pickle.load(f, fix_imports=True, encoding='latin1', errors='strict')
return datadict

batch1=upickle(batch1_filename)

Результат, немного другой, но все равно неудовлетварительный:


UnicodeDecodeError Traceback (most recent call last)
in ()
9 datadict = pickle.load(f, fix_imports=True, encoding='latin1', errors='strict')
10 return datadict
---> 11 batch1=upickle(batch1_filename)
in upickle(filename)
7 def upickle(filename):
8 with open(filename) as f:
----> 9 datadict = pickle.load(f, fix_imports=True, encoding='latin1', errors='strict')
10 return datadict
11 batch1=upickle(batch1_filename)
/home/od2elf/anaconda3/lib/python3.5/codecs.py in decode(self, input, final)
319 # decode input (taking the buffer into account)
320 data = self.buffer + input
--> 321 (result, consumed) = self._buffer_decode(data, self.errors, final)
322 # keep undecoded input until the next call
323 self.buffer = data[consumed:]
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte

Теперь сраываетсяне на 6м символе, а на 0м =)))
Но,что забавно, какой бы метод энкодинга не пытался использовать в прошлый раз он грешилна кодек ASCII, а сейчас на кодек utf-8, может что-то не так в глобальных переменных системы?

od2elf@Hebys:~$ echo $LANG
en_US.UTF-8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants