![](/img/trans.png)
[英]Keras accuracy is different between model and classification report for binary output
[英]Untrained binary classification keras model gives output of 1 on all
我正在尝试用一个隐藏层构建一个小型神经网络。 我希望在训练之前,该模型将输出随机值。 但是对于所有输入,我得到1.0作为输出。 为什么会这样?
import tensorflow as tf
from tensorflow import keras
import numpy as np
def NewModel():
return keras.Sequential([
keras.layers.Dense(20, input_shape=(18,), activation=tf.nn.relu, name="inputLayer"),
keras.layers.Dense(1, activation=tf.nn.softmax, name="outputLayer"),
])
model = NewModel()
i = np.array([[0.2]*18])
print(model.predict(i))
您不能将softmax与单个输出神经元一起使用,因为它会通过除以所有神经元的输出进行归一化,从而产生一个恒定的1.0值,这就是您所看到的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.