【问题标题】:Tensorflow - What is wrong if mainly bias is updated?Tensorflow - 如果主要更新偏差有什么问题?
【发布时间】:2018-08-23 06:47:35
【问题描述】:

我使用来自Tensorflow-Hub 的预训练网络,并将输出向量通过 2 个全连接层。我用 He 初始化初始化权重矩阵,用 0 初始化偏差。

损失函数的行为很奇怪。它也确实更新了权重矩阵,但主要是偏差。

有人知道如何提高学习效率吗?

提前致谢!

with tf.name_scope('tf_hub'):
    module = hub.Module("https://tfhub.dev/google/imagenet/pnasnet_large/feature_vector/2")
    tf_hub_features = module(X)  # Features with shape [batch_size, num_features].

he_initializer = tf.contrib.layers.variance_scaling_initializer(factor=2.0, mode='FAN_IN', uniform=False)

with tf.name_scope('Hidden1'):
    W1 = tf.get_variable(initializer=he_initializer, shape=[Constants.PNAS_NET2_NB_FEATURES, config["h1_nb_units"]],
                         name="W1")
    # W1 = tf.Variable(tf.random_normal([Constants.PNAS_NET2_NB_FEATURES, config["h1_nb_units"]]), name="W1")
    tf.summary.histogram("W1", W1)
    b1 = tf.Variable(tf.zeros([config["h1_nb_units"]]), name="b1")
    tf.summary.histogram("b1", b1)
    o1 = tf.nn.relu(tf.matmul(tf_hub_features, W1) + b1, name="o1")
    # dropout1 = tf.layers.dropout(inputs=o1, rate=config["keep_probability"], name="dropout1")

with tf.name_scope('Hidden2'):
    W2 = tf.get_variable(initializer=he_initializer, shape=[config["h1_nb_units"], config["h2_nb_units"]],
                         name="W2")
    tf.summary.histogram("W2", W2)
    b2 = tf.Variable(tf.zeros([config["h2_nb_units"]]), name="b2")
    tf.summary.histogram("b2", b2)
    o2 = tf.nn.relu(tf.matmul(o1, W2) + b2, name="o2")

with tf.name_scope('Y'):
    WY = tf.get_variable(initializer=he_initializer, shape=[config["h2_nb_units"], config["output_dim"]],
                         name="WY")
    tf.summary.histogram("WY", WY)
    bY = tf.Variable(tf.zeros([config["output_dim"]]), name="bY")
    tf.summary.histogram("bY", bY)
    Y_star = tf.add(tf.matmul(o2, WY), bY, name="Y_star")
    Y = tf.nn.sigmoid(Y_star, name="Y")

with tf.name_scope('loss'):
    Y_ = tf.placeholder(tf.float32, shape=(None, 1), name="Y_")
    loss = tf.losses.log_loss(Y_, Y_hat)

optimizer = tf.train.AdamOptimizer(config["learning_rate"])
train_step = optimizer.minimize(loss)

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

    答案很简单。我在输入输入时出错。它们都是零和一些。因此,权重只有很小的变化。我想调整了偏差,因为它会学习线性回归中的“平均值”之类的东西。

    【讨论】:

      猜你喜欢
      • 2017-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-29
      相关资源
      最近更新 更多