tf.map_fn報錯記錄

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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章