Skip to content

Vector output not possible for multitarget classification #246

@kaueltzen

Description

@kaueltzen

Hi, I noticed this issue while implementing multitarget classification in #245 .

At the moment, training a multitarget classification MODNetModel with a single output vector targets like this: [[["cl_target_0","cl_target_1"]]]
will only train on the first target and discard the others.

First, in the build_model method, the output shape is set to (None, num_classes[group[prop_idx][0]]) instead of (None, sum([v for k, v in num_classes.items() if k in group[prop_idx]])).

n = num_classes[group[prop_idx][0]]
name = group[prop_idx][0]
if n >= 2:
out = tf.keras.layers.Dense(
n,
activation="sigmoid" if multi_label else "softmax",
name=name,
)(previous_layer)
else:
out = tf.keras.layers.Dense(
len(group[prop_idx]),
activation=out_act,
name=name,
)(previous_layer)

In the fit method, only the first target is converted to y.

for prop in self.targets_groups:
if self.num_classes[prop[0]] >= 2: # Classification
targ = prop[0]
if self.multi_label:
y_inner = np.stack(training_data.df_targets[targ].values)
if loss is None:
loss = "binary_crossentropy"
else:
y_inner = tf.keras.utils.to_categorical(
training_data.df_targets[targ].values,
num_classes=self.num_classes[targ],
)
if loss is None:
loss = "categorical_crossentropy"

I'd either correct this or add in the documentation that multitarget classification should be done with separate output layers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions