diff --git a/src/Microsoft.ML.Dnn/Microsoft.ML.Dnn.csproj b/src/Microsoft.ML.Dnn/Microsoft.ML.Dnn.csproj index b32dfd85ce..6f7a008323 100644 --- a/src/Microsoft.ML.Dnn/Microsoft.ML.Dnn.csproj +++ b/src/Microsoft.ML.Dnn/Microsoft.ML.Dnn.csproj @@ -15,7 +15,7 @@ - + diff --git a/src/Microsoft.ML.Dnn/TensorflowUtils.cs b/src/Microsoft.ML.Dnn/TensorflowUtils.cs index eaa5f01ba8..440581c0f6 100644 --- a/src/Microsoft.ML.Dnn/TensorflowUtils.cs +++ b/src/Microsoft.ML.Dnn/TensorflowUtils.cs @@ -78,7 +78,7 @@ internal static Session LoadTFSession(IExceptionContext ectx, byte[] modelBytes, var graph = new Graph(); try { - graph.Import(modelBytes); + graph.Import(modelBytes, ""); } catch (Exception ex) { diff --git a/src/Microsoft.ML.TensorFlow/TensorFlow/TensorflowUtils.cs b/src/Microsoft.ML.TensorFlow/TensorFlow/TensorflowUtils.cs index 82d29a18aa..68591d888a 100644 --- a/src/Microsoft.ML.TensorFlow/TensorFlow/TensorflowUtils.cs +++ b/src/Microsoft.ML.TensorFlow/TensorFlow/TensorflowUtils.cs @@ -32,7 +32,7 @@ internal static class TensorFlowUtils internal static DataViewSchema GetModelSchema(IExceptionContext ectx, Graph graph, string opType = null) { var schemaBuilder = new DataViewSchema.Builder(); - foreach (Operation op in graph.get_operations()) + foreach (var op in graph) { if (opType != null && opType != op.OpType) continue; diff --git a/src/Microsoft.ML.TensorFlow/TensorflowTransform.cs b/src/Microsoft.ML.TensorFlow/TensorflowTransform.cs index 23e21ee5f7..8a62a02a20 100644 --- a/src/Microsoft.ML.TensorFlow/TensorflowTransform.cs +++ b/src/Microsoft.ML.TensorFlow/TensorflowTransform.cs @@ -461,8 +461,7 @@ private void Dispose(bool disposing) { if (Session != IntPtr.Zero) { - Session.close(); - Session.Dispose(); + Session.close(); // invoked Dispose() } } finally @@ -796,39 +795,43 @@ public Tensor GetTensor() var sbyteBuffer = (sbyte[])Convert.ChangeType(_denseData, typeof(sbyte[])); return new Tensor(sbyteBuffer, _dims); } - - if (typeof(T) == typeof(ulong)) + else if (typeof(T) == typeof(ulong)) { var longBuffer = (ulong[])Convert.ChangeType(_denseData, typeof(ulong[])); return new Tensor(longBuffer, _dims); } - - if (typeof(T) == typeof(UInt32)) + else if (typeof(T) == typeof(UInt32)) { var uint32Buffer = (UInt32[])Convert.ChangeType(_denseData, typeof(UInt32[])); return new Tensor(uint32Buffer, _dims); } - - if (typeof(T) == typeof(UInt16)) + else if (typeof(T) == typeof(UInt16)) { var uint16Buffer = (UInt16[])Convert.ChangeType(_denseData, typeof(UInt16[])); return new Tensor(uint16Buffer, _dims); } - - if (typeof(T) == typeof(bool)) + else if (typeof(T) == typeof(bool)) { return new Tensor(new NDArray(_denseData, _tfShape), TF_DataType.TF_BOOL); } - - if (typeof(T) == typeof(float)) + else if (typeof(T) == typeof(float)) { return new Tensor(new NDArray(_denseData, _tfShape), TF_DataType.TF_FLOAT); } - - if (typeof(T) == typeof(double)) + else if (typeof(T) == typeof(double)) { return new Tensor(new NDArray(_denseData, _tfShape), TF_DataType.TF_DOUBLE); } + else if (typeof(T) == typeof(System.ReadOnlyMemory)) + { + byte[][] bytes = new byte[_vBuffer.Length][]; + for (int i = 0; i < bytes.Length; i++) + { + bytes[i] = Encoding.UTF8.GetBytes(((System.ReadOnlyMemory)(object)_denseData[i]).ToArray()); + } + + return new Tensor(bytes, _tfShape.dims.Select(x => (long)x).ToArray()); + } return new Tensor(new NDArray(_denseData, _tfShape)); //TFTensor.Create(_denseData, _vBuffer.Length, _tfShape); }