logo
Loading...

Day16 第二Part : 執行程式 images_aug = seq.augment_images(img_combine) 產生 [ValueError] - Cupoy

import numpy as npimport imgaug as iaimport imgaug...

cvdl,cvdl-d16

Day16 第二Part : 執行程式 images_aug = seq.augment_images(img_combine) 產生 [ValueError]

2020/07/01 03:09 PM
電腦視覺深度學習論壇
Andy
觀看數:0
回答數:2
收藏數:0
cvdl
cvdl-d16

import numpy as np

import imgaug as ia

import imgaug.augmenters as iaa

import matplotlib.pyplot as plt

%matplotlib inline


##輸入照片

img = cv2.imread('Tano.JPG')  

img = cv2.resize(img, (224,224))##改變圖片尺寸

img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) #Cv2讀進來是BGR,轉成RGB

img_origin=img.copy()

img= np.array(img, dtype=np.float32)


img_combine=np.array([img,img,img,img],dtype=np.float32) 


sometimes = lambda aug: iaa.Sometimes(0.5, aug) # Sometimes(0.5, ...) 代表每次都有50%的機率運用不同的Augmentation


##包裝想運用之圖像強化方式

seq = iaa.Sequential([

    iaa.Crop(px=(0, 16)),

    iaa.Fliplr(0.4), 

   sometimes(iaa.CropAndPad(

        percent=(-0.05, 0.1),

        pad_mode=ia.ALL,

        pad_cval=(0, 255)

    )),

    sometimes(iaa.Affine(

        scale={"x": (0.8, 1.2), "y": (0.8, 1.2)}, 

        translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)}, 

        rotate=(-10, 10),

        shear=(-8, 8), 

        order=[0, 1], 

        cval=(0, 255),

        mode=ia.ALL 

    )),

    sometimes(iaa.Superpixels(p_replace=(0, 1.0), n_segments=(20, 200))), # convert images into their superpixel representation

    sometimes(iaa.OneOf([

    iaa.GaussianBlur((0, 3.0)), # blur images 

                    iaa.AverageBlur(k=(1,3)), # blur image using local means with kernel sizes between 1 and 3

                    iaa.MedianBlur(k=(3, 5)), # blur image using local medians with kernel sizes between 3 and 5

                ])),

     sometimes(iaa.Sharpen(alpha=(0, 0.2), lightness=(0.1, 0.4))), # sharpen images

     sometimes(iaa.Emboss(alpha=(0, 0.3), strength=(0, 0.5))), # emboss images

    ],random_order=True)




images_aug = seq.augment_images(img_combine) ## Image Augmentation


##畫出來

i=1

plt.figure(figsize=(20,20))

for image in images_aug:

    plt.subplot(1, 5, 1)

    plt.imshow(img_origin.astype(np.uint8))

    plt.subplot(1, 5, i+1)

    plt.imshow(image.astype(np.uint8))

    plt.axis('off')

    i+=1

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-46d926da1dee> in <module>
    46
    47
---> 48 images_aug = seq.augment_images(img_combine) ## Image Augmentation
    49
    50 ##畫出來

D:\Anaconda3\lib\site-packages\imgaug\augmenters\meta.py in augment_images(self, images, parents, hooks)
   823             UnnormalizedBatch(images=images),
   824             parents=parents,
--> 825             hooks=hooks
   826         ).images_aug
   827

D:\Anaconda3\lib\site-packages\imgaug\augmenters\meta.py in augment_batch_(self, batch, parents, hooks)
   643                     random_state=self.random_state,
   644                     parents=parents if parents is not None else [],
--> 645                     hooks=hooks)
   646
   647         # revert augmentables being set to None for non-activated augmenters

D:\Anaconda3\lib\site-packages\imgaug\augmenters\meta.py in _augment_batch_(self, batch, random_state, parents, hooks)
  3125                     batch,
  3126                     parents=parents + [self],
-> 3127                     hooks=hooks
  3128                 )
  3129         return batch

D:\Anaconda3\lib\site-packages\imgaug\augmenters\meta.py in augment_batch_(self, batch, parents, hooks)
   643                     random_state=self.random_state,
   644                     parents=parents if parents is not None else [],
--> 645                     hooks=hooks)
   646
   647         # revert augmentables being set to None for non-activated augmenters

D:\Anaconda3\lib\site-packages\imgaug\augmenters\meta.py in _augment_batch_(self, batch, random_state, parents, hooks)
  3634                         batch_sub,
  3635                         parents=parents + [self],
-> 3636                         hooks=hooks
  3637                     )
  3638                     batch = batch.invert_subselect_rows_by_indices_(indices,

D:\Anaconda3\lib\site-packages\imgaug\augmenters\meta.py in augment_batch_(self, batch, parents, hooks)
   643                     random_state=self.random_state,
   644                     parents=parents if parents is not None else [],
--> 645                     hooks=hooks)
   646
   647         # revert augmentables being set to None for non-activated augmenters

D:\Anaconda3\lib\site-packages\imgaug\augmenters\meta.py in _augment_batch_(self, batch, random_state, parents, hooks)
  3125                     batch,
  3126                     parents=parents + [self],
-> 3127                     hooks=hooks
  3128                 )
  3129         return batch

D:\Anaconda3\lib\site-packages\imgaug\augmenters\meta.py in augment_batch_(self, batch, parents, hooks)
   643                     random_state=self.random_state,
   644                     parents=parents if parents is not None else [],
--> 645                     hooks=hooks)
   646
   647         # revert augmentables being set to None for non-activated augmenters

D:\Anaconda3\lib\site-packages\imgaug\augmenters\segmentation.py in _augment_batch_(self, batch, random_state, parents, hooks)
   237                                      "float16", "float32", "float64",
   238                                      "float96", "float128", "float256"],
--> 239                          augmenter=self)
   240
   241         nb_images = len(images)

D:\Anaconda3\lib\site-packages\imgaug\dtypes.py in gate_dtypes(dtypes, allowed, disallowed, augmenter)
   330                     augmenter.name,
   331                     augmenter.__class__.__name__,
--> 332                     ", ".join(disallowed)
   333                 ))
   334         else:

ValueError: Got dtype 'float32' in augmenter 'UnnamedSuperpixels' (class 'Superpixels'), which is a forbidden dtype (uint128, uint256, int128, int256, float16, float32, float64, float96, float128, float256).