| @@ -302,7 +302,7 @@ namespace Tensorflow | |||||
| // wired, don't know why we have to start from offset 9. | // wired, don't know why we have to start from offset 9. | ||||
| // length in the begin | // length in the begin | ||||
| 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); | |||||
| break; | break; | ||||
| case TF_DataType.TF_UINT8: | case TF_DataType.TF_UINT8: | ||||
| var _bytes = new byte[tensor.size]; | var _bytes = new byte[tensor.size]; | ||||
| @@ -63,7 +63,6 @@ Docs: https://tensorflownet.readthedocs.io</Description> | |||||
| <ItemGroup> | <ItemGroup> | ||||
| <PackageReference Include="Google.Protobuf" Version="3.9.0" /> | <PackageReference Include="Google.Protobuf" Version="3.9.0" /> | ||||
| <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" /> | |||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| @@ -51,12 +51,13 @@ namespace Tensorflow | |||||
| } | } | ||||
| // "sbyte", "byte", "short", "ushort", "int", "uint", "long", "ulong", "float", "double", "Complex" | // "sbyte", "byte", "short", "ushort", "int", "uint", "long", "ulong", "float", "double", "Complex" | ||||
| public static TF_DataType as_dtype(Type type) | |||||
| public static TF_DataType as_dtype(Type type, TF_DataType? dtype = null) | |||||
| { | { | ||||
| TF_DataType dtype = TF_DataType.DtInvalid; | |||||
| switch (type.Name) | switch (type.Name) | ||||
| { | { | ||||
| case "Char": | |||||
| dtype = dtype ?? TF_DataType.TF_UINT8; | |||||
| break; | |||||
| case "SByte": | case "SByte": | ||||
| dtype = TF_DataType.TF_INT8; | dtype = TF_DataType.TF_INT8; | ||||
| break; | break; | ||||
| @@ -100,7 +101,7 @@ namespace Tensorflow | |||||
| throw new Exception("as_dtype Not Implemented"); | throw new Exception("as_dtype Not Implemented"); | ||||
| } | } | ||||
| return dtype; | |||||
| return dtype.Value; | |||||
| } | } | ||||
| public static DataType as_datatype_enum(this TF_DataType type) | public static DataType as_datatype_enum(this TF_DataType type) | ||||
| @@ -226,7 +226,7 @@ namespace Tensorflow | |||||
| } | } | ||||
| } | } | ||||
| var numpy_dtype = dtypes.as_dtype(nparray.dtype); | |||||
| var numpy_dtype = dtypes.as_dtype(nparray.dtype, dtype: dtype); | |||||
| if (numpy_dtype == TF_DataType.DtInvalid) | if (numpy_dtype == TF_DataType.DtInvalid) | ||||
| throw new TypeError($"Unrecognized data type: {nparray.dtype}"); | throw new TypeError($"Unrecognized data type: {nparray.dtype}"); | ||||
| @@ -33,6 +33,14 @@ namespace Tensorflow | |||||
| verify_shape: verify_shape, | verify_shape: verify_shape, | ||||
| allow_broadcast: false); | allow_broadcast: false); | ||||
| public static Tensor constant(string value, | |||||
| string name = "Const") => constant_op._constant_impl(value, | |||||
| tf.@string, | |||||
| new int[] { 1 }, | |||||
| name, | |||||
| verify_shape: false, | |||||
| allow_broadcast: false); | |||||
| public static Tensor constant(float value, | public static Tensor constant(float value, | ||||
| int shape, | int shape, | ||||
| string name = "Const") => constant_op._constant_impl(value, | string name = "Const") => constant_op._constant_impl(value, | ||||
| @@ -29,8 +29,9 @@ namespace TensorFlowNET.Examples | |||||
| { | { | ||||
| // Run the op | // Run the op | ||||
| var result = sess.run(hello); | var result = sess.run(hello); | ||||
| Console.WriteLine(result.ToString()); | |||||
| return result.ToString().Equals(str); | |||||
| string result_string = string.Join("", result.GetData<char>()); | |||||
| Console.WriteLine(result_string); | |||||
| return result_string.Equals(str); | |||||
| }); | }); | ||||
| } | } | ||||