Skip to content

Commit

Permalink
Data description/repr shorter
Browse files Browse the repository at this point in the history
  • Loading branch information
albertz committed Sep 11, 2021
1 parent 44637ed commit 123c9f7
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions returnn/tf/util/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1583,8 +1583,6 @@ def get_description(self, with_name=True, with_placeholder=False, catch_exceptio
else:
if self.dtype != "float32":
keys.append("dtype")
if with_name:
keys.insert(0, "name")
if with_placeholder:
keys.append("placeholder")
if not self.available_for_inference:
Expand All @@ -1595,6 +1593,17 @@ def get_description(self, with_name=True, with_placeholder=False, catch_exceptio
if not self.batch or self.batch.beam != self.beam:
keys.append("beam")
args = []
if with_name:
name = getattr(self, "name", None)
args += [repr(name) if name else "<undefined>"]
try:
batch_shape_meta = "[%s]" % ",".join(self.get_batch_axes_short_description())
except Exception as exc:
if catch_exceptions:
batch_shape_meta = "<!%s: %s>" % (type(exc).__name__, exc)
else:
raise
args += [batch_shape_meta]
for key in keys:
try:
value_repr = repr(getattr(self, key))
Expand All @@ -1604,15 +1613,16 @@ def get_description(self, with_name=True, with_placeholder=False, catch_exceptio
else:
raise
args += ["%s=%s" % (key, value_repr)]
try:
batch_shape_meta = "[%s]" % ",".join(self.get_batch_axes_short_description())
except Exception as exc:
if catch_exceptions:
batch_shape_meta = "<!%s: %s>" % (type(exc).__name__, exc)
else:
raise
args += ["batch_shape_meta=" + batch_shape_meta]
return "Data(%s)" % ", ".join(args)
if self.control_flow_ctx:
try:
value_repr = self.control_flow_ctx.repr_inner()
except Exception as exc:
if catch_exceptions:
value_repr = "<!%s: %s>" % (type(exc).__name__, exc)
else:
raise
args += ["ctx=" + value_repr]
return "Data{%s}" % ", ".join(args)

def get_batch_axes_short_description(self, special_axes=True):
"""
Expand Down

0 comments on commit 123c9f7

Please sign in to comment.