sloss.py 752 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # time: 2023/5/8 13:15
  4. # file: loss.py.py
  5. # author: David
  6. # company: shenyang JY
  7. import tensorflow as tf
  8. from keras import backend as K
  9. import keras
  10. class SouthLoss(keras.losses.Loss):
  11. def __init__(self, cap):
  12. """
  13. 南网新规则损失函数
  14. :param cap:装机容量
  15. """
  16. self.cap = 0.2*cap
  17. super().__init__()
  18. def call(self, y_true, y_predict):
  19. """
  20. 自动调用
  21. :param y_true: 标签
  22. :param y_predict: 预测
  23. :return: 损失值
  24. """
  25. print(type(y_true))
  26. print("y_shape:", y_true.shape)
  27. loss = K.square(y_true - y_predict)
  28. loss = K.mean(loss, axis=-1)
  29. return loss