0

I want to train a neural network that has a loss component coming from an AdaBoost classifier.

myLoss(y_true, y_pred, adaClf, Z_):
    loss = BinaryCrossEntropy(y_true, y_pred) + MeanSquareError(adaClf.predict(Y_pred), Z_)
    return loss

where adaClf is the scikit-learn classifier. How can I implement this in Keras?

user7867665
  • 852
  • 7
  • 25

1 Answers1

1

Sorry, but you can not use external functions as loss in tensorflow. With tf.map you can use external functions, but no gradients can flow through it and you definitely need gradients in your loss. So you probably have to implement the classifier in tensorflow. Maybe this helps you.

Lau
  • 1,353
  • 7
  • 26
  • Okay. Thanks for the clarification, I really need a boosted decision tree. – user7867665 Nov 12 '18 at 12:25
  • The decision tree only gives me the correct labels, the loss function should still be differentiable. So I think it's possible in tensoflow to do this. – user7867665 Nov 12 '18 at 12:29
  • 1
    Yeah that is right, but in that case I would suggest you use the tf.dataset API. You can load the input image and directly calc the label with `tf.map`. You can also do it at runtime like in your code, but performance wise I would do it with tf.dataset. – Lau Nov 12 '18 at 12:34