aleju / imgaug

Image augmentation for machine learning experiments.
http://imgaug.readthedocs.io
MIT License
14.42k stars 2.44k forks source link

draw_masks generates numbers bigger than 1 #777

Open alumgit opened 3 years ago

alumgit commented 3 years ago

Hey, i have created a sequential model for augmenting my images when i run it i get this error sometimes(i removed my code from the traceback since i think its to relevant here):

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
...
...
...
~/miniconda3/envs/btd/lib/python3.9/site-packages/imgaug/augmenters/meta.py in __call__(self, *args, **kwargs)
   2025     def __call__(self, *args, **kwargs):
   2026         """Alias for :func:`~imgaug.augmenters.meta.Augmenter.augment`."""
-> 2027         return self.augment(*args, **kwargs)
   2028 
   2029     def pool(self, processes=None, maxtasksperchild=None, seed=None):

~/miniconda3/envs/btd/lib/python3.9/site-packages/imgaug/augmenters/meta.py in augment(self, return_batch, hooks, **kwargs)
   1996         )
   1997 
-> 1998         batch_aug = self.augment_batch_(batch, hooks=hooks)
   1999 
   2000         # return either batch or tuple of augmentables, depending on what

~/miniconda3/envs/btd/lib/python3.9/site-packages/imgaug/augmenters/meta.py in augment_batch_(self, batch, parents, hooks)
    641                 pf_enabled = not self.deterministic
    642                 with iap.toggled_prefetching(pf_enabled):
--> 643                     batch_inaug = self._augment_batch_(
    644                         batch_inaug,
    645                         random_state=self.random_state,

~/miniconda3/envs/btd/lib/python3.9/site-packages/imgaug/augmenters/meta.py in _augment_batch_(self, batch, random_state, parents, hooks)
   3141 
   3142             for index in order:
-> 3143                 batch = self[index].augment_batch_(
   3144                     batch,
   3145                     parents=parents + [self],

~/miniconda3/envs/btd/lib/python3.9/site-packages/imgaug/augmenters/meta.py in augment_batch_(self, batch, parents, hooks)
    641                 pf_enabled = not self.deterministic
    642                 with iap.toggled_prefetching(pf_enabled):
--> 643                     batch_inaug = self._augment_batch_(
    644                         batch_inaug,
    645                         random_state=self.random_state,

~/miniconda3/envs/btd/lib/python3.9/site-packages/imgaug/augmenters/meta.py in _augment_batch_(self, batch, random_state, parents, hooks)
   3650                 if augmenters is not None and len(augmenters) > 0:
   3651                     batch_sub = batch.subselect_rows_by_indices(indices)
-> 3652                     batch_sub = augmenters.augment_batch_(
   3653                         batch_sub,
   3654                         parents=parents + [self],

~/miniconda3/envs/btd/lib/python3.9/site-packages/imgaug/augmenters/meta.py in augment_batch_(self, batch, parents, hooks)
    641                 pf_enabled = not self.deterministic
    642                 with iap.toggled_prefetching(pf_enabled):
--> 643                     batch_inaug = self._augment_batch_(
    644                         batch_inaug,
    645                         random_state=self.random_state,

~/miniconda3/envs/btd/lib/python3.9/site-packages/imgaug/augmenters/meta.py in _augment_batch_(self, batch, random_state, parents, hooks)
   3420                 if len(active) > 0:
   3421                     batch_sub = batch.subselect_rows_by_indices(active)
-> 3422                     batch_sub = self[augmenter_index].augment_batch_(
   3423                         batch_sub,
   3424                         parents=parents + [self],

~/miniconda3/envs/btd/lib/python3.9/site-packages/imgaug/augmenters/meta.py in augment_batch_(self, batch, parents, hooks)
    641                 pf_enabled = not self.deterministic
    642                 with iap.toggled_prefetching(pf_enabled):
--> 643                     batch_inaug = self._augment_batch_(
    644                         batch_inaug,
    645                         random_state=self.random_state,

~/miniconda3/envs/btd/lib/python3.9/site-packages/imgaug/augmenters/blend.py in _augment_batch_(self, batch, random_state, parents, hooks)
    847             self, batch, hooks, parents)
    848 
--> 849         masks = self.mask_generator.draw_masks(batch, random_state)
    850 
    851         for i, mask in enumerate(masks):

~/miniconda3/envs/btd/lib/python3.9/site-packages/imgaug/augmenters/blend.py in draw_masks(self, batch, random_state)
   2615                                                     random_state=random_state)
   2616 
-> 2617         return [self._draw_mask(shape, random_state, per_channel_i)
   2618                 for shape, per_channel_i
   2619                 in zip(shapes, per_channel)]

~/miniconda3/envs/btd/lib/python3.9/site-packages/imgaug/augmenters/blend.py in <listcomp>(.0)
   2615                                                     random_state=random_state)
   2616 
-> 2617         return [self._draw_mask(shape, random_state, per_channel_i)
   2618                 for shape, per_channel_i
   2619                 in zip(shapes, per_channel)]

~/miniconda3/envs/btd/lib/python3.9/site-packages/imgaug/augmenters/blend.py in _draw_mask(self, shape, random_state, per_channel)
   2640             if mask.item(0) > 1:
   2641                 print(mask.item(0))
-> 2642             assert 0 <= mask.item(0) <= 1.0, (
   2643                 "Expected 'parameter' samples to be in the interval "
   2644                 "[0.0, 1.0]. Got min %.4f and max %.4f." % (

AssertionError: Expected 'parameter' samples to be in the interval [0.0, 1.0]. Got min 0.0173 and max 1.0000.

After some debugging, it seems that the max number is about 1.0000000001. this is generated by the draw_masks function which just generates it randomly using a RNG object. if i run this in a while true, after a while, randomly, it will throw this exception. i have also tried to run the draw_samples functions (which is used in blend.py:2635) which runs before the assertion to generate the masks and it also generates sometimes a number above 1 (slightly) every 10,000 iterations.