tf.map_fn报错
ValueError: The two structures don't have the same nested structure
错误代码处如下:
#函数,需要两种tensor的输入,输出一个tensor
def fun(elems):
input_0,input_1= elems
.....
return result
#调用
result= tf.map_fn(fun, (input_0,input_1))
原因:map_fn调用的函数fun,其返回类型与输出elems不一样(包括输入与返回tensor的数量)时,需要指定dtype参数,确定输出类型。
上述代码改正后如下:
result= tf.map_fn(fun, (input_0,input_1),dtype=tf.float32)