| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 500f0c0 commit a994a86
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -589,23 +589,17 @@ public static string to_numpy_string(Tensor tensor) | |||
| 589 | 589 | { | |
| 590 | 590 | return "<unprintable>"; | |
| 591 | 591 | } | |
| 592 | + else if (dtype == TF_DataType.TF_RESOURCE) | ||
| 593 | + { | ||
| 594 | + return "<unprintable>"; | ||
| 595 | + } | ||
| 592 | 596 | ||
| 593 | 597 | var nd = tensor.numpy(); | |
| 594 | 598 | ||
| 595 | 599 | if (nd.size == 0) | |
| 596 | 600 | return "[]"; | |
| 597 | 601 | ||
| 598 | - switch (dtype) | ||
| 599 | - { | ||
| 600 | - case TF_DataType.TF_STRING: | ||
| 601 | - return string.Join(string.Empty, nd.ToArray<byte>() | ||
| 602 | - .Select(x => x < 32 || x > 127 ? "\\x" + x.ToString("x") : Convert.ToChar(x).ToString())); | ||
| 603 | - case TF_DataType.TF_VARIANT: | ||
| 604 | - case TF_DataType.TF_RESOURCE: | ||
| 605 | - return "<unprintable>"; | ||
| 606 | - default: | ||
| 607 | - return nd.ToString(); | ||
| 608 | - } | ||
| 602 | + return nd.ToString(); | ||
| 609 | 603 | } | |
| 610 | 604 | ||
| 611 | 605 | public static ParsedSliceArgs ParseSlices(Slice[] slices) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | using System; | |
| 2 | 2 | using System.Collections.Generic; | |
| 3 | 3 | using System.Linq; | |
| 4 | + using Tensorflow.Keras.Losses; | ||
| 4 | 5 | using Tensorflow.Keras.Metrics; | |
| 5 | 6 | using static Tensorflow.KerasApi; | |
| 6 | 7 | ||
@@ -74,11 +75,15 @@ Metric _get_metric_object(string metric, Tensor y_t, Tensor y_p) | |||
| 74 | 75 | metric_obj = keras.metrics.sparse_categorical_accuracy; | |
| 75 | 76 | else | |
| 76 | 77 | metric_obj = keras.metrics.categorical_accuracy; | |
| 77 | - | ||
| 78 | - return new MeanMetricWrapper(metric_obj, metric); | ||
| 79 | 78 | } | |
| 79 | + else if(metric == "mean_absolute_error" || metric == "mae") | ||
| 80 | + { | ||
| 81 | + metric_obj = keras.metrics.mean_absolute_error; | ||
| 82 | + } | ||
| 83 | + else | ||
| 84 | + throw new NotImplementedException(""); | ||
| 80 | 85 | ||
| 81 | - throw new NotImplementedException(""); | ||
| 86 | + return new MeanMetricWrapper(metric_obj, metric); | ||
| 82 | 87 | } | |
| 83 | 88 | ||
| 84 | 89 | public IEnumerable<Metric> metrics | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,5 +40,11 @@ public Tensor sparse_categorical_accuracy(Tensor y_true, Tensor y_pred) | |||
| 40 | 40 | ||
| 41 | 41 | return math_ops.cast(math_ops.equal(y_true, y_pred), TF_DataType.TF_FLOAT); | |
| 42 | 42 | } | |
| 43 | + | ||
| 44 | + public Tensor mean_absolute_error(Tensor y_true, Tensor y_pred) | ||
| 45 | + { | ||
| 46 | + y_true = math_ops.cast(y_true, y_pred.dtype); | ||
| 47 | + return keras.backend.mean(math_ops.abs(y_pred - y_true), axis: -1); | ||
| 48 | + } | ||
| 43 | 49 | } | |
| 44 | 50 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments