Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么我的准确度和损失,0.000和nan,在keras中?_Python_Tensorflow_Machine Learning_Keras_Conv Neural Network - Fatal编程技术网

Python 为什么我的准确度和损失,0.000和nan,在keras中?

Python 为什么我的准确度和损失,0.000和nan,在keras中?,python,tensorflow,machine-learning,keras,conv-neural-network,Python,Tensorflow,Machine Learning,Keras,Conv Neural Network,我的理解是“稀疏分类交叉熵”适合我的多重分类,而不需要一个热编码案例。我还降低了adam学习速度,以防超出预测 我不确定我不理解的是我做得不对 我的输入数据如下所示: 我的输出预测结果是标签:[1 2 3 4 5 6 7 8 9 10](不是一个热编码)。每个数字代表我希望网络最终选择的数字 print(x_train.shape) print(x_test.shape) x_train = x_train.reshape(x_train.shape[0], round(x_train.sha

我的理解是“稀疏分类交叉熵”适合我的多重分类,而不需要一个热编码案例。我还降低了adam学习速度,以防超出预测

我不确定我不理解的是我做得不对

我的输入数据如下所示:

我的输出预测结果是标签:[1 2 3 4 5 6 7 8 9 10](不是一个热编码)。每个数字代表我希望网络最终选择的数字

print(x_train.shape)
print(x_test.shape)
x_train = x_train.reshape(x_train.shape[0], round(x_train.shape[1]/5), 5)
x_test = x_test.reshape(x_test.shape[0], round(x_test.shape[1]/5), 5)
print(x_train.shape)
print(np.unique(y_train))
print(len(np.unique(y_train)))

input_shape = (x_train.shape[1], 5)

adam = keras.optimizers.Adam(learning_rate=0.0001)

model = Sequential()
model.add(Conv1D(512, 5, activation='relu', input_shape=input_shape))
model.add(Conv1D(512, 5, activation='relu'))
model.add(MaxPooling1D(3))
model.add(Conv1D(512, 5, activation='relu'))
model.add(Conv1D(512, 5, activation='relu'))
model.add(GlobalAveragePooling1D())
model.add(Dropout(0.5))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='sparse_categorical_crossentropy', optimizer=adam, metrics=['accuracy'])
    
model.fit(x_train, y_train, batch_size=32, epochs=25, validation_data=(x_test, y_test))
print(model.summary())
以下是错误结果:

模型层(如果有帮助):


我认为您的方法存在两个主要问题

您的标签从1到10。。。它们必须从0开始,才能在0-9范围内。只需执行
y\u-train-1
y\u-test-1
(如果y\u-test和y\u-train是numpy阵列)即可实现这一点

网络的最后一层必须是密集的(10,activation='softmax'),其中10是要预测的类数,softmax用于生成多类问题的概率


使用
sparse\u categorical\u crossentropy
是可以的,因为您有整数编码的目标

,所以您似乎有10个类要预测,1个密集输出和sigmoid?您能显示
y序列的样本吗?除了单个类的输出,还不清楚输入是否是稀疏的