The Python Oracle

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

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Ancient Construction

--

Chapters
00:00 Tensorflow: Why Is Tf.Case Giving Me The Wrong Result?
01:30 Accepted Answer Score 1
01:53 Thank you

--

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

--

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.