首页 > 解决方案 > Keras/Tensorflow prediction used in another program to calculate loss

问题描述

There is a pipeline I want to try that utilizes Keras/Tensorflow with another program. My 'very professional' diagram below shows what I am trying to accomplish

CNN with external program pipeline

The input to the CNN is a 2D-matrix and the output is a 2D matrix with the same dimensions as the input matrix. I want to feed the prediction into a separate program, which computes a new 2D matrix that should then be compared with the input matrix to calculate the loss.

I know that this would be slow to compute, but I still want to know if it is feasible. My first idea was to modify the loss function to interface with the external program - but a small amount of research seems to indicate that this is not possible. Is there some other way to interject a separate program to the loss function, or is there some other way to rework this pipeline?

Any suggestions are greatly appreciated!

标签: pythontensorflowkeras

解决方案


简短的回答是不,一般来说这是不可能的。这是因为 CNN 和任何神经网络都是通过使用反向传播和损失函数来训练的。如果要执行反向传播,您需要知道将输入 x 转换为输出 y 的过程。这样你就可以计算梯度。如果您使用黑盒程序作为等式的一部分,则无法进行反向传播。

一些可能的建议。

  • 如果可行,您可以训练一个卷积网络来模拟黑盒程序,然后就可以将其用作训练的一部分。
  • 你可以做一些其他形式的优化,在没有梯度的情况下工作/与黑盒损失函数一起工作。

推荐阅读