I have the following code:
def map_per_image(class_index_array):
def index_to_label_f(index):
index_to_label = {0:label_Vehicles, 1:label_Roads, 2:label_None}
#print(index.eval())
label = index_to_label[index]
return label
translated = tf.map_fn(index_to_label_f, class_index_array)
return translated
Outside of Tensorflow environment, using ordinary map it would have worked. But the value of the argument class_index_array
is a tensor, thus is its element, index
also tensor.
I need somehow to convert the tensor index
to an int value, in order to look up the dictionary. I tried index.eval()
but got an error:
ValueError: Operation 'map_8/while/map/while/TensorArrayReadV3' has been marked as not fetchable.
Without such conversion, I would get a different error due to using a tensor value to look up the dictionary:
KeyError: <tf.Tensor 'map_9/while/map/while/TensorArrayReadV3:0' shape=() dtype=int32>
I wonder what's the proper way to express my above implementation logic in Tensorflow execution (session) environment?