Skip to content

Add a model family

A model family converts a trial's architecture parameters and a ModelBuildContext into a Keras model. The context supplies the dataset's input shape and dtype and the task's target specification.

  1. Create a ModelFamilyABC subclass under src/crest/model_families/. Implement sample_hparams(trial, ctx, config) and build_model(hparams, ctx, config). Return an uncompiled model for the task to compile.
  2. Validate family settings with validate_config and sampled or replayed choices with validate_hparams. Use decode_trial_hparams if saved values need rebuilding. For explicit proposers, implement trial_search_space(ctx, config) with the same names, bounds, and choices that sample_hparams uses.
  3. Check the export path. The base class can build an untrained model or load a trained checkpoint. Override materialize_export_model for family-specific transformations and supply custom_objects() if checkpoints use custom Keras types.
  4. Register the family with model_family_registry in builtin_components.py. Select it under model.family, set the export variant in model.params.export_variant, and put search overrides in model.search.

For example, both the Portenta and STM32 audio studies select the DS-CNN family and export a model with untrained weights. Each study configures its board separately.

model:
  family: audio_dscnn
  params:
    export_variant: untrained
  search: {}

See audio DS-CNN for categorical search overrides and odometry TCN for a custom export transformation. Test sampling and output shape with a small context, then try the export on the intended backend. The DS-CNN tests and TCN tests show both families in use.

Read the API reference

For more information, read the full model-family README on GitHub.