| @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Core", "src\T | |||||
| EndProject | EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Visualization", "src\TensorFlowNET.Visualization\TensorFlowNET.Visualization.csproj", "{0254BFF9-453C-4FE0-9609-3644559A79CE}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Visualization", "src\TensorFlowNET.Visualization\TensorFlowNET.Visualization.csproj", "{0254BFF9-453C-4FE0-9609-3644559A79CE}" | ||||
| EndProject | EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NumSharp.Core", "..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj", "{647E7590-9B50-48D9-B9E2-47743E9EAA56}" | |||||
| EndProject | |||||
| Global | Global | ||||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
| Debug|Any CPU = Debug|Any CPU | Debug|Any CPU = Debug|Any CPU | ||||
| @@ -33,6 +35,10 @@ Global | |||||
| {0254BFF9-453C-4FE0-9609-3644559A79CE}.Debug|Any CPU.Build.0 = Debug|Any CPU | {0254BFF9-453C-4FE0-9609-3644559A79CE}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| {0254BFF9-453C-4FE0-9609-3644559A79CE}.Release|Any CPU.ActiveCfg = Release|Any CPU | {0254BFF9-453C-4FE0-9609-3644559A79CE}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| {0254BFF9-453C-4FE0-9609-3644559A79CE}.Release|Any CPU.Build.0 = Release|Any CPU | {0254BFF9-453C-4FE0-9609-3644559A79CE}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| {647E7590-9B50-48D9-B9E2-47743E9EAA56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||||
| {647E7590-9B50-48D9-B9E2-47743E9EAA56}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||||
| {647E7590-9B50-48D9-B9E2-47743E9EAA56}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||||
| {647E7590-9B50-48D9-B9E2-47743E9EAA56}.Release|Any CPU.Build.0 = Release|Any CPU | |||||
| EndGlobalSection | EndGlobalSection | ||||
| GlobalSection(SolutionProperties) = preSolution | GlobalSection(SolutionProperties) = preSolution | ||||
| HideSolutionNode = FALSE | HideSolutionNode = FALSE | ||||
| @@ -252,6 +252,11 @@ namespace Tensorflow | |||||
| return math_ops.reduce_sum(input); | return math_ops.reduce_sum(input); | ||||
| } | } | ||||
| public static Tensor reduce_sum(Tensor input, int axis, int? reduction_indices = null) | |||||
| { | |||||
| return math_ops.reduce_sum(input, axis); | |||||
| } | |||||
| public static Tensor reduce_mean(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null, int? reduction_indices = null) | public static Tensor reduce_mean(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null, int? reduction_indices = null) | ||||
| => math_ops.reduce_mean(input_tensor, axis: axis, keepdims: keepdims, name: name, reduction_indices: reduction_indices); | => math_ops.reduce_mean(input_tensor, axis: axis, keepdims: keepdims, name: name, reduction_indices: reduction_indices); | ||||
| @@ -83,7 +83,7 @@ namespace Tensorflow | |||||
| { | { | ||||
| var log_prob = _log_unnormalized_prob(_z(x)); | var log_prob = _log_unnormalized_prob(_z(x)); | ||||
| var log_norm = _log_normalization(); | var log_norm = _log_normalization(); | ||||
| return log_prob - log_norm; | |||||
| return tf.sub(log_prob, log_norm); | |||||
| } | } | ||||
| private Tensor _log_unnormalized_prob (Tensor x) | private Tensor _log_unnormalized_prob (Tensor x) | ||||
| @@ -211,14 +211,14 @@ namespace Tensorflow | |||||
| /// <returns> The reduced tensor.</returns> | /// <returns> The reduced tensor.</returns> | ||||
| public static Tensor reduce_logsumexp(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null) | public static Tensor reduce_logsumexp(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null) | ||||
| { | { | ||||
| with(ops.name_scope(name, "ReduceLogSumExp", new { input_tensor }), scope => | |||||
| return with(ops.name_scope(name, "ReduceLogSumExp", new { input_tensor }), scope => | |||||
| { | { | ||||
| var raw_max = reduce_max(input_tensor, axis, true); | var raw_max = reduce_max(input_tensor, axis, true); | ||||
| var my_max = array_ops.stop_gradient(array_ops.where(gen_math_ops.is_finite(raw_max), raw_max, array_ops.zeros_like(raw_max))); | var my_max = array_ops.stop_gradient(array_ops.where(gen_math_ops.is_finite(raw_max), raw_max, array_ops.zeros_like(raw_max))); | ||||
| var result = gen_math_ops.log( | var result = gen_math_ops.log( | ||||
| reduce_sum( | reduce_sum( | ||||
| gen_math_ops.exp(gen_math_ops.sub(input_tensor, my_max)), | gen_math_ops.exp(gen_math_ops.sub(input_tensor, my_max)), | ||||
| new Tensor(axis), | |||||
| axis[0], | |||||
| keepdims)); | keepdims)); | ||||
| if (!keepdims) | if (!keepdims) | ||||
| { | { | ||||
| @@ -227,7 +227,6 @@ namespace Tensorflow | |||||
| result = gen_math_ops.add(result, my_max); | result = gen_math_ops.add(result, my_max); | ||||
| return _may_reduce_to_scalar(keepdims, axis, result); | return _may_reduce_to_scalar(keepdims, axis, result); | ||||
| }); | }); | ||||
| return null; | |||||
| } | } | ||||
| public static Tensor reduce_max(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null) | public static Tensor reduce_max(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null) | ||||
| @@ -284,13 +283,17 @@ namespace Tensorflow | |||||
| if (!common_shapes.has_fully_defined_shape(output) && | if (!common_shapes.has_fully_defined_shape(output) && | ||||
| !keepdims && | !keepdims && | ||||
| axis == null) | axis == null) | ||||
| // We want set_shape to be reflected in the C API graph for when we run it. | |||||
| output.shape = new long[0]; | output.shape = new long[0]; | ||||
| return output; | return output; | ||||
| } | } | ||||
| private static Tensor _may_reduce_to_scalar(bool keepdims, int[] axis, Tensor output) | private static Tensor _may_reduce_to_scalar(bool keepdims, int[] axis, Tensor output) | ||||
| { | { | ||||
| output.shape = new long[0]; | |||||
| if (!common_shapes.has_fully_defined_shape(output) && | |||||
| !keepdims && | |||||
| axis == null) | |||||
| output.shape = new long[0]; | |||||
| return output; | return output; | ||||
| } | } | ||||
| @@ -312,7 +315,7 @@ namespace Tensorflow | |||||
| if (axis != null) | if (axis != null) | ||||
| { | { | ||||
| // should return axis. or check before. | // should return axis. or check before. | ||||
| return null; | |||||
| return ops.convert_to_tensor(axis, TF_DataType.TF_INT32); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| @@ -58,4 +58,8 @@ Bug memory leak issue when allocating Tensor.</PackageReleaseNotes> | |||||
| <Folder Include="Keras\Initializers\" /> | <Folder Include="Keras\Initializers\" /> | ||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | |||||
| <ProjectReference Include="..\..\..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj" /> | |||||
| </ItemGroup> | |||||
| </Project> | </Project> | ||||
| @@ -12,7 +12,7 @@ namespace TensorFlowNET.Examples | |||||
| { | { | ||||
| public class ImageRecognition : Python, IExample | public class ImageRecognition : Python, IExample | ||||
| { | { | ||||
| public int Priority => 6; | |||||
| public int Priority => 7; | |||||
| public bool Enabled => true; | public bool Enabled => true; | ||||
| public string Name => "Image Recognition"; | public string Name => "Image Recognition"; | ||||
| @@ -15,8 +15,8 @@ namespace TensorFlowNET.Examples | |||||
| /// </summary> | /// </summary> | ||||
| public class KMeansClustering : Python, IExample | public class KMeansClustering : Python, IExample | ||||
| { | { | ||||
| public int Priority => 7; | |||||
| public bool Enabled => true; | |||||
| public int Priority => 8; | |||||
| public bool Enabled => false; | |||||
| public string Name => "K-means Clustering"; | public string Name => "K-means Clustering"; | ||||
| Datasets mnist; | Datasets mnist; | ||||
| @@ -12,7 +12,7 @@ namespace TensorFlowNET.Examples | |||||
| /// </summary> | /// </summary> | ||||
| public class NaiveBayesClassifier : Python, IExample | public class NaiveBayesClassifier : Python, IExample | ||||
| { | { | ||||
| public int Priority => 100; | |||||
| public int Priority => 6; | |||||
| public bool Enabled => true; | public bool Enabled => true; | ||||
| public string Name => "Naive Bayes Classifier"; | public string Name => "Naive Bayes Classifier"; | ||||
| @@ -88,7 +88,7 @@ namespace TensorFlowNET.Examples | |||||
| var s = tf.Session(); | var s = tf.Session(); | ||||
| if (xx.dtype == typeof(float)) | if (xx.dtype == typeof(float)) | ||||
| { | { | ||||
| var samples = np.vstack <float>(xx.ravel(), yy.ravel()); | |||||
| var samples = np.hstack<float>(xx.ravel().reshape(-1,1), yy.ravel().reshape(-1,1)); | |||||
| var Z = s.run(predict(samples)); | var Z = s.run(predict(samples)); | ||||
| } | } | ||||
| @@ -179,7 +179,7 @@ namespace TensorFlowNET.Examples | |||||
| var joint_likelihood = tf.add(ops.convert_to_tensor(priors, TF_DataType.TF_FLOAT), cond_probs); | var joint_likelihood = tf.add(ops.convert_to_tensor(priors, TF_DataType.TF_FLOAT), cond_probs); | ||||
| // normalize to get (log)-probabilities | // normalize to get (log)-probabilities | ||||
| var norm_factor = tf.reduce_logsumexp(joint_likelihood, new int[] { 1 }, true); | |||||
| var norm_factor = tf.reduce_logsumexp(joint_likelihood, new int[] { 1 }, keepdims: true); | |||||
| var log_prob = joint_likelihood - norm_factor; | var log_prob = joint_likelihood - norm_factor; | ||||
| // exp to get the actual probabilities | // exp to get the actual probabilities | ||||
| return tf.exp(log_prob); | return tf.exp(log_prob); | ||||
| @@ -11,7 +11,7 @@ namespace TensorFlowNET.Examples | |||||
| { | { | ||||
| public class TextClassificationWithMovieReviews : Python, IExample | public class TextClassificationWithMovieReviews : Python, IExample | ||||
| { | { | ||||
| public int Priority => 7; | |||||
| public int Priority => 9; | |||||
| public bool Enabled => false; | public bool Enabled => false; | ||||
| public string Name => "Movie Reviews"; | public string Name => "Movie Reviews"; | ||||