Open MetaDev opened 5 years ago
That assert is at a point in the augmenter that tries to make sure that your image's height does not reach 0 after cropping. Considering you crop/pad by a percentage value that is a bit odd. Can you make sure that you have no broken images in your dataset? I.e. no images of height/width <= 2, which would cause problems when combining scaling to 50% and cropping 25%. (My guess would be that you might have images with a shape of (0, 0, 3).)
For a bit easier debugging you could try the following:
def func_images(images, random_state, parents, hooks):
print("---------------")
print([type(image) for image in images])
print([image.shape for image in images])
print("---------------")
return images
def func_heatmaps(heatmaps, random_state, parents, hooks):
return heatmaps
def func_keypoints(keypoints_on_images, random_state, parents, hooks):
return keypoints_on_images
debug_print = iaa.Lambda(images=func_images, heatmaps=func_heatmaps, keypoints=func_keypoints)
flip_j = lambda keypoints_on_images, random_state, parents, hooks: flip_symmetric_keypoints(
keypoints_on_images)
noop = lambda images, random_state, parents, hooks: images
seq = iaa.SomeOf(2, [
iaa.Sometimes(0.4, iaa.Scale(iap.Uniform(0.5,1.0))),
iaa.Sometimes(0.6, iaa.Sequential([debug_print, iaa.CropAndPad(percent=(-0.25, 0.25), pad_mode=["edge"], keep_size=False)])),
iaa.Sometimes(0.2, iaa.Sequential([iaa.Fliplr(1), iaa.Lambda(noop, flip_j)])),
iaa.Sometimes(0.4, iaa.AdditiveGaussianNoise(scale=(0, 0.05 * 50))),
iaa.Sometimes(0.1, iaa.GaussianBlur(sigma=(0, 3.0)))
])
seq_det = seq.to_deterministic()
or alternatively you can directly verify the shape before cropping:
flip_j = lambda keypoints_on_images, random_state, parents, hooks: flip_symmetric_keypoints(
keypoints_on_images)
noop = lambda images, random_state, parents, hooks: images
seq = iaa.SomeOf(2, [
iaa.Sometimes(0.4, iaa.Scale(iap.Uniform(0.5,1.0))),
iaa.Sometimes(0.6, iaa.Sequential([iaa.AssertShape((None, (1, None), (1, None), 3)), iaa.CropAndPad(percent=(-0.25, 0.25), pad_mode=["edge"], keep_size=False)])),
iaa.Sometimes(0.2, iaa.Sequential([iaa.Fliplr(1), iaa.Lambda(noop, flip_j)])),
iaa.Sometimes(0.4, iaa.AdditiveGaussianNoise(scale=(0, 0.05 * 50))),
iaa.Sometimes(0.1, iaa.GaussianBlur(sigma=(0, 3.0)))
])
seq_det = seq.to_deterministic()
You can also try to update to the newest version from master. I don't think it will change anything, but there's always a chance.
Thanks for the elaborate help. I was cropping my images based on keypoints before and some had no keypoints. I love the API btw, reminds me of rx, super clean.
even i have the same error im tryimg fig out but im ny geting im working on knn algorithm
def image_to_feature_vector(image, size=(32, 32)):
# resize the image to a fixed size, then flatten the image into
# a list of raw pixel intensities
return cv2.resize(image, size).flatten()
I had the below error with the MTCNN as it was returning a (0,83,3) shaped image:
error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
Solution(replacing x1, y1 with their absolute values): x1, y1, width, height = result['box'] x1 = abs(x1) y1=abs(y1) x2, y2 = x1+width, y1+height face= img[y1:y2,x1:x2,:] print(np.shape(face))
I am trying to figure out why I get this error but I am a little stuck.
the augmentation code:
I think there must be a few images with a resolution for which a combination of the augmentations doesn't work, but I can't figure out a way to find it because I can't print out debug inside the neural network training loop of the library keras.
my output:
Epoch 1/50 788/3150 [======>.......................] - ETA: 13:52 - loss: 0.0609 - 0_conv_1x1_parts_loss: 0.0345 - 1_conv_1x1_parts_loss: 0.0264 - 0_conv_1x1_parts_acc: 0.0766 - 1_conv_1x1_parts_acc: 0.0833Traceback (most recent call last): File "train.py", line 62, in
batch_size=args.batch_size)
File "../net/hourglass.py", line 65, in trainMPII2
epochs=epochs, callbacks=xcallbacks)
File "/media/ssddata/jstaley/miniconda3/envs/py35/lib/python3.5/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "/media/ssddata/jstaley/miniconda3/envs/py35/lib/python3.5/site-packages/keras/engine/training.py", line 2212, in fit_generator
generator_output = next(output_generator)
File "/media/ssddata/jstaley/miniconda3/envs/py35/lib/python3.5/site-packages/keras/utils/data_utils.py", line 779, in get
six.reraise(value.class, value, value.traceback)
File "/media/ssddata/jstaley/miniconda3/envs/py35/lib/python3.5/site-packages/six.py", line 686, in reraise
raise value
File "/media/ssddata/jstaley/miniconda3/envs/py35/lib/python3.5/site-packages/keras/utils/data_utils.py", line 644, in _data_generator_task
generator_output = next(self._generator)
File "../data_gen/mpII_datagen2.py", line 122, in generator
image_aug = seq_det.augment_image(image)
File "/media/ssddata/jstaley/miniconda3/envs/py35/lib/python3.5/site-packages/imgaug/augmenters/meta.py", line 323, in augment_image
return self.augment_images([image], hooks=hooks)[0]
File "/media/ssddata/jstaley/miniconda3/envs/py35/lib/python3.5/site-packages/imgaug/augmenters/meta.py", line 431, in augment_images
hooks=hooks
File "/media/ssddata/jstaley/miniconda3/envs/py35/lib/python3.5/site-packages/imgaug/augmenters/meta.py", line 1762, in _augment_images
hooks=hooks
File "/media/ssddata/jstaley/miniconda3/envs/py35/lib/python3.5/site-packages/imgaug/augmenters/meta.py", line 431, in augment_images
hooks=hooks
File "/media/ssddata/jstaley/miniconda3/envs/py35/lib/python3.5/site-packages/imgaug/augmenters/meta.py", line 1979, in _augment_images
hooks=hooks
File "/media/ssddata/jstaley/miniconda3/envs/py35/lib/python3.5/site-packages/imgaug/augmenters/meta.py", line 431, in augment_images
hooks=hooks
File "/media/ssddata/jstaley/miniconda3/envs/py35/lib/python3.5/site-packages/imgaug/augmenters/meta.py", line 1522, in _augment_images
hooks=hooks
File "/media/ssddata/jstaley/miniconda3/envs/py35/lib/python3.5/site-packages/imgaug/augmenters/meta.py", line 431, in augment_images
hooks=hooks
File "/media/ssddata/jstaley/miniconda3/envs/py35/lib/python3.5/site-packages/imgaug/augmenters/size.py", line 611, in _augment_images
crop_top, crop_right, crop_bottom, crop_left, pad_top, pad_right, pad_bottom, pad_left, pad_mode, pad_cval = self._draw_samples_image(seed, height, width)
File "/media/ssddata/jstaley/miniconda3/envs/py35/lib/python3.5/site-packages/imgaug/augmenters/size.py", line 727, in _draw_samples_image
ia.do_assert(regain_bottom <= crop_bottom)
File "/media/ssddata/jstaley/miniconda3/envs/py35/lib/python3.5/site-packages/imgaug/imgaug.py", line 678, in do_assert
raise AssertionError(str(message))
AssertionError: Assertion failed.