mardi 2 juin 2020

Using tf.switch_case or tf.case with string condition

I am learning tensorflow and have some trouble implementing things that are otherwise easy.

I have a toy function:

def function(fruit, b):
    if fruit == 'apple':
        return b        
    elif fruit == 'banana':
        return b+2        
    else:
        return b*3

The case syntax is: tf.case(pred_fn_pairs, default=None, exclusive=False, strict=False, name='case') where pred_fn_pairs refers to a tuple of (condition, output) and I have trouble rewriting the condition in a fully tensorflow way since it is a string.

How would the above function be written using only tensorflow?

Aucun commentaire:

Enregistrer un commentaire