I have a question concerning tf's map function. I encounter weird behavior with this function. If I do as stated in manual
label_tensor # shape [150, 1]
y = tf.map_fun(lambda x: x*x, label_tensor)
# returns y as a tensor with label_tensor x^2
however, if i want to implement my own function it doesn't seem to work. It just always passes a tensor to the specified function which is not made to handle tensors.
y = tf.map_fn(special_fun, label_tensor)
def special_fun(key):
return int(2000 * round(float(key)/2000))
# TypeError: float() argument must be a string or a number, not 'Tensor'
I am somehow not seeing the issue here.
Also if I try something like:
tmp_label_list = tf.Session().run(label_tensor)
print(tmp_label_list)
# prints out an evaluated list, [1, 2, 3, 3, 1, 2, 2,...]
But if I then pass [special_fun(i) for i in tmp_label_list]
it raises the Type-Error again, that it expected no 'Tensor'
What am I missing or doing wrong? Thanks in advance.