You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

MeanAbsoluteError.cs 841 B

4 years ago
1234567891011121314151617181920212223
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using static Tensorflow.Binding;
  5. using static Tensorflow.KerasApi;
  6. namespace Tensorflow.Keras.Losses
  7. {
  8. public class MeanAbsoluteError : LossFunctionWrapper, ILossFunc
  9. {
  10. public MeanAbsoluteError(
  11. string reduction = null,
  12. string name = null) :
  13. base(reduction: reduction, name: name == null ? "mean_absolute_error" : name){ }
  14. public override Tensor Apply(Tensor y_true = null, Tensor y_pred =null, bool from_logits = false, int axis = -1)
  15. {
  16. Tensor y_pred_dispatch = ops.convert_to_tensor(y_pred);
  17. Tensor y_true_cast = gen_math_ops.cast(y_true, y_pred_dispatch.dtype);
  18. return gen_math_ops.mean(math_ops.abs(y_pred_dispatch - y_true_cast), axis: -1);
  19. }
  20. }
  21. }