-
Notifications
You must be signed in to change notification settings - Fork 34
Description
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]])).
modnet/modnet/models/vanilla.py
Lines 196 to 209 in 7ee7d8b
| 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.
modnet/modnet/models/vanilla.py
Lines 347 to 360 in 7ee7d8b
| 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.