Tensorflow-如果主要偏差被更新,会有什么问题?
我使用一个预先训练过的网络,并通过两个完全连接的层传递输出向量。我用He初始化权重矩阵,用0初始化偏差 损失函数表现得非常糟糕。此外,它确实在一定程度上更新了权重矩阵,但主要是偏差 有人知道如何提高学习效率吗 提前谢谢Tensorflow-如果主要偏差被更新,会有什么问题?,tensorflow,Tensorflow,我使用一个预先训练过的网络,并通过两个完全连接的层传递输出向量。我用He初始化权重矩阵,用0初始化偏差 损失函数表现得非常糟糕。此外,它确实在一定程度上更新了权重矩阵,但主要是偏差 有人知道如何提高学习效率吗 提前谢谢 答案很简单。我在输入时出错。它们都是零和一些一。因此,重量只有微小的变化。我认为偏差是经过调整的,因为它将学习线性回归中的“平均值” with tf.name_scope('tf_hub'): module = hub.Module("https://tfhub.de
答案很简单。我在输入时出错。它们都是零和一些一。因此,重量只有微小的变化。我认为偏差是经过调整的,因为它将学习线性回归中的“平均值”
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)