2016-03-02 62 views
2
def compileActivation(self, net, layerNum): 
    variable = net.x if layerNum == 0 else net.varArrayA[layerNum - 1] 
    #print tf.expand_dims(net.dropOutVectors[layerNum], 1) 

    #print net.varWeights[layerNum]['w'].get_shape().as_list() 

    z = tf.matmul((net.varWeights[layerNum]['w']), (variable * (tf.expand_dims(net.dropOutVectors[layerNum], 1) if self.dropout else 1.0))) + tf.expand_dims(net.varWeights[layerNum]['b'], 1) 

    a = self.activation(z, self.pool_size) 
    net.varArrayA.append(a) 

我正在運行,其計算z,並將其傳遞到S形激活的激活功能相同的等級。 當我嘗試執行上面的功能,我得到以下錯誤:TensorFlow錯誤:TensorShape()必須具有

ValueError: Shapes TensorShape([Dimension(-2)]) and TensorShape([Dimension(None), Dimension(None)]) must have the same rank 

的theano當量計算z工作就好了:

z = T.dot(net.varWeights[layerNum]['w'], variable * (net.dropOutVectors[layerNum].dimshuffle(0, 'x') if self.dropout else 1.0)) + net.varWeights[layerNum]['b'].dimshuffle(0, 'x') 
+0

該代碼看起來在語法上是正確的,但似乎'net'中的某個對象具有損壞的形狀。特別是'TensorShape([Dimension(-2)])'永遠不會出現,並且在TensorFlow 0.7.0中進行測試,所以如果升級,您可能會收到更有幫助的錯誤消息。 – mrry

+0

謝謝。我會嘗試升級 –

回答

0

米希爾,

當我遇到了這個問題,這是因爲我的佔位符在我的Feed字典中大小錯誤。你也應該知道如何在會話中運行圖形。 tf.Session.run(fetches, feed_dict=None)

這裏是我的代碼,以使placeholders

# Note this place holder is for the input data feed-dict definition 
input_placeholder = tf.placeholder(tf.float32, shape=(batch_size, FLAGS.InputLayer)) 
# Not sure yet what this will be used for. 
desired_output_placeholder = tf.placeholder(tf.float32, shape=(batch_size, FLAGS.OutputLayer)) 

這裏是我的填充料詞典功能:

def feel_feed_funct(data_sets_train, input_pl, output_pl): 
    ti_feed, dto_feed = data_sets_train.next_batch(FLAGS.batch_size) 

    feed_dict = { 
    input_pl: ti_feed, 
    output_pl: dto_feed 
    } 
    return feed_dict 

後來我這樣做:

# Fill a feed dictionary with the actual set of images and labels 
# for this particular training step. 
feed_dict = fill_feed_dict(data_sets.train, input_placeholder, desired_output_placeholder) 

然後運行會話並獲取輸出我有這條線

_, l = sess.run([train_op, loss], feed_dict=feed_dict) 
相關問題