Where vs Select operators in the Tensorflow frontend


#1

Hi,

I have a Tensorflow model with some unsupported operators and among them there is the “Where” operator. After checking the Relay IR operators it seems the Where operator is supported but exposed in the Tensorflow frontend as a Select operator.

Could someone clarify why is this the case? Are Select and where equivalent? Could I extend the Tensorflow frontend by adding an entry to include the “Where” operator just like “Select”?

Thanks


#2

You could try it out, because Select and Where seem to be equivalent in TF, It’s just different names in different versions.(But I’m not sure)


#3

Yes that is my feeling that where are select are the same, but I have not been able to confirm this by looking at the TF documentation. Maybe someone in the community can clarify this.


#4

It seems that Select is deprecated and where should be used instead. I am wondering if some could clarify this and why Select is the one used in the Tensorflow frontend.

Moreover, the Select operator invokes the where function in the Tensorflow frontend:


#5

@tico we saw the same issue before, I added Select. If you saw Where in your model, very likely your model was trained with very old tf version. Select is the c++ operator for tf.where() now. So the where should be gone if you use new tf version (>=1.0).

BTW, I am happy to add Where support if you have a small python test case to help reproduce


#6

I am afraid OP where is different from OP Select

Select is from tf.where(condition, x, y), but Where is from tf.where(x)

Where:

Select:

The output shape of Where is determined by content of its input, can relay support this case now?


#7

Thanks @lixiaoquan for pointing this out. Now I have the test case as below for Where. Since the output shape may vary based on the number of true elements. Then adding support for Where needs to rely on dynamism on which folks are working.

condition = [[True,False,False],
             [False,True,True]]
with tf.Session() as sess:
  print(sess.run(tf.where(condition)))

#8

@yongwww yes the pb file was generated using a very old version of TF, but now I have a new one generated with TF 1.13


#9

So you mean that currently “Where” does not support the case of only one parameter, and we need to wait until the TensorArray is supported. Is my understanding correct? thanks! @yongwww


#10

@ydy Where needs to wait dynamism is supported (a few guys are working on dynamism actively)


Whether TVM will support dynamic shapes in the future