Skip to content

Commit ac395f3

Browse files
authored
Merge pull request #922 from jignparm/jignparm/fix_str_decode
Fix UnicodeDecode error
2 parents 3383ff9 + e0edb23 commit ac395f3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tf2onnx/tf_utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ def tf_to_onnx_tensor(tensor, name=""):
5757
# assume np_data is string, numpy_helper.from_array accepts ndarray,
5858
# in which each item is of str while the whole dtype is of object.
5959
try:
60-
np_data = np_data.astype(np.str).astype(np.object)
61-
except: # pylint: disable=bare-except
60+
if len(np_data.shape) > 0:
61+
np_data = np_data.astype(np.str).astype(np.object)
62+
else:
63+
np_data = np.array(str(np_data)).astype(np.object)
64+
except: # pylint: disable=bare-except
6265
raise RuntimeError("Not support type: {}".format(type(np_data.flat[0])))
6366
return numpy_helper.from_array(np_data, name=name)
6467

0 commit comments

Comments
 (0)