【问题标题】:Large Numpy array causses Error when trying to load大型 Numpy 数组在尝试加载时导致错误
【发布时间】:2023-02-06 22:58:52
【问题描述】:

我正在使用图像识别制作人工智能,所以我将播放的每一帧记录到一个 numpy 数组中。当我第一次导出所有图像并获得其中的 6000 张时,它工作得很好。现在,我正在记录更多的数据,但突然间我得到了这个错误,而我的代码或环境没有任何变化

追溯(最近一次通话):

文件“D:\Dev\Fall-Guys-AI-Race\utils\CreateImages.py”,第 6 行,位于 > data = np.load("D:/Dev/Fall-Guys-AI-Race/data/training_data.npy", allow_pickle=True)

文件“D:\Program Files\Python39\lib\site-packages\numpy\lib\npyio.py”,第 430 行,加载中 > 返回格式.read_array(fid, allow_pickle=allow_pickle,

文件“D:\Program Files\Python39\lib\site-packages\numpy\lib\format.py”,第 786 行,在 read_array 中 > array.shape = 形状

ValueError:无法将大小为 2147483648 的数组重塑为形状 (14460,224,224,3)

这是我的 CreateImages.py :

import cv2, os
import numpy as np

listing = os.listdir("D:/Dev/Fall-Guys-AI-Race/data/")
for j in range(1):
    data = np.load("D:/Dev/Fall-Guys-AI-Race/data/training_data.npy", allow_pickle=True)
    targets = np.load("D:/Dev/Fall-Guys-AI-Race/data/target_data.npy", allow_pickle=True)

    print(f'Image Data Shape: {data.shape}')
    print(f'targets Shape: {targets.shape}')

    # Lets see how many of each type of move we have.
    unique_elements, counts = np.unique(targets, return_counts=True)

    # Store both data and targets in a list.
    # We may want to shuffle down the road.

    holder_list = []
    for i, image in enumerate(data):
        holder_list.append([data[i], targets[i]])

    count_up = 0
    count_left = 0
    count_right = 0
    count_jump = 0
    count_down = 0

    for data in holder_list:
        #writes data to image in correct folder, skipped because lots of lines:
        cv2.imwrite(f"*my_path*{count_left}.png", data[0])
    print("done")
    print(count_down, count_up, count_jump, count_left, count_right)


谢谢您的帮助

【问题讨论】:

    标签: python numpy opencv pickle numpy-ndarray


    【解决方案1】:

    您似乎正在尝试加载 numpy 数组,并且新数组比之前加载的数组大。

    错误通知通知您您尝试加载的数组大小无法塑造成适当的形状。

    这可能是因为数据大小已经扩展并且数组无法容纳在内存中,从而导致错误。

    到使固定这个,考虑

    • 将数据保存为更小的部分或将数据拆分为 不同的文件并独立加载它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-18
      • 2013-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多