Custom loss function

I want to use a pretrained TensorFlow model inside a custom loss function to train another model. Is it possible to do that? it seems that I cannot run a sess in a graph.

Hi Leonard, can you clarify a little bit.

Do you want to use the pretrained TF model to be the ground truth and those values are compared to what your model is generating?

If so, could you instead cache the pre trained model’s results and use that instead?

Hi ! thanks for your reply.
Yes, I want to minimize the result between pretrained model and the training model.
Since the data set is large and the data is randomly feed into model, I trying to load the pretrained model in training phase. Is it possible to do that?

My gut feeling is that it might work yes

@markdaoust what do you think?


it seems that I cannot run a sess in a graph.

That’s correct. But you shouldn’t need sessions or graphs at all. Everything will be a lot easier if you use TF2.

1 Like

Thanks for your reply!
I try to modify the training code of TF1. Are there other solution to do this?

It’s possible. You just have to build everything into a single graph and use a single session. That’s hard. Maybe not worth the effort at this point.

But if you can make a saved_model from your TF1 model, you can easily load that in TF2 and everything should work.


As Mark said, if you can migrate to TF 2, it will make your life easier

1 Like

Thanks for your information. I will try to migrate to TF2.