keras-team / keras-hub

Pretrained model hub for Keras 3
Apache License 2.0
771 stars 233 forks source link

Require `num_classes` to be set when creating a classifier #955

Closed mattdangerw closed 1 year ago

mattdangerw commented 1 year ago

When creating a classifier via from_preset() or the default constructor, we should require num_classes to be passed. This will be consistent with recent updates to keras-cv.

model = BertClassifier.from_preset("bert_base_en_uncased")   # Error, no num_classes.
model = BertClassifier(backbone)  # Error, no num_classes.
mattdangerw commented 1 year ago

The simplest way to do this, which will be consistent with latest on keras-cv, is to simply make num_classes a positional argument with no default.

When creating a class via from_preset(), this will result in an error about a missing positional argument num_classes. This is partially false, we will need num_classes to be passed via keyword, and it could never be passed positionally with from_preset(). But it should be close enough to general UX working.

mattdangerw commented 1 year ago

As part of this change, we should update our README quickstart to take in num_classes.