The Python Oracle

Tensorflow: Why is tf.case giving me the wrong result?

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Techno Bleepage Open

--

Chapters
00:00 Question
01:58 Accepted answer (Score 1)
02:33 Thank you

--

Full question
https://stackoverflow.com/questions/4272...

Question links:
https://www.tensorflow.org/api_docs/pyth...

Accepted answer links:
https://github.com/tensorflow/tensorflow...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #tensorflow #python2x

#avk47



ACCEPTED ANSWER

Score 1


This was answered in https://github.com/tensorflow/tensorflow/issues/8776

It turns out that tf.case behavior is undefined if, in fn_tensors, the lambdas return a tensor that was created outside of the lambda. The correct usage is to define the lambdas such that they return a newly-created tensor.

According to the linked Github issue, this usage is required because tf.case must create the tensor itself in order to hook up the tensor's inputs to the correct branch of the predicate.