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,23 +82,27 @@ class Augmentor(object): ...@@ -81,23 +82,27 @@ 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})"
""" """
argspec = inspect.getargspec(self.__init__) try:
assert argspec.varargs is None, "The default __repr__ doesn't work for vaargs!" argspec = inspect.getargspec(self.__init__)
assert argspec.keywords is None, "The default __repr__ doesn't work for kwargs!" assert argspec.varargs is None, "The default __repr__ doesn't work for vaargs!"
fields = argspec.args[1:] assert argspec.keywords is None, "The default __repr__ doesn't work for kwargs!"
index_field_has_default = len(fields) - (0 if argspec.defaults is None else len(argspec.defaults)) fields = argspec.args[1:]
index_field_has_default = len(fields) - (0 if argspec.defaults is None else len(argspec.defaults))
classname = type(self).__name__
argstr = [] classname = type(self).__name__
for idx, f in enumerate(fields): argstr = []
assert hasattr(self, f), \ for idx, f in enumerate(fields):
"Attribute {} not found! The default __repr__ only works if attributes match the constructor.".format(f) assert hasattr(self, f), \
attr = getattr(self, f) "Attribute {} not found! Default __repr__ only works if attributes match the constructor.".format(f)
if idx >= index_field_has_default: attr = getattr(self, f)
if attr is argspec.defaults[idx - index_field_has_default]: if idx >= index_field_has_default:
continue if attr is argspec.defaults[idx - index_field_has_default]:
argstr.append("{}={}".format(f, pprint.pformat(attr))) continue
return "imgaug.{}({})".format(classname, ', '.join(argstr)) argstr.append("{}={}".format(f, pprint.pformat(attr)))
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