【问题标题】:What does input_shape mismatch meansinput_shape 不匹配是什么意思
【发布时间】:2019-04-25 10:37:37
【问题描述】:
InvalidArgumentError: Incompatible shapes: [6,2,3] vs. [6,1] what does        
 this means.

不兼容的形状是什么意思

InvalidArgumentErrorTraceback(最近一次调用最后一次) in () ----> 1 个 odel.fit(x, y, epochs=500)

4 frames
/usr/local/lib/python2.7/dist- 
 packages/tensorflow/python/framework/errors_impl.pyc in __exit__(self, 
 type_arg, value_arg, traceback_arg)
 526             None, None,
 527             compat.as_text(c_api.TF_Message(self.status.status)),
 -->  528             c_api.TF_GetCode(self.status.status))
 529     # Delete the underlying status object from memory otherwise it 
stays alive
 530     # as there is a reference to status from this from the traceback 
  due to

 InvalidArgumentError: Incompatible shapes: [6,2,3] vs. [6,1]
  [ ]

 > Blockquote


   import tensorflow as tf
   import numpy as np
   from tensorflow import keras

  odel = tf.keras.Sequential([keras.layers.Dense(units=3)])

   odel.compile(optimizer='sgd', loss='mean_squared_error')

   x = np.array([[[1,2],[6,3]],[[3,4],[6,3]],[[4,5],[6,6]],[[5,6],[6,6]], 
                [[6,7],[6,4]],[[7,8],[6,2]]], dtype=float)
   y = np.array([6, 10, 15, 17, 17,17], dtype=float)

   odel.fit(x, y, epochs=500)

   a=np.array([[2,3]])`enter code here`
     print(odel.predict(a))

【问题讨论】:

    标签: tensorflow2.0


    【解决方案1】:

    代码中有很多事情需要解决

    1- 输入形状

    tf.Sequential 的第一层应该有一个 InputShape。它是特征的一个元素的形状

    2 - 标签

    标签至少有两个维度(特征也是如此)。 y 是[6] 的形状,而它应该是[b, 3] 的形状,3 是最后一层的单元值,b 是批次数。看特征,b是6

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-19
      • 2012-04-05
      • 1970-01-01
      • 1970-01-01
      • 2010-12-20
      相关资源
      最近更新 更多