Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vector output not possible for multitarget classification #246

Open
kaueltzen opened this issue Nov 21, 2024 · 0 comments
Open

Vector output not possible for multitarget classification #246

kaueltzen opened this issue Nov 21, 2024 · 0 comments

Comments

@kaueltzen
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant