Given a 2D Tensor of unknown dimensions [?, ?] containing integers (representing classes), I would like to obtain a new Tensor of the same shape, but with the values replaced by floats taken from a lookup table (representing class weights).
For example:
inputs = [ [1,3,3], [2,4,2] ]
lookup table: {1: 0.2, 2: 0.25, 3: 0.1, 4: 0.45}
output: [ [0.2, 0.1, 0.1], [0.25, 0.45, 0.25] ]
I have tried to chain two lambda functions with tf.map_fn, iterating over every row, then over every element:
elem_iter = lambda y: unknown_lookup_function(y)
row_iter = lambda x: elem_iter(x)
weights = tf.map_fn(row_iter, inputs, dtype=tf.float32)
but could not find a proper way of defining the lookup function. Any advice on how to implement this behaviour ? Is there a native op that I could use instead of map_fn ?