ValueError:2000x100000 像素的图像尺寸太大。每个方向都必须小于 2^16

问题描述 投票:0回答:1

我正在尝试绘制数据集的 5000 张图像(猫和狗的图片)以进行图像分类。我正在使用 google colab,甚至当我尝试使用 pycharm 时,它也显示相同的错误。我正在使用 import matplotlib.pyplot 作为我的代码的 plt 。所有图像的尺寸均为 512x512

#Calculate the number of rows and columns for subplots. Plot the images
num_images = len(df_BW)
num_rows = (num_images - 1) // 10 + 1
num_cols = min(num_images, 10)

fig, axes = plt.subplots(num_rows, 10, figsize=(20, num_rows * 2))
for idx, (img, label) in enumerate(zip(df_BW['image'], df_BW['label'])):
    ax = axes[idx // 10, idx % 10]
    ax.imshow(img, cmap = 'gray')
    ax.axis('off')
    ax.set_title(label)

#Hide empty subplots
for i in range(num_images, num_rows * 10):
    axes.flatten()[i].axis('off')

plt.tight_layout()
plt.show()

使用 100 个图像(我测试过的最高图像),代码可以正常工作,但是当我尝试使用 5000 个图像时,它会显示“ValueError:2000x100000 像素的图像尺寸太大。每个方向都必须小于 2^16。”

python matplotlib pycharm google-colaboratory valueerror
1个回答
0
投票

脚本中运行的

10
正在对列数进行硬编码。 如果您将其更改为
20
,那么您将制作一个 4000 x 50000 的图像,而不是 2000 x 100000,这两者都在 2^16 限制内。

顺便说一句,这表明您的图像实际上是 200 x 200 像素,而不是 512x512?

(顺便说一句,

num_cols
已定义但未使用;您可以将其删除。)

© www.soinside.com 2019 - 2024. All rights reserved.