亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我不明白有兩個輸入的 map_fn

我不明白有兩個輸入的 map_fn

偶然的你 2023-12-29 15:39:45
map_fn當我在元組上使用它時,我很難理解它的作用。為了測試我做了以下事情:a = tf.constant([[1,2,3,4],[5,6,7,8],[9,10,11,12]])b = tf.constant([[1,2,3],[4,5,6],[7,8,9]])func = lambda x: x[0]y = tf.map_fn(func,(a,b))我在這里期望的是,map_fn 將 a 和 b 分別分成三個向量,并將它們賦予 func。func 然后只返回第一個輸入,而 map_fn 將它們重新堆疊在一起。所以我想我應該回來。相反發生的是一個可怕的錯誤:ValueError: The two structures don't have the same nested structure.First structure: type=tuple str=(<tf.Tensor: shape=(3, 4), dtype=int32, numpy=array([[ 1,  2,  3,  4],       [ 5,  6,  7,  8],       [ 9, 10, 11, 12]], dtype=int32)>, <tf.Tensor: shape=(3, 3), dtype=int32, numpy=array([[1, 2, 3],       [4, 5, 6],       [7, 8, 9]], dtype=int32)>)Second structure: type=EagerTensor str=tf.Tensor([1 2 3 4], shape=(4,), dtype=int32)More specifically: Substructure "type=tuple str=(<tf.Tensor: shape=(3, 4), dtype=int32, numpy=array([[ 1,  2,  3,  4],       [ 5,  6,  7,  8],       [ 9, 10, 11, 12]], dtype=int32)>, <tf.Tensor: shape=(3, 3), dtype=int32, numpy=array([[1, 2, 3],       [4, 5, 6],       [7, 8, 9]], dtype=int32)>)" is a sequence, while substructure "type=EagerTensor str=tf.Tensor([1 2 3 4], shape=(4,), dtype=int32)" is notDuring handling of the above exception, another exception occurred:ValueError                                Traceback (most recent call last)9 frames/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/nest.py in assert_same_structure(nest1, nest2, check_types, expand_composites)    400                   "Entire first structure:\n%s\n"    401                   "Entire second structure:\n%s"--> 402                   % (str(e), str1, str2))    403     404 ValueError: The two structures don't have the same nested structure.First structure: type=tuple str=(<tf.Tensor: shape=(3, 4), dtype=int32, numpy=array([[ 1,  2,  3,  4],       [ 5,  6,  7,  8],       [ 9, 10, 11, 12]], dtype=int32)>, <tf.Tensor: shape=(3, 3), dtype=int32, numpy=array([[1, 2, 3],       [4, 5, 6],       [7, 8, 9]], dtype=int32)>)在我看來,map_fn試圖以某種方式將整個元組與其組件之一結合起來。有人可以解釋一下這是怎么回事嗎?
查看完整描述

1 回答

?
斯蒂芬大帝

TA貢獻1827條經驗 獲得超8個贊

來自文檔:

如果 fn 的輸入和輸出簽名不同,則必須使用 fn_output_signature 指定輸出簽名。

您的函數接受兩個張量的元組并返回一個張量,因此您需要指定fn_output_signature

y?=?tf.map_fn(func,(a,b),?fn_output_signature=tf.int32)


查看完整回答
反對 回復 2023-12-29
  • 1 回答
  • 0 關注
  • 174 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號