0

I has been trying to understand this machine learning problem for many days now and it really confuses me, I need some help.

I am trying to train a neural network whose input is an image, and which generates another image as output (it is not a very large image, it is 8x8 pixels). And I have an arbitrary fancy_algorithm() "black box" function that receives the input and prediction of the network (the two images) and outputs a float number that tells how good the output of the network was (calculates a loss). My problem is that I want to train THIS neural network but using the loss generated by the black box algorithm. This problem is confusing me, I researched a lot and I didn't find much about it, it seems like reinforcement learning, but at the same time I'm not sure because it’s not like an agent, but it has some kind of reinforcement at the same time.

In case you need more details to help me just ask. Thanks in advance!

  • 1
    you can define a custom loss function in keras/tensorflow, if that's what you're looking for: https://heartbeat.fritz.ai/how-to-create-a-custom-loss-function-in-keras-637bd312e9ab – Tyesh May 06 '20 at 02:02
  • Does this answer your question? [Make a custom loss function in keras](https://stackoverflow.com/questions/45961428/make-a-custom-loss-function-in-keras) – Marat May 06 '20 at 02:08
  • Yeah but how I will be able to pass the y_pred to the algorithm? y_pred is a tensor, the algorithm needs the (8x8 image) prediction of the network to be able to give the loss. I can’t just use the y_pred as a numpy array right. –  May 06 '20 at 02:20
  • That’s the big problem.. –  May 06 '20 at 02:23
  • You can convert numpy to tensor with tf.convert_to_tensor() – Ajai May 06 '20 at 06:14
  • You cannot use an arbitrary algorithm, it has to be implemented with backend functions, so gradients can be computer automatically – Dr. Snoopy May 06 '20 at 09:30
  • Yes, I suspected that, because I don't have a y_true. I can only calculate the y_pred loss... –  May 06 '20 at 13:13
  • So basically this problem just can't be solved using gradients? So I think the only way to solve this is to create several different networks that are consecutively better than each other, like a GA or particle swarm. That's right? –  May 06 '20 at 13:14
  • This question continues here: https://www.reddit.com/r/tensorflow/comments/gekotd/can_i_use_an_arbitrary_algorithm_as_a_loss/ –  May 06 '20 at 16:59

1 Answers1

0

Alright question solved. This is a reinforcement learning problem. I can’t use a gradient based optimization on my black-box loss function which don’t has any gradient. More details here: https://www.reddit.com/r/tensorflow/comments/gekotd/can_i_use_an_arbitrary_algorithm_as_a_loss/