0

How do I implement a network cost function of type autoencoder in keras based on the database labels. The examples of this base have labels 0 and 1. I did the form presented below, I do not know if it is correct.

def loss_function (x):
    def function(y_true, y_pred):
        for i in range (batch_size):
            if x[i]==0:
            print('valorA',x[i])
            L1=K.mean(K.square(y_pred[i] - y_true[i]))
            else:
            print('valorB',x[i])
            L2=K.mean(K.square(y_pred[i] - y_true[i]))      
    return L1+L2

return function

compilação do autoencoder

autoencoder.compile(loss=loss_function(labeltr),optimizer='adam')
curveball
  • 4,320
  • 15
  • 39
  • 49
Monteiro
  • 1
  • 1
  • 1
    Welcome to StackOverflow, please, visit [tour](https://stackoverflow.com/tour) and read [how to ask a question](https://stackoverflow.com/help/how-to-ask). Please, provide more info on efforts you made and share some code. – PeS Aug 15 '18 at 01:52
  • def loss_function (x): def function(y_true, y_pred): for i in range (batch_size): if x[i]==0: print('valorA',x[i]) L1=K.mean(K.square(y_pred[i] - y_true[i])) else: print('valorB',x[i]) L2=K.mean(K.square(y_pred[i] - y_true[i])) return L1+L2 – Monteiro Aug 15 '18 at 01:57
  • Add code to original question and format that properly. It will help others to help you. – PeS Aug 15 '18 at 01:59

0 Answers0