首页 > 解决方案 > Python返回'UFuncTypeError:ufunc'add'不包含循环..'

问题描述

我正在研究图像深度学习。运行此代码时出现此错误:

from PIL import Image

using_image_num = 10000
batch_num = 2 

for category in classes:
    for j in range(using_image_num):
        img = category[j,:j+784].reshape(1,28,28,1)
        batch = 0
        flow = datagen.flow(img, batch_size = 1, save_to_dir = saved_location, save_prefix = 'augmented_' + classes[i], save_format='png')
        for augmenting_batch in flow:
            batch += 1
            if batch > batch_num:
                break

    print("augmented " + category + " is saved.")

错误看起来像:

UFuncTypeError                            Traceback (most recent call last)
<ipython-input-42-e9dd2f490a52> in <module>
     15         img = category[j,:j+784].reshape(1,28,28,1)
     16         batch = 0
---> 17         flow = datagen.flow(img, batch_size = 1, save_to_dir = saved_location, save_prefix = 'augmented_' + classes[i], save_format='png')
     18         for augmenting_batch in flow:
     19             batch += 1

UFuncTypeError: ufunc 'add' did not contain a loop with signature matching types (dtype('<U10'), dtype('<U10')) -> dtype('<U10')

当我在 colab 中运行此代码时,它会很好地返回结果。

我不知道为什么这不适用于 Jupyter 笔记本。我在 AWS ec2 服务器上操作了这段代码。一开始,我以为 colab 和 jupyter 的工作方式类似,但结果并非如此。我发现 U10 表示 unicode .... 但我陷入了这个问题而没有任何解决方案..

标签: pythonimage-processingdeep-learninggoogle-colaboratory

解决方案


推荐阅读