Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
143 views
in Technique[技术] by (71.8m points)

python - Why does Tensorflow 2 give errors when we use custom loss functions?

When specifying the contractive loss in an autoencoder according to the method given in the link:

https://wiseodd.github.io/techblog/2016/12/05/contractive-autoencoder/

Tensorflow 2.0 seems to be constantly throwing up errors. It says that we are giving a numpy input to a symbolic array or something. I ran the example in Google Colab and got the error. The Custom Loss function given in the link only worked when I set the following commands:

import tensorflow.compat.v1 as tf

tf.disable_v2_behavior()

I also tried to specify the custom reconstructive loss and KL loss for a VAE but I got the same error. It only worked when I copied the custom train_step from the Keras site. I tried the same procedure here but it didn't work. I got the error:

'KerasTensor' is missing attribute '_id'

I've heard that the issue may stem from eager execution in v2 but simply disabling eager execution in v2 doesn't seem to fix the error. Does anyone know how I can specify the custom loss without disabling v2 functionality?

question from:https://stackoverflow.com/questions/65601953/why-does-tensorflow-2-give-errors-when-we-use-custom-loss-functions

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...