Skip to content

Commit

Permalink
fix error message when running toco from python3.
Browse files Browse the repository at this point in the history
Otherwize it's still bytes, so the exception reports the entire console output on a single line, making it unreadable.

PiperOrigin-RevId: 217813440
  • Loading branch information
MarkDaoust authored and tensorflower-gardener committed Oct 19, 2018
1 parent ca8cab3 commit 6044558
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tensorflow/contrib/lite/python/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@
if _toco_from_proto_bin and not _os.path.exists(_toco_from_proto_bin):
_toco_from_proto_bin = "toco_from_protos"

def _try_convert_to_unicode(output):
if output is None:
return u""

if isinstance(output, bytes):
try:
return output.decode()
except UnicodeDecodeError:
pass
return output

class ConverterMode(enum.Enum):
"""Enum class defining the converters available to generate TFLite models.
Expand Down Expand Up @@ -145,6 +155,8 @@ def toco_convert_protos(model_flags_str, toco_flags_str, input_data_str):
with open(output_filename, "rb") as fp:
return fp.read()
else:
stdout = _try_convert_to_unicode(stdout)
stderr = _try_convert_to_unicode(stderr)
raise RuntimeError(
"TOCO failed see console for info.\n%s\n%s\n" % (stdout, stderr))
finally:
Expand Down

0 comments on commit 6044558

Please sign in to comment.