coco_pipe.decoding.foundation_models.estimators#
Clone-safe sklearn estimators backed by lazily loaded foundation models.
Classes#
Target-independent frozen feature extractor suitable for sklearn pipelines. |
|
Lazy trainable foundation-model classifier with grouped validation. |
Functions#
Empty the shared frozen-backbone embedding cache. |
Module Contents#
- coco_pipe.decoding.foundation_models.estimators.clear_frozen_embedding_cache()#
Empty the shared frozen-backbone embedding cache.
- Return type:
None
- class coco_pipe.decoding.foundation_models.estimators.FrozenBackboneTransformer(model_key, backend='auto', device='auto', pooling='mean', sfreq=None, ch_names=None, cache_embeddings=False, backend_kwargs=None)#
Bases:
sklearn.base.BaseEstimator,sklearn.base.TransformerMixinTarget-independent frozen feature extractor suitable for sklearn pipelines.
- Parameters:
- backend_ = None#
- prepared_ = None#
- backend = 'auto'#
- device = 'auto'#
- pooling = 'mean'#
- sfreq = None#
- ch_names = None#
- cache_embeddings = False#
- backend_kwargs = None#
- fit(X, y=None)#
- Parameters:
X (numpy.ndarray)
y (numpy.ndarray | None)
- transform(X)#
- Parameters:
X (numpy.ndarray)
- Return type:
- release_memory()#
Release the fitted backend’s torch modules (see BackendBase).
- Return type:
None
- class coco_pipe.decoding.foundation_models.estimators.FoundationClassifier(model_key, backend='auto', train_mode='full', device='auto', n_outputs=None, sfreq=None, ch_names=None, trainer=None, lora=None, backend_kwargs=None, checkpoints=None, class_weight='balanced', random_state=42)#
Bases:
sklearn.utils.metadata_routing.AutoRequestMixin,sklearn.base.ClassifierMixin,sklearn.base.BaseEstimatorLazy trainable foundation-model classifier with grouped validation.
- Parameters:
- backend_ = None#
- prepared_ = None#
- checkpoint_path_ = None#
- backend = 'auto'#
- train_mode = 'full'#
- device = 'auto'#
- n_outputs = None#
- sfreq = None#
- ch_names = None#
- trainer = None#
- lora = None#
- backend_kwargs = None#
- checkpoints = None#
- class_weight = 'balanced'#
- random_state = 42#
- get_metadata_routing()#
Ask for each window’s group in
fit(its sample weight is asked for throughAutoRequestMixin).
- fit(X, y, groups=None, sample_weight=None)#
Fine-tune the model on labelled windows.
- Parameters:
X (np.ndarray of shape (n_windows, n_channels, n_times)) – Windows in microvolts.
y (np.ndarray of shape (n_windows,)) – Class labels.
groups (np.ndarray of shape (n_windows,), optional) – The group (e.g. subject) of each window: the validation split keeps each group on one side.
sample_weight (np.ndarray of shape (n_windows,), optional) – Weights of each window’s loss, rescaled to average 1, e.g.
coco_pipe.utils.balanced_sample_weights(). Needsclass_weight=None.
- Returns:
self
- Return type:
- Raises:
ValueError – If
sample_weightis given with aclass_weight.
- restore_checkpoint(path=None)#
Restore every saved backend component into this fitted estimator.
- Parameters:
path (str | pathlib.Path | None)
- predict(X)#
- Parameters:
X (numpy.ndarray)
- Return type:
- predict_proba(X)#
- Parameters:
X (numpy.ndarray)
- Return type:
- transform(X)#
Return the window embeddings of the fitted backbone.
The vector
FrozenBackboneTransformergives, here from the weights this fit left; for CTNet, Deep4Net, EEGNet and ShallowFBCSPNet, the flattened input of their final layer. WithExperimentConfig(keep_test_embeddings=True), each outer fold keeps those of its test rows.- Parameters:
X (numpy.ndarray)
- Return type:
- release_memory()#
Release the fitted backend’s torch modules (see BackendBase).
- Return type:
None