My tensorflow graph neural network has a loss function looks like the code below. It calculates the loss based on the input key. Since gnn stores the key in bytes format, and I need to evaluate it to string for hashing the features. But it failed with eager execution is disabled. How to make it works?
#! /usr/bin/python
import tensorflow as tf
tf.config.run_functions_eagerly(False) # numpy() works when eager is enabled
@tf.function
def loss_fn(d):
return tf.reduce_mean(d['features'][d['key'][0].numpy().decode('utf-8')])
d = {'key': tf.constant(['A01', 'B01']),
'features': {'A01': [0.1,0.2],
'B01': [0.3,0.4]}}
loss=loss_fn(d)
print(loss)
Access the feature based on input key