简体   繁体   English

MemoryError:无法为形状为 (15500, 2, 240, 240, 1) 且数据类型为 int16 的数组分配 3.33 GiB

[英]MemoryError: Unable to allocate 3.33 GiB for an array with shape (15500, 2, 240, 240, 1) and data type int16

To run the code I'm using PyCharm latest version on a Windows 7 64bit with 16Gb of RAM and...要运行代码,我在 Windows 7 64bit 上使用 PyCharm 最新版本,具有 16Gb 的 RAM 和...

Python version: 3.7.7 (default, May  6 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)]

I'm trying to load a lot of NIFTI images using SimplyITK and Numpy from the BraTS 2019 dataset .我正在尝试使用来自BraTS 2019 数据集的 SimplyITK 和 Numpy 加载大量 NIFTI 图像。

This is the code I use to load the images into a numpy array.这是我用来将图像加载到 numpy 数组中的代码。

import SimpleITK as sitk


def read_nifti_images(images_full_path):
    """ 
    Read nifti files from a gziped file.
  
    Read nifti files from a gziped file using SimpleITK library.
  
    Parameters: 
    images_full_path (string): Full path to gziped file including file name.
  
    Returns: 
    SimpleITK.SimpleITK.Image, numpy array: images read as image, images read as numpy array 
  
    """
    # Reads images using SimpleITK.
    images = sitk.ReadImage(images_full_path)
    # Get a numpy array from a SimpleITK Image.
    images_array = sitk.GetArrayFromImage(images)
    
    # More info about SimpleITK images: http://simpleitk.github.io/SimpleITK-Notebooks/01_Image_Basics.html
    
    return images, images_array

This code works fine with smallest dataset.此代码适用于最小的数据集。 I'm trying to load 518 nii.gz files with 155 images each file.我正在尝试加载 518 个 nii.gz 文件,每个文件包含 155 个图像。

When I run the code, there are 4GiB of RAM used, and when it gets to 8GiB, it throws the exception.当我运行代码时,使用了 4GiB 的 RAM,当它达到 8GiB 时,它会抛出异常。

Is there any way to load all the images in memory?有没有办法加载 memory 中的所有图像? Maybe there is a memory usage limitation in Windows and/or in PyCharm.在 Windows 和/或 PyCharm 中可能存在 memory 使用限制。

You have two copies of images in memory, a SimpleITK version and a numpy version.您在 memory 中有两个图像副本,一个 SimpleITK 版本和一个 numpy 版本。 So when you hit 8 gig of images, you've really got 16 gig in memory, hence your crash.因此,当您点击 8 gig 的图像时,您在 memory 中确实有 16 gig,因此您的崩溃。

You can try using sitk.GetArrayViewFromImage.您可以尝试使用 sitk.GetArrayViewFromImage。 That does not make a whole new copy of the image when converting from SimpleITK to numpy.当从 SimpleITK 转换为 numpy 时,这不会生成图像的全新副本。 It creates a numpy data structure that points to the same pixel buffer as the SimpleITK image.它创建了一个 numpy 数据结构,该结构指向与 SimpleITK 图像相同的像素缓冲区。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MemoryError:无法为形状为 (5844379795,) 且数据类型为 int64 的数组分配 43.5 GiB - MemoryError: Unable to allocate 43.5 GiB for an array with shape (5844379795,) and data type int64 MemoryError: Unable to allocate 115. GiB for an array with shape (1122, 1122, 12288) and data type float64 - MemoryError: Unable to allocate 115. GiB for an array with shape (1122, 1122, 12288) and data type float64 MemoryError: 无法为形状 (2549150, 99) 和数据类型对象的数组分配 1.88 GiB - MemoryError: Unable to allocate 1.88 GiB for an array with shape (2549150, 99) and data type object MemoryError:无法为形状为 (323313, 3435) 且数据类型为 float64 的数组分配 8.27 GiB - MemoryError: Unable to allocate 8.27 GiB for an array with shape (323313, 3435) and data type float64 MemoryError: Unable to allocate 617. GiB for an array with shape (82754714206,) and data type float64 On Windows and using Python - MemoryError: Unable to allocate 617. GiB for an array with shape (82754714206,) and data type float64 On Windows and using Python MemoryError: Unable to allocate 5.62 GiB for an array with shape (16384, 30720, 3) and data type float32 when training StyleGan2 - MemoryError: Unable to allocate 5.62 GiB for an array with shape (16384, 30720, 3) and data type float32 When training StyleGan2 无法为形状为 (129213603, 28) 且数据类型为 int8 的数组分配 3.37 GiB - Unable to allocate 3.37 GiB for an array with shape (129213603, 28) and data type int8 Pandas 无法为形状 X 和数据类型 Y 的数组分配 GiB - Pandas unable to allocate GiB for an array with shape X and data type Y Python MemoryError:无法为形状为 () 且数据类型为 int64 的数组分配 10.8 TiB - Python MemoryError: Unable to allocate 10.8 TiB for an array with shape () and data type int64 MemoryError:无法为形状为 (5004, 96) 且数据类型为 int32 的数组分配 1.83 MiB - MemoryError: Unable to allocate 1.83 MiB for an array with shape (5004, 96) and data type int32
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM