|
1 | | -using System; |
2 | | -using System.Collections.Generic; |
3 | | -using System.Text; |
4 | | -using static Tensorflow.Binding; |
5 | | -using static Tensorflow.KerasApi; |
| 1 | +namespace Tensorflow.Keras.Losses; |
6 | 2 |
|
7 | | -namespace Tensorflow.Keras.Losses |
| 3 | +public class CategoricalCrossentropy : LossFunctionWrapper, ILossFunc |
8 | 4 | { |
9 | | - public class CategoricalCrossentropy : LossFunctionWrapper, ILossFunc |
| 5 | + float label_smoothing; |
| 6 | + public CategoricalCrossentropy( |
| 7 | + bool from_logits = false, |
| 8 | + float label_smoothing = 0, |
| 9 | + string reduction = null, |
| 10 | + string name = null) : |
| 11 | + base(reduction: reduction, |
| 12 | + name: name == null ? "categorical_crossentropy" : name, |
| 13 | + from_logits: from_logits) |
10 | 14 | { |
11 | | - float label_smoothing; |
12 | | - public CategoricalCrossentropy( |
13 | | - bool from_logits = false, |
14 | | - float label_smoothing = 0, |
15 | | - string reduction = null, |
16 | | - string name = null) : |
17 | | - base(reduction: reduction, |
18 | | - name: name == null ? "categorical_crossentropy" : name, |
19 | | - from_logits: from_logits) |
20 | | - { |
21 | | - this.label_smoothing = label_smoothing; |
22 | | - } |
| 15 | + this.label_smoothing = label_smoothing; |
| 16 | + } |
23 | 17 |
|
24 | 18 |
|
25 | | - public override Tensor Apply(Tensor y_true, Tensor y_pred, bool from_logits = false, int axis = -1) |
26 | | - { |
27 | | - // Try to adjust the shape so that rank of labels = rank of logits - 1. |
28 | | - return keras.backend.categorical_crossentropy(y_true, y_pred, from_logits: from_logits); |
29 | | - } |
| 19 | + public override Tensor Apply(Tensor y_true, Tensor y_pred, bool from_logits = false, int axis = -1) |
| 20 | + { |
| 21 | + // Try to adjust the shape so that rank of labels = rank of logits - 1. |
| 22 | + return keras.backend.categorical_crossentropy(y_true, y_pred, from_logits: from_logits); |
30 | 23 | } |
31 | 24 | } |
0 commit comments