关于python:使用mmap在numpy.load期间出现ACCESS_READ错误

ACCESS_READ error during numpy.load using mmap

我正试图加载一个相当大的numpy数组(大约75k个图像),但由于整个数据集都被加载到内存中,所以我不断地出现内存错误。我想使用numpy-mmap,但我一直收到访问读取错误。当我尝试使用mmap加载numpy数组时,我总是得到错误:

Traceback (most recent call last):

File"mmap.py", line 29, in
training_images = np.load('data_small/training_images.npy', mmap_mode='r', encoding = 'latin1')

File"/usr/local/lib/python2.7/site-packages/numpy/lib/npyio.py", line 416, in load
return format.open_memmap(file, mode=mmap_mode)

File"/usr/local/lib/python2.7/site-packages/numpy/lib/format.py", line 792, in open_memmap
mode=mode, offset=offset)

File"/usr/local/lib/python2.7/site-packages/numpy/core/memmap.py", line 205, in new
import mmap

File"/Users/Bjarnason/Desktop/AVEC/mmap.py", line 29, in
training_images = np.load('data_small/training_images.npy', mmap_mode='r', encoding = 'latin1')

File"/usr/local/lib/python2.7/site-packages/numpy/lib/npyio.py", line 416, in load
return format.open_memmap(file, mode=mmap_mode)
File"/usr/local/lib/python2.7/site-packages/numpy/lib/format.py", line 792, in open_memmap
mode=mode, offset=offset)

File"/usr/local/lib/python2.7/site-packages/numpy/core/memmap.py", line 257, in new
acc = mmap.ACCESS_READ

AttributeError: 'module' object has no attribute 'ACCESS_READ'

下面是我要运行的代码:

import numpy as np training_images =
np.load('data_small/training_images.npy', mmap_mode='r')


不要调用你的文件mmap.py。这将隐藏numpy使用的python mmap库。

numpy库中的文件numpy/core/memmap.py执行import mmapmmap是python标准库的一部分,但您的文件也被称为mmap.py,因此numpy执行的导入会找到您的文件。