| @@ -62,7 +62,6 @@ StyleCopReport.xml | |||||
| *_p.c | *_p.c | ||||
| *_i.h | *_i.h | ||||
| *.ilk | *.ilk | ||||
| *.meta | |||||
| *.obj | *.obj | ||||
| *.iobj | *.iobj | ||||
| *.pch | *.pch | ||||
| @@ -1,5 +1,4 @@ | |||||
| # TensorFlow.NET | # TensorFlow.NET | ||||
| TensorFlow.NET provides a .NET Standard binding for [TensorFlow](https://www.tensorflow.org/). It aims to implement the complete Tensorflow API in CSharp which allows .NET developers to develop, train and deploy Machine Learning models with the cross-platform .NET Standard framework. | |||||
| TensorFlow.NET (TF.NET) provides a .NET Standard binding for [TensorFlow](https://www.tensorflow.org/). It aims to implement the complete Tensorflow API in CSharp which allows .NET developers to develop, train and deploy Machine Learning models with the cross-platform .NET Standard framework. | TensorFlow.NET (TF.NET) provides a .NET Standard binding for [TensorFlow](https://www.tensorflow.org/). It aims to implement the complete Tensorflow API in CSharp which allows .NET developers to develop, train and deploy Machine Learning models with the cross-platform .NET Standard framework. | ||||
| [](https://gitter.im/sci-sharp/community) | [](https://gitter.im/sci-sharp/community) | ||||
| @@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Examples", "t | |||||
| EndProject | EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Core", "src\TensorFlowNET.Core\TensorFlowNET.Core.csproj", "{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Core", "src\TensorFlowNET.Core\TensorFlowNET.Core.csproj", "{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}" | ||||
| EndProject | EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NumSharp.Core", "..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj", "{DE97EAD7-B92C-4112-9690-91C40A97179E}" | |||||
| EndProject | |||||
| Global | Global | ||||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
| Debug|Any CPU = Debug|Any CPU | Debug|Any CPU = Debug|Any CPU | ||||
| @@ -27,6 +29,10 @@ Global | |||||
| {FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Debug|Any CPU.Build.0 = Debug|Any CPU | {FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| {FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Release|Any CPU.ActiveCfg = Release|Any CPU | {FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| {FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Release|Any CPU.Build.0 = Release|Any CPU | {FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| {DE97EAD7-B92C-4112-9690-91C40A97179E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||||
| {DE97EAD7-B92C-4112-9690-91C40A97179E}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||||
| {DE97EAD7-B92C-4112-9690-91C40A97179E}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||||
| {DE97EAD7-B92C-4112-9690-91C40A97179E}.Release|Any CPU.Build.0 = Release|Any CPU | |||||
| EndGlobalSection | EndGlobalSection | ||||
| GlobalSection(SolutionProperties) = preSolution | GlobalSection(SolutionProperties) = preSolution | ||||
| HideSolutionNode = FALSE | HideSolutionNode = FALSE | ||||
| @@ -20,32 +20,9 @@ namespace Tensorflow | |||||
| foreach (var op_def in op_list.Op) | foreach (var op_def in op_list.Op) | ||||
| _registered_ops[op_def.Name] = op_def; | _registered_ops[op_def.Name] = op_def; | ||||
| if (!_registered_ops.ContainsKey("NearestNeighbors")) | |||||
| _registered_ops["NearestNeighbors"] = op_NearestNeighbors(); | |||||
| } | } | ||||
| return _registered_ops; | return _registered_ops; | ||||
| } | } | ||||
| /// <summary> | |||||
| /// Doesn't work because the op can't be found on binary | |||||
| /// </summary> | |||||
| /// <returns></returns> | |||||
| private static OpDef op_NearestNeighbors() | |||||
| { | |||||
| var def = new OpDef | |||||
| { | |||||
| Name = "NearestNeighbors" | |||||
| }; | |||||
| def.InputArg.Add(new ArgDef { Name = "points", Type = DataType.DtFloat }); | |||||
| def.InputArg.Add(new ArgDef { Name = "centers", Type = DataType.DtFloat }); | |||||
| def.InputArg.Add(new ArgDef { Name = "k", Type = DataType.DtInt64 }); | |||||
| def.OutputArg.Add(new ArgDef { Name = "nearest_center_indices", Type = DataType.DtInt64 }); | |||||
| def.OutputArg.Add(new ArgDef { Name = "nearest_center_distances", Type = DataType.DtFloat }); | |||||
| return def; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -335,7 +335,7 @@ namespace Tensorflow.Operations | |||||
| ret.Enter(); | ret.Enter(); | ||||
| foreach (var nested_def in proto.NestedContexts) | foreach (var nested_def in proto.NestedContexts) | ||||
| throw new NotImplementedException(""); | |||||
| from_control_flow_context_def(nested_def, import_scope: import_scope); | |||||
| ret.Exit(); | ret.Exit(); | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| @@ -3,7 +3,8 @@ using System.Collections.Generic; | |||||
| using System.Linq; | using System.Linq; | ||||
| using System.Text; | using System.Text; | ||||
| using Tensorflow.Operations.ControlFlows; | using Tensorflow.Operations.ControlFlows; | ||||
| using static Tensorflow.ControlFlowContextDef; | |||||
| namespace Tensorflow.Operations | namespace Tensorflow.Operations | ||||
| { | { | ||||
| /// <summary> | /// <summary> | ||||
| @@ -184,6 +185,23 @@ namespace Tensorflow.Operations | |||||
| return null; | return null; | ||||
| } | } | ||||
| /// <summary> | |||||
| /// Deserializes `context_def` into the appropriate ControlFlowContext. | |||||
| /// </summary> | |||||
| /// <param name="context_def">ControlFlowContextDef proto</param> | |||||
| /// <param name="import_scope">Name scope to add</param> | |||||
| /// <returns>A ControlFlowContext subclass</returns> | |||||
| protected ControlFlowContext from_control_flow_context_def(ControlFlowContextDef context_def, string import_scope = "") | |||||
| { | |||||
| switch (context_def.CtxtCase) | |||||
| { | |||||
| case CtxtOneofCase.CondCtxt: | |||||
| return new CondContext().from_proto(context_def.CondCtxt, import_scope: import_scope); | |||||
| } | |||||
| throw new NotImplementedException($"Unknown ControlFlowContextDef field: {context_def.CtxtCase}"); | |||||
| } | |||||
| public object to_proto() | public object to_proto() | ||||
| { | { | ||||
| throw new NotImplementedException(); | throw new NotImplementedException(); | ||||
| @@ -0,0 +1,34 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Text; | |||||
| namespace Tensorflow | |||||
| { | |||||
| /// <summary> | |||||
| /// Convert to other datatype implicitly | |||||
| /// </summary> | |||||
| public partial class Operation | |||||
| { | |||||
| public static implicit operator Operation(IntPtr handle) => new Operation(handle); | |||||
| public static implicit operator IntPtr(Operation op) => op._handle; | |||||
| public static implicit operator Tensor(Operation op) => op.output; | |||||
| public override string ToString() | |||||
| { | |||||
| return _handle == IntPtr.Zero ? "tf.Operation Undefined" : $"tf.Operation '{name}' type={OpType}"; | |||||
| } | |||||
| public override bool Equals(object obj) | |||||
| { | |||||
| switch (obj) | |||||
| { | |||||
| case IntPtr val: | |||||
| return val == _handle; | |||||
| case Operation val: | |||||
| return val._handle == _handle; | |||||
| } | |||||
| return base.Equals(obj); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -248,27 +248,6 @@ namespace Tensorflow | |||||
| s.Check(); | s.Check(); | ||||
| return NodeDef.Parser.ParseFrom(buffer); | return NodeDef.Parser.ParseFrom(buffer); | ||||
| } | } | ||||
| } | |||||
| public override string ToString() | |||||
| { | |||||
| return _handle == IntPtr.Zero ? "tf.Operation Undefined" : $"tf.Operation '{name}' type={OpType}"; | |||||
| } | |||||
| public static implicit operator Operation(IntPtr handle) => new Operation(handle); | |||||
| public static implicit operator IntPtr(Operation op) => op._handle; | |||||
| public override bool Equals(object obj) | |||||
| { | |||||
| switch (obj) | |||||
| { | |||||
| case IntPtr val: | |||||
| return val == _handle; | |||||
| case Operation val: | |||||
| return val._handle == _handle; | |||||
| } | |||||
| return base.Equals(obj); | |||||
| } | } | ||||
| /// <summary> | /// <summary> | ||||
| @@ -27,6 +27,11 @@ namespace Tensorflow | |||||
| return Enumerable.Range(0, end); | return Enumerable.Range(0, end); | ||||
| } | } | ||||
| protected IEnumerable<int> range(int start, int end) | |||||
| { | |||||
| return Enumerable.Range(start, end); | |||||
| } | |||||
| public static T New<T>(object args) where T : IPyClass | public static T New<T>(object args) where T : IPyClass | ||||
| { | { | ||||
| var instance = Activator.CreateInstance<T>(); | var instance = Activator.CreateInstance<T>(); | ||||
| @@ -204,6 +204,12 @@ namespace Tensorflow | |||||
| switch (tensor.dtype) | switch (tensor.dtype) | ||||
| { | { | ||||
| case TF_DataType.TF_BOOL: | |||||
| var bools = new bool[tensor.size]; | |||||
| for (ulong i = 0; i < tensor.size; i++) | |||||
| bools[i] = *(bool*)(offset + (int)(tensor.itemsize * i)); | |||||
| nd = np.array(bools).reshape(ndims); | |||||
| break; | |||||
| case TF_DataType.TF_STRING: | case TF_DataType.TF_STRING: | ||||
| var bytes = tensor.Data(); | var bytes = tensor.Data(); | ||||
| // wired, don't know why we have to start from offset 9. | // wired, don't know why we have to start from offset 9. | ||||
| @@ -211,12 +217,6 @@ namespace Tensorflow | |||||
| var str = UTF8Encoding.Default.GetString(bytes, 9, bytes[8]); | var str = UTF8Encoding.Default.GetString(bytes, 9, bytes[8]); | ||||
| nd = np.array(str).reshape(); | nd = np.array(str).reshape(); | ||||
| break; | break; | ||||
| case TF_DataType.TF_UINT8: | |||||
| var _bytes = new byte[tensor.size]; | |||||
| for (ulong i = 0; i < tensor.size; i++) | |||||
| _bytes[i] = *(byte*)(offset + (int)(tensor.itemsize * i)); | |||||
| nd = np.array(_bytes).reshape(ndims); | |||||
| break; | |||||
| case TF_DataType.TF_INT16: | case TF_DataType.TF_INT16: | ||||
| var shorts = new short[tensor.size]; | var shorts = new short[tensor.size]; | ||||
| for (ulong i = 0; i < tensor.size; i++) | for (ulong i = 0; i < tensor.size; i++) | ||||
| @@ -10,9 +10,9 @@ namespace Tensorflow | |||||
| /// </summary> | /// </summary> | ||||
| public class _ElementFetchMapper : _FetchMapper | public class _ElementFetchMapper : _FetchMapper | ||||
| { | { | ||||
| private Func<List<object>, object> _contraction_fn; | |||||
| private Func<List<NDArray>, object> _contraction_fn; | |||||
| public _ElementFetchMapper(object[] fetches, Func<List<object>, object> contraction_fn) | |||||
| public _ElementFetchMapper(object[] fetches, Func<List<NDArray>, object> contraction_fn) | |||||
| { | { | ||||
| var g = ops.get_default_graph(); | var g = ops.get_default_graph(); | ||||
| ITensorOrOperation el = null; | ITensorOrOperation el = null; | ||||
| @@ -31,7 +31,7 @@ namespace Tensorflow | |||||
| /// </summary> | /// </summary> | ||||
| /// <param name="values"></param> | /// <param name="values"></param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| public override NDArray build_results(List<object> values) | |||||
| public override NDArray build_results(List<NDArray> values) | |||||
| { | { | ||||
| NDArray result = null; | NDArray result = null; | ||||
| @@ -42,7 +42,7 @@ namespace Tensorflow | |||||
| public NDArray build_results(BaseSession session, NDArray[] tensor_values) | public NDArray build_results(BaseSession session, NDArray[] tensor_values) | ||||
| { | { | ||||
| var full_values = new List<object>(); | |||||
| var full_values = new List<NDArray>(); | |||||
| if (_final_fetches.Count != tensor_values.Length) | if (_final_fetches.Count != tensor_values.Length) | ||||
| throw new InvalidOperationException("_final_fetches mismatch tensor_values"); | throw new InvalidOperationException("_final_fetches mismatch tensor_values"); | ||||
| @@ -24,19 +24,7 @@ namespace Tensorflow | |||||
| { | { | ||||
| var type = values[0].GetType(); | var type = values[0].GetType(); | ||||
| var nd = new NDArray(type, values.Count); | var nd = new NDArray(type, values.Count); | ||||
| switch (type.Name) | |||||
| { | |||||
| case "Single": | |||||
| nd.SetData(values.Select(x => (float)x).ToArray()); | |||||
| break; | |||||
| case "NDArray": | |||||
| NDArray[] arr = values.Select(x => (NDArray)x).ToArray(); | |||||
| nd = new NDArray(arr); | |||||
| break; | |||||
| default: | |||||
| break; | |||||
| } | |||||
| nd.SetData(values.ToArray()); | |||||
| return nd; | return nd; | ||||
| } | } | ||||
| @@ -57,4 +57,8 @@ More math/ linalg APIs.</PackageReleaseNotes> | |||||
| <Folder Include="Keras\Initializers\" /> | <Folder Include="Keras\Initializers\" /> | ||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | |||||
| <ProjectReference Include="..\..\..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj" /> | |||||
| </ItemGroup> | |||||
| </Project> | </Project> | ||||
| @@ -67,8 +67,7 @@ namespace Tensorflow | |||||
| case "Double": | case "Double": | ||||
| Marshal.Copy(nd1.Data<double>(), 0, dotHandle, nd.size); | Marshal.Copy(nd1.Data<double>(), 0, dotHandle, nd.size); | ||||
| break; | break; | ||||
| case "Byte": | |||||
| Marshal.Copy(nd1.Data<byte>(), 0, dotHandle, nd.size); | |||||
| //case "Byte": | |||||
| /*var bb = nd.Data<byte>(); | /*var bb = nd.Data<byte>(); | ||||
| var bytes = Marshal.AllocHGlobal(bb.Length); | var bytes = Marshal.AllocHGlobal(bb.Length); | ||||
| Marshal.Copy(bb, 0, bytes, bb.Length); | Marshal.Copy(bb, 0, bytes, bb.Length); | ||||
| @@ -195,7 +195,6 @@ namespace Tensorflow | |||||
| case "Double": | case "Double": | ||||
| return TF_DataType.TF_DOUBLE; | return TF_DataType.TF_DOUBLE; | ||||
| case "Byte": | case "Byte": | ||||
| return TF_DataType.TF_UINT8; | |||||
| case "String": | case "String": | ||||
| return TF_DataType.TF_STRING; | return TF_DataType.TF_STRING; | ||||
| default: | default: | ||||
| @@ -2,6 +2,7 @@ | |||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Linq; | using System.Linq; | ||||
| using System.Text; | using System.Text; | ||||
| using Tensorflow.Operations; | |||||
| namespace Tensorflow | namespace Tensorflow | ||||
| { | { | ||||
| @@ -115,6 +116,9 @@ namespace Tensorflow | |||||
| case List<ITensorOrOperation> values: | case List<ITensorOrOperation> values: | ||||
| foreach (var element in values) ; | foreach (var element in values) ; | ||||
| break; | break; | ||||
| case List<CondContext> values: | |||||
| foreach (var element in values) ; | |||||
| break; | |||||
| default: | default: | ||||
| throw new NotImplementedException("_build_internal.check_collection_list"); | throw new NotImplementedException("_build_internal.check_collection_list"); | ||||
| } | } | ||||
| @@ -15,9 +15,9 @@ namespace TensorFlowNET.Examples | |||||
| public class ObjectDetection : Python, IExample | public class ObjectDetection : Python, IExample | ||||
| { | { | ||||
| public int Priority => 7; | |||||
| public int Priority => 11; | |||||
| public bool Enabled { get; set; } = true; | public bool Enabled { get; set; } = true; | ||||
| public string Name => "Image Recognition"; | |||||
| public string Name => "Object Detection"; | |||||
| public float MIN_SCORE = 0.5f; | public float MIN_SCORE = 0.5f; | ||||
| string modelDir = "ssd_mobilenet_v1_coco_2018_01_28"; | string modelDir = "ssd_mobilenet_v1_coco_2018_01_28"; | ||||
| @@ -14,6 +14,7 @@ | |||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| <ProjectReference Include="..\..\..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj" /> | |||||
| <ProjectReference Include="..\..\src\TensorFlowNET.Core\TensorFlowNET.Core.csproj" /> | <ProjectReference Include="..\..\src\TensorFlowNET.Core\TensorFlowNET.Core.csproj" /> | ||||
| </ItemGroup> | </ItemGroup> | ||||
| @@ -22,6 +22,7 @@ | |||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| <ProjectReference Include="..\..\..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj" /> | |||||
| <ProjectReference Include="..\..\src\TensorFlowNET.Core\TensorFlowNET.Core.csproj" /> | <ProjectReference Include="..\..\src\TensorFlowNET.Core\TensorFlowNET.Core.csproj" /> | ||||
| <ProjectReference Include="..\TensorFlowNET.Examples\TensorFlowNET.Examples.csproj" /> | <ProjectReference Include="..\TensorFlowNET.Examples\TensorFlowNET.Examples.csproj" /> | ||||
| </ItemGroup> | </ItemGroup> | ||||