参数“target”和“output”必须具有相同的等级(ndim)

问题描述 投票:0回答:1

我正在使用多输出张量流模型,仅用于学习目的,该模型应输出 1 个数值数据和 1 个分类数据(6 个类别)。

一切似乎都很好,定义明确,但是当我拟合模型时,它错误地说“ValueError:参数

target
output
必须具有相同的排名(ndim)。收到:target.shape =(无,) , 输出.shape=(无, 6)"

为了简单起见,在输出层我有:

layers.Dense(1, activation='relu', name="output_numerical")(x)
layers.Dense(6, activation='softmax', name="output_categorical")(x)

模型编译为:

losses = {'output_numerical': 'mse', 'output_categorical': 'categorical_crossentropy'}
loss_weights = {'output_numerical': 1.0, 'output_categorical': 1.0}
model.compile(optimizer=optimizer, loss=losses, loss_weights=loss_weights)

最后是特征 x 和标签 y 的样本:

input_numerical | input_categorical
1.0 | 1
1.1 | 0
1.2 | 3
1.5 | 5
....
output_numerical| output_categorical
2.0 | 5
1.1 | 4
3.2 | 3
4.5 | 2
....

谁能帮我解决这个问题吗?

我预计 softmax 仅输出 1 个数字,即预期类别,但我怀疑它正在输出每个类别的概率。

python tensorflow
1个回答
0
投票

了解数据的形状非常重要

存在 (vector int) 的 Categorical_crossentropy https://www.tensorflow.org/api_docs/python/tf/keras/losses/categorical_crossentropy [[1,2,3],[0,1,0]] 和 Space_categorical_crossentropy 数据 https://www.tensorflow.org/api_docs/python/tf/keras/losses/SparseCategoricalCrossentropy(数字类) [[0,0,1,2]]

© www.soinside.com 2019 - 2024. All rights reserved.