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

一切似乎都很好,定义良好,但是当我适合模型时,它会错误地说“ValueError:参数target并且output必须具有相同的排名(ndim)。收到:target.shape =(None,),output.shape =(None , 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 个数字,即预期类别,但我怀疑它正在输出每个类别的概率。

1

  • 看一下。这可以处理标签编码的目标。也许您还必须重塑标签以具有附加轴,因为它们应该具有 shape (None, 1)


    – 

$(function() {
$(“.js-gps-inline-related-questions .spacer”).on(“click”, function () {
fireRelatedEvent($(this).index() + 1, $(this).data(‘question-id’));
});

function fireRelatedEvent(position, questionId) {
StackExchange.using(“gps”, function() {
StackExchange.gps.track(‘related_questions.click’,
{
position: position,
originQuestionId: 78365339,
relatedQuestionId: +questionId,
location: ‘inline’,
source: ‘Baseline_Fallback’
});
});
}
});

function toggleInlineRelated(showMore) {
var inlineRelatedLess = document.getElementById(“inline_related_var_a_less”);
var inlineRelatedMore = document.getElementById(“inline_related_var_a_more”);

var inlineRelatedSeeMore = document.getElementById(“inline_related_see_more”);
var inlineRelatedSeeLess = document.getElementById(“inline_related_see_less”);

if (showMore) {
inlineRelatedLess.classList.add(“d-none”);
inlineRelatedSeeMore.classList.add(“d-none”);

inlineRelatedMore.classList.remove(“d-none”);
inlineRelatedSeeLess.classList.remove(“d-none”);
}
else {
inlineRelatedMore.classList.add(“d-none”);
inlineRelatedSeeLess.classList.add(“d-none”);

inlineRelatedLess.classList.remove(“d-none”);
inlineRelatedSeeMore.classList.remove(“d-none”);
}
}

0