Commit 8e5a46a4 authored by Yuxin Wu's avatar Yuxin Wu

don't throw when repr(imgaug) fails

parent 26d792d4
...@@ -9,6 +9,7 @@ import six ...@@ -9,6 +9,7 @@ import six
from six.moves import zip from six.moves import zip
from ...utils.utils import get_rng from ...utils.utils import get_rng
from ...utils.argtools import log_once
from ..image import check_dtype from ..image import check_dtype
__all__ = ['Augmentor', 'ImageAugmentor', 'AugmentorList'] __all__ = ['Augmentor', 'ImageAugmentor', 'AugmentorList']
...@@ -81,6 +82,7 @@ class Augmentor(object): ...@@ -81,6 +82,7 @@ class Augmentor(object):
Produce something like: Produce something like:
"imgaug.MyAugmentor(field1={self.field1}, field2={self.field2})" "imgaug.MyAugmentor(field1={self.field1}, field2={self.field2})"
""" """
try:
argspec = inspect.getargspec(self.__init__) argspec = inspect.getargspec(self.__init__)
assert argspec.varargs is None, "The default __repr__ doesn't work for vaargs!" assert argspec.varargs is None, "The default __repr__ doesn't work for vaargs!"
assert argspec.keywords is None, "The default __repr__ doesn't work for kwargs!" assert argspec.keywords is None, "The default __repr__ doesn't work for kwargs!"
...@@ -91,13 +93,16 @@ class Augmentor(object): ...@@ -91,13 +93,16 @@ class Augmentor(object):
argstr = [] argstr = []
for idx, f in enumerate(fields): for idx, f in enumerate(fields):
assert hasattr(self, f), \ assert hasattr(self, f), \
"Attribute {} not found! The default __repr__ only works if attributes match the constructor.".format(f) "Attribute {} not found! Default __repr__ only works if attributes match the constructor.".format(f)
attr = getattr(self, f) attr = getattr(self, f)
if idx >= index_field_has_default: if idx >= index_field_has_default:
if attr is argspec.defaults[idx - index_field_has_default]: if attr is argspec.defaults[idx - index_field_has_default]:
continue continue
argstr.append("{}={}".format(f, pprint.pformat(attr))) argstr.append("{}={}".format(f, pprint.pformat(attr)))
return "imgaug.{}({})".format(classname, ', '.join(argstr)) return "imgaug.{}({})".format(classname, ', '.join(argstr))
except AssertionError as e:
log_once(e.args[0], 'warn')
return super(Augmentor, self).__repr__()
__str__ = __repr__ __str__ = __repr__
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# File: parallel_map.py # File: parallel_map.py
import numpy as np import numpy as np
import time
import ctypes import ctypes
import copy import copy
import threading import threading
...@@ -271,6 +272,7 @@ class MultiProcessMapDataZMQ(_ParallelMapData, _MultiProcessZMQDataFlow): ...@@ -271,6 +272,7 @@ class MultiProcessMapDataZMQ(_ParallelMapData, _MultiProcessZMQDataFlow):
self._iter_worker = _repeat_iter(lambda: iter(self._proc_ids)) self._iter_worker = _repeat_iter(lambda: iter(self._proc_ids))
self._start_processes() self._start_processes()
time.sleep(5) # TODO temporarily work around #673
self._fill_buffer() # pre-fill the bufer self._fill_buffer() # pre-fill the bufer
def reset_state(self): def reset_state(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment