TransWikia.com

How to run tensorflow model twice before computing the loss

Data Science Asked by Odgiiv on January 28, 2021

I want to compute a loss function which uses output of the network twice on different inputs. For example as hypothetically,

first_output = model(first_input)
second_output = model(second_input)
loss = mean_absolute_error(first_output, second_output)

How to achieve this in tensorflow or keras?

One Answer

So, as in comment:

Put as many inputs in the batch as you want, and the run prediction on that batch. That way, you could use all outputs to calculate the loss function.

Keras

In Keras framework, if you want to calculate the mean_absolute_error as you state in your question, you could use predefined mean_absolute_error loss. Also, to have two inputs as you state in your question, specify the batch size of the model to 2.

Answered by Antonio Jurić on January 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP