【发布时间】:2017-11-06 18:17:03
【问题描述】:
我正在尝试下载 MNIST 数据集并对其进行解码而不将其写入磁盘(主要是为了好玩)。
request_stream = urlopen('http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz')
zip_file = GzipFile(fileobj=request_stream, mode='rb')
with zip_file as fd:
magic, numberOfItems = struct.unpack('>ii', fd.read(8))
rows, cols = struct.unpack('>II', fd.read(8))
images = np.fromfile(fd, dtype='uint8') # < here be dragons
images = images.reshape((numberOfItems, rows, cols))
return images
此代码失败并显示 OSError: obtaining file position failed,这是一个似乎无法通过 Google 搜索的错误。可能是什么问题?
【问题讨论】:
标签: python-3.x numpy gzip