You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Keras多标签多分类模型预测结果的类别对应关系确认

Answer

Absolutely, the order of the arrays returned by model.predict(test_data) matches exactly the order in which you defined your output layers in the model architecture.

Let's break this down with your specific setup:

  • Your model ends with three Dense(1) layers added in the sequence: first for Class1, then Class2, finally Class3.
  • So the three (num_samples, 1) ndarrays you get back will correspond to:
    • First array: Predictions for Class1
    • Second array: Predictions for Class2
    • Third array: Predictions for Class3

This is a consistent, default behavior in Keras for multi-output models. The framework tracks each output tensor in the exact order you add them during model construction—this applies to both training (when mapping loss functions to outputs) and inference (when returning predictions).

A handy tip to avoid any confusion down the line: name your output layers explicitly when defining them, like this:

# ... after GRU2 layer ...
output_class1 = Dense(1, name="pred_class1")(gru2_output)
output_class2 = Dense(1, name="pred_class2")(gru2_output)
output_class3 = Dense(1, name="pred_class3")(gru2_output)

model = Model(inputs=input_layer, outputs=[output_class1, output_class2, output_class3])

Then you can use return_dict=True in predict() to get a dictionary where keys are your layer names and values are the corresponding prediction arrays:

predictions = model.predict(test_data, return_dict=True)
# Access predictions like predictions["pred_class1"], predictions["pred_class2"], etc.

This makes your code more readable and eliminates any ambiguity about which prediction corresponds to which class.

内容的提问来源于stack exchange,提问作者shanlodh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 04:17:44