python - 两层神经网络 Tensorflow python

标签 python tensorflow neural-network

#layer 1
w1 = tf.Variable(tf.zeros([784, 30]))
b1 = tf.Variable(tf.zeros([30]))
y1 = tf.nn.relu(tf.matmul(X, w1) + b1)

#layer 2
w2 = tf.Variable(tf.zeros([30, 10]))
b2 = tf.Variable(tf.zeros([10]))
logits = tf.matmul(y1, w2) + b2
preds = tf.nn.softmax(logits)

嗨,我是 tensorflow 和神经网络的新手。我尝试实现一个两层神经网络来进行数字识别。当只有一层时,代码工作正常,但在添加第二层后,精度下降到 0.11xxxx。我的代码有什么问题吗?提前致谢

最佳答案

您可以使用 random_normal 初始化权重。

w1 = tf.Variable(tf.random_normal([784, 30]))
...
w2 = tf.Variable(tf.random_normal([30, 10]))

关于python - 两层神经网络 Tensorflow python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45982900/

相关文章:

tensorflow - Keras:以两种不同方式拟合 ConvNet 时结果不一致

python - 如何从变量调用并运行另一个Python文件

python - 在 python 中定义名称

python - 如何在python网页中获取当前URL?

python - 训练 acc 减少,验证增加。训练损失、验证损失减少

machine-learning - 确定 Keras 的 Mnist 输入形状

python导入问题

tensorflow - Keras image_dataset_from_directory 未找到图像

python - 如何在 Keras 中向 CuDNNGRU 或 CuDNNLSTM 添加循环丢失

.net - 查找重复模式的最佳算法