水平,竖直翻转 self.transHVflip = iaa.Sequential([ iaa.SomeOf((0, 2), [ iaa.Fliplr(0.5),…
- User
水平,竖直翻转
self.transHVflip = iaa.Sequential([ iaa.SomeOf((0, 2), [ iaa.Fliplr(0.5), iaa.Flipud(0.5), ]) ]) # 随机仿射变换 self.transAffine = iaa.Sequential([ iaa.Affine( translate_percent={'x': (-0.0625, 0.0625), 'y': (-0.0625, 0.0625)}, scale={'x': (0.9, 1.1), 'y': (0.9, 1.1)}, rotate=(-45, 45), mode='reflect' ) ]) # 随机弹性变换 self.transElastic = iaa.Sequential([ iaa.ElasticTransformation(alpha=1.0, sigma=0.25) ]) # 随机直方图均衡 self.transCLAHE = iaa.Sequential([ iaa.CLAHE(clip_limit=(1,4), tile_grid_size_px=(8,8)) ]) # 随机中心模糊 self.transMedBlur = iaa.Sequential([ iaa.MedianBlur(k=(3, 7)) ]) # 随机gamma噪声 self.transGamma = iaa.Sequential([ iaa.GammaContrast((0.7, 1.5)), iaa.AdditiveGaussianNoise(loc=0, scale=(20,50)) ], random_order=True)这是我写的 数据增强的函数, 我现在有baseline和二值化的mask, 为什么二值化的mask在和baseline做transHVflip的时候会报错/home/amax/anaconda3/lib/python3.11/site-packages/imgaug/augmenters/meta.py:3368: FutureWarning: In the future
np.boolwill be defined as the corresponding NumPy scalar. augmenter_active = np.zeros((nb_rows, len(self)), dtype=np.bool) Traceback (most recent call last): File "/home/amax/anaconda3/lib/python3.11/site-packages/imgaug/augmenters/meta.py", line 641, in augment_batch_ batch_inaug = self.augment_batch( ^^^^^^^^^^^^^^^^^^^^^ File "/home/amax/anaconda3/lib/python3.11/site-packages/imgaug/augmenters/meta.py", line 3124, in augment_batch batch = self[index].augment_batch_( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/amax/anaconda3/lib/python3.11/site-packages/imgaug/augmenters/meta.py", line 641, in augment_batch_ batch_inaug = self.augment_batch( ^^^^^^^^^^^^^^^^^^^^^ File "/home/amax/anaconda3/lib/python3.11/site-packages/imgaug/augmenters/meta.py", line 3395, in augment_batch augmenter_active = self._get_augmenter_active(batch.nb_rows, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/amax/anaconda3/lib/python3.11/site-packages/imgaug/augmenters/meta.py", line 3368, in get_augmenter_active augmenter_active = np.zeros((nb_rows, len(self)), dtype=np.bool) ^^^^^^^ File "/home/amax/anaconda3/lib/python3.11/site-packages/numpy/init.py", line 324, in getattr raise AttributeError(former_attrs[attr]) AttributeError: module 'numpy' has no attribute 'bool'.np.boolwas a deprecated alias for the builtinbool. To avoid this error in existing code, useboolby itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, usenp.bool_here. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations. Did you mean: 'bool'? python-BaseException - Assistant
根据您提供的错误信息,问题的根本原因是
numpy库中不再支持np.bool,这一别名在numpy1.20 中被弃用,现在您应该使用bool或np.bool_。在您报告的错误中,涉及到的代码是
imgaug库中的meta.py,这说明imgaug中的某些代码仍然在使用过时的np.bool。这个问题需要通过更新imgaug库 或者手动修改其源码来解决。不过在imgaug中查找并修改源码并不是推荐的方法,因此我们建议您以下几种应对策略:-
更新库:检查
imgaug是否有更新版本,如果有,请更新到最新版,看看是否已经修复了这个问题。pip install --upgrade imgaug -
降级 NumPy:如果更新
imgaug无法解决问题,作为权宜之计,可以尝试降级numpy到 1.19.x 版本,因为在这个版本中np.bool仍然是可用的。请注意,这可能会导致其他库出现问题。pip install numpy==1.19.5 -
联系 imgaug 开发者:如果这些方法都无效,可以考虑联系
imgaug的维护者或在其 GitHub 仓库中提交问题,以提醒他们该兼容性问题。
暂时通过降级
numpy可以绕过这个问题,但是从长远来看,最好的解决方式还是依赖库的更新以兼容新的numpy版本。这样做可以保持代码和环境的现代化,同时减少放弃使用过时和不再受支持的功能所带来的安全和稳定性风险。 -