| 27 | |
| 28 | |
| 29 | class ExceptionHandler: |
| 30 | def __init__(self, catch_exceptions=False): |
| 31 | self._nr_error = 0 |
| 32 | self.catch_exceptions = catch_exceptions |
| 33 | |
| 34 | @contextmanager |
| 35 | def catch(self): |
| 36 | try: |
| 37 | yield |
| 38 | except Exception: |
| 39 | self._nr_error += 1 |
| 40 | if not self.catch_exceptions: |
| 41 | raise |
| 42 | else: |
| 43 | if self._nr_error % 100 == 0 or self._nr_error < 10: |
| 44 | logger.exception("Got {} augmentation errors.".format(self._nr_error)) |
| 45 | |
| 46 | |
| 47 | class ImageFromFile(RNGDataFlow): |