新手在這裏,我很抱歉,如果這個問題很愚蠢,但我在網上找不到任何東西。我得到了一個意想不到的形狀,輸出爲tf.squared_difference
。我期望一個張量與shape=(100, ?)
形狀從下面的代碼片斷Tensorflow tf.squared_difference輸出意想不到的形狀
[print("Logits",logits,"#Labels",labels,"LOSS",tf.squared_difference(labels,logits)) for logits, labels in zip(logits_series,labels_series)]
但是它產生(100,100)
損失
Logits張量( 「add_185:0」 的獲得與損失,形狀=(100, 1),dtype = float32)#Labels張量(「unstack_29:0」,shape =(100,),dtype = float32)LOSS張量(「SquaredDifference_94:0」,shape =(100,100),dtype = float32) Logits Tensor(「add_186:0」,shape =(100,1),dtype = float32)#Labels張量(「unstack_29:1」,shape =(100,),dtype = float32)LOSS張量(「SquaredDifference_95:0」 ,形狀=(100,100),dtype = float32)
我測試了下面的代碼的另一個例子,並給出了預期的輸出形狀。
myTESTX = tf.placeholder(tf.float32, [100, None])
myTESTY = tf.placeholder(tf.float32, [100, 1])
print("Test diff X-Y",tf.squared_difference(myTESTX,myTESTY))
print("Test diff Y-X",tf.squared_difference(myTESTY,myTESTX))
測試DIFF XY張量( 「SquaredDifference_92:0」?,形狀=(100,),D型細胞= FLOAT32) 測試diff的YX張量( 「SquaredDifference_93:0」,形狀=(100,? ),D型= FLOAT32)
我有問題,爲什麼這兩個片段產生不同的輸出形狀
謝謝你,但我真的不明白爲什麼它是10,10。張量的第二維不是10. – cagdas
對。我同意這是一個令人困惑/不直觀的例子。如果有幫助,請注意shape(10,)是一個行向量,shape(10,1)是一個列向量。 Numpy(和tensorflow)做所謂的[廣播](https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html)。如果元素操作的形狀不匹配,numpy會嘗試複製其中一個數組,使其適合其他形狀,然後將它們縫合在一起。 –