diff --git a/src/Microsoft.ML.TensorFlow/TensorflowUtils.cs b/src/Microsoft.ML.TensorFlow/TensorflowUtils.cs index dd25bb104b..065fb064a5 100644 --- a/src/Microsoft.ML.TensorFlow/TensorflowUtils.cs +++ b/src/Microsoft.ML.TensorFlow/TensorflowUtils.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Security.AccessControl; using System.Security.Principal; +using System.Text; using Microsoft.ML.Data; using Microsoft.ML.Internal.Utilities; using Microsoft.ML.Runtime; @@ -440,13 +441,13 @@ internal static Tensor CastDataAndReturnAsTensor(T[] data, TensorShape tfShap return new Tensor((double[])(object)data, dims, TF_DataType.TF_DOUBLE); else if (typeof(T) == typeof(ReadOnlyMemory)) { - string[] strings = new string[data.Length]; - for (int i = 0; i < strings.Length; i++) + byte[][] bytes = new byte[data.Length][]; + for (int i = 0; i < bytes.Length; i++) { - strings[i] = data[i].ToString(); + bytes[i] = Encoding.Unicode.GetBytes(((ReadOnlyMemory)(object)data[i]).ToArray()); } - return new Tensor(strings); + return new Tensor(bytes, TF_DataType.TF_STRING); } return new Tensor(new NDArray(data, tfShape));