我尝试了以下代码,使用了tf.map_fn,但仍然出现错误,因为:“仅在启用急切执行时,tensor对象才可迭代。要使用tf.map_fn迭代此张量。” < / p>
def get_tensor_A(i):
return mask[i] #another tensor returned
def get_tensor_B(x):
return tf.nn.softmax(x, 1)
def final_rt(i, inp):
return get_tensor_A(idx)*get_tensor_B(inp)
tensor_2_list = [ tf.map_fn(lambda x: final_rt(x(0), x(1)), (idx, inp)) for idx, inp in enumerate(tensor_1_list)]