代码之家  ›  专栏  ›  技术社区  ›  ssm

张量流中的线性模型

  •  1
  • ssm  · 技术社区  · 7 年前

    N        = 400
    features = 100
    nSteps   = 1000
    
    data = (np.random.randn(N, features), np.random.randint(0, 2, N))
    
    W = tf.placeholder(tf.float32, shape=(features,1), name='W')
    b = tf.placeholder(tf.float32, shape=(features,1), name='b')
    d = tf.constant(data[0], dtype=tf.float32)
    
    result = tf.add( tf.matmul(d, W), b)
    

    结果表明,可能存在一些与尺寸有关的问题 b

    注:

    result = tf.matmul(d, W)
    

    我检查了结果的形状,与 b . 不太确定可能有什么问题。

    1 回复  |  直到 7 年前
        1
  •  3
  •   Gerges    7 年前

    在线性模型中(即输出层中的一个单元), b 应为标量。

    result = WX + b ,其中尺寸 W [1 x功能], X [功能x 1]。然后 WX 是标量。因此 b 应为标量。

    所以你应该改变 b

    b = tf.placeholder(tf.float32, shape=(1,1), name='b')