【问题标题】:File load error: not enough storage available with 1.7TB storage free文件加载错误:可用 1.7TB 存储空间不足
【发布时间】:2019-12-20 00:07:34
【问题描述】:

我正在使用以下代码在 Python 中以 NiFTI 格式加载我的文件。

import nibabel as nib 

img_arr = []
for i in range(len(datadir)):
    img = nib.load(datadir[i])
    img_data = img.get_fdata()
    img_arr.append(img_data)
    img.uncache()

少量图像可以正常工作,但如果我想加载更多图像,则会收到以下错误:

OSError                                   Traceback (most recent call last)
<ipython-input-55-f982811019c9> in <module>()
     10     #img = nilearn.image.smooth_img(datadir[i],fwhm = 3) #Smoothing filter for preprocessing (necessary?)
     11     img = nib.load(datadir[i])
---> 12     img_data = img.get_fdata()
     13     img_arr.append(img_data)
     14     img.uncache()

~\AppData\Roaming\Python\Python36\site-packages\nibabel\dataobj_images.py in get_fdata(self, caching, dtype)
    346             if self._fdata_cache.dtype.type == dtype.type:
    347                 return self._fdata_cache
--> 348         data = np.asanyarray(self._dataobj).astype(dtype, copy=False)
    349         if caching == 'fill':
    350             self._fdata_cache = data

~\AppData\Roaming\Python\Python36\site-packages\numpy\core\_asarray.py in asanyarray(a, dtype, order)
    136 
    137     """
--> 138     return array(a, dtype, copy=False, order=order, subok=True)
    139 
    140 

~\AppData\Roaming\Python\Python36\site-packages\nibabel\arrayproxy.py in __array__(self)
    353     def __array__(self):
    354         # Read array and scale
--> 355         raw_data = self.get_unscaled()
    356         return apply_read_scaling(raw_data, self._slope, self._inter)
    357 

~\AppData\Roaming\Python\Python36\site-packages\nibabel\arrayproxy.py in get_unscaled(self)
    348                                        offset=self._offset,
    349                                        order=self.order,
--> 350                                        mmap=self._mmap)
    351         return raw_data
    352 

~\AppData\Roaming\Python\Python36\site-packages\nibabel\volumeutils.py in array_from_file(shape, in_dtype, infile, offset, order, mmap)
    507                              shape=shape,
    508                              order=order,
--> 509                              offset=offset)
    510             # The error raised by memmap, for different file types, has
    511             # changed in different incarnations of the numpy routine

~\AppData\Roaming\Python\Python36\site-packages\numpy\core\memmap.py in __new__(subtype, filename, dtype, mode, offset, shape, order)
    262             bytes -= start
    263             array_offset = offset - start
--> 264             mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=start)
    265 
    266             self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm,

OSError: [WinError 8] Not enough storage is available to process this command

我认为 img.uncache() 会从内存中删除图像,这样它就不会占用太多存储空间,但仍然可以使用图像数组。将这一位添加到代码中并没有改变任何东西。

有谁知道我能帮上忙吗?我正在使用的计算机有 24 核 2.6 GHz CPU,超过 52 GB 内存,工作目录有超过 1.7 TB 的可用存储空间。我正在尝试从 ADNI 数据库加载大约 1500 张 MRI 图像。

非常感谢任何建议。

【问题讨论】:

  • 你真的需要同时在内存中的所有 1500 张图像吗?你打算用它们做什么?

标签: python memory neuroscience


【解决方案1】:

这个错误不是因为1.7TB 硬盘被填满,而是因为你的内存用完了,也就是内存。 It's going to be important to understand how those two things differ。

uncache() 确实不会从内存中完全删除一个项目,正如 here 所记录的那样,但该链接还包含更多内存节省提示。

如果你想完全从内存中删除一个对象,你可以使用Garbage Collector interface,像这样:

import nibabel as nib 
import gc

img_arr = []
for i in range(len(datadir)):
    img = nib.load(datadir[i])
    img_data = img.get_fdata()
    img_arr.append(img_data)
    img.uncache()
    # Delete the img object and free the memory
    del img
    gc.collect()

这应该有助于减少您使用的内存量。

【讨论】:

    【解决方案2】:

    如何解决“没有足够的可用存储空间..”?

    • 尝试执行以下步骤:

      1. 同时按下键盘上的 Windows + R 键,然后在“运行”窗口中键入 Regedit.exe 并单击“确定”。

      2. 然后展开 HKEY_LOCAL_MACHINE、SYSTEM、CurrentControlSet、services、LanmanServer、Parameters。

      3. 找到 IRPStackSize(如果找到请跳至步骤 5),如果不存在则右键单击右侧窗口并选择新建 > Dword 值 (32)

      4. 现在在名称下输入 IRPStackSize,然后回车。

      5. 右键单击 IRPStackSize 并单击 Modify,然后设置任何高于 15 但低于 50 的值并单击 OK

      6. 重新启动系统并尝试重复发生错误时所做的相同操作。

    • 或者:

      1. 将以下注册表项 HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\LargeSystemCache 设置为值“1”

      2. 设置以下注册表 HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\Size 为值“3”

    另一种在“nibabel”中节省内存的方法:

    除了 uncache() 方法还有其他节省内存的方法,您可以使用:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-28
      • 1970-01-01
      • 1970-01-01
      • 2014-01-04
      • 1970-01-01
      • 2023-03-17
      相关资源
      最近更新 更多