錯誤一:二分類,標簽y
ValueError: Cannot feed value of shape (128,1) for Tensor u'input_y_2:0', which has shape '(?, 2)'
我的輸入y_train維度為(128,1),即是一個向量,batch_size為128.
在tensorflow中你在做數據喂養的時候你輸入的是一個一維數組如:[0,1,0],他的shape 為(3,)
在tensorflow中一維數組是不能與同樣的一維數組進行運算的,必須通過reshape成為(1,3)而
另一個一維數組必須是(3,1)才能相乘,但是在numpy中兩個一維數組相乘是不會報錯的,
這個原因是在tensorflow中向量是不能和矩陣進行運算的,你需要把他改成二維的矩陣才能運算;
故:將原來的y_train = [0,1,1,0,1,0,……]改成 [ [ 0] , [1] , [1] , [0], [1] , [0] ,……]形式
y_train = np.array(y_train[start_index: end_index]).reshape(-1, 1)
接着產生第二個錯誤:
InvalidArgumentError: You must feed a value for placeholder tensor 'input/y-input' with dtype float and shape [?,2]
記住:二分類的num_classes = 1,這里報錯是因為我的num_classes = 2。
接着產生第三錯誤:雙向RNN的模型
Tensorflow: unable to share dense/kernel - ValueError: Trying to share variable dense/kernel, but specified shape (128, 1) and found shape (128, 2)
原因:name_scope可能取相同的名字。
解決:
(第一)
- Give each layer a unique name
- Put everything in a
variable_scope
withreuse=tf.AUTO_REUSE
(for the Adam optimizer)
(第二):
刪除這一個代碼【雖然不知道原因是什么,merge_all會報錯】:merged_summary = tf.summary.merge_all()