向单张图像添加AdditiveGaussianNoise – AssertionError: Expected boolean as argument for ‘return_batch’

我想向一张之前调整过大小的图像添加AdditiveGaussianNoise(链接:https://imgaug.readthedocs.io/en/latest/source/overview/arithmetic.html#additivegaussiannoise)。

这是我的代码:

from skimage.io import imreadfrom skimage.transform import resizeimport imgaug.augmenters as iaafile_name = "path/to/image.jpg"resized_img = resize(imread(file_name), (224, 224))aug = iaa.AdditiveGaussianNoise(scale=(0, 0.2*255))augmented_image = aug(resized_img)

我得到了这个错误信息:

---------------------------------------------------------------------------AssertionError                            Traceback (most recent call last)<ipython-input-20-e4a0b17d4ac4> in <module>()----> 1 augmented_image =aug(resized_img)1 frames/usr/local/lib/python3.6/dist-packages/imgaug/augmenters/meta.py in augment(self, return_batch, hooks, **kwargs)   1782             ("Expected boolean as argument for 'return_batch', got type %s. "   1783              + "Call augment() only with named arguments, e.g. "-> 1784              + "augment(images=<array>).") % (str(type(return_batch)),)   1785         )   1786 AssertionError: Expected boolean as argument for 'return_batch', got type <class 'numpy.ndarray'>. Call augment() only with named arguments, e.g. augment(images=<array>).

我需要如何修改我的代码?

非常感谢!


回答:

这是使用随机图像的解决方案…您需要指定images参数

import numpy as npimport imgaug.augmenters as iaaimg = np.random.randint(0,256, (1,224,224,3)).astype('float32')aug = iaa.AdditiveGaussianNoise(scale=(0, 0.2*255))augmented_image = aug(images=img)

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注