FED Encoders¶
ECG foundation-model encoder adapters for Fréchet ECG Distance (FED).
Each adapter exposes a single encode(signals) method:
signals : np.ndarray, shape (N, L, T)
N recordings × L leads × T timepoints.
returns : np.ndarray, shape (N, D)
One embedding vector per recording.
Weights are downloaded from HuggingFace on first use and cached in the
default HuggingFace cache directory (~/.cache/huggingface).
Set the HF_HOME environment variable to change the cache location.
Supported backbone names
"ecgfounder"— ECGFounder (PKUDigitalHealth/ECGFounder, RegNet, 10.7 M ECGs)"hubert_ecg"— HuBERT-ECG (Edoardo-BS/hubert-ecg-base, Transformer, 9.1 M ECGs)"ecgfm"— ECG-FM (bowang-lab/ECG-FM, wav2vec2-style, 1.5 M ECGs)
get_encoder
¶
Return an initialised encoder adapter for the requested backbone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
One of |
required |
device
|
str
|
PyTorch device string, e.g. |
'cpu'
|
batch_size
|
int
|
Number of recordings to process per forward pass. |
32
|
Returns:
| Type | Description |
|---|---|
An encoder object with an ``encode(signals: np.ndarray) -> np.ndarray`` method.
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If name is not a recognised backbone. |
ImportError
|
If |
Source code in ecgen_eval/metrics/encoders/__init__.py
Adapters¶
ECGFounderEncoder
¶
Lazy-loading encoder wrapper for ECGFounder.
The HuggingFace checkpoint is downloaded only when encode() is called
for the first time (or when the object is first constructed if
preload=True).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
str
|
PyTorch device ( |
'cpu'
|
batch_size
|
int
|
Recordings per forward pass. |
32
|
preload
|
bool
|
If |
False
|
Source code in ecgen_eval/metrics/encoders/ecgfounder.py
encode
¶
Encode ECG signals into embedding vectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signals
|
(ndarray, shape(N, L, T))
|
|
required |
Returns:
| Type | Description |
|---|---|
(ndarray, shape(N, D))
|
|
Source code in ecgen_eval/metrics/encoders/ecgfounder.py
HuBERTECGEncoder
¶
HuBERTECGEncoder(device: str = 'cpu', batch_size: int = 32, variant: str = 'base', preload: bool = False)
Lazy-loading encoder wrapper for HuBERT-ECG.
The HuggingFace checkpoint is downloaded only when encode() is called
for the first time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
str
|
PyTorch device ( |
'cpu'
|
batch_size
|
int
|
Recordings per forward pass. |
32
|
variant
|
str
|
|
'base'
|
preload
|
bool
|
If |
False
|
Source code in ecgen_eval/metrics/encoders/hubert_ecg.py
encode
¶
Encode ECG signals into embedding vectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signals
|
(ndarray, shape(N, L, T))
|
|
required |
Returns:
| Type | Description |
|---|---|
(ndarray, shape(N, D))
|
|
Source code in ecgen_eval/metrics/encoders/hubert_ecg.py
ECGFMEncoder
¶
Lazy-loading encoder wrapper for ECG-FM.
The HuggingFace checkpoint is downloaded only when encode() is called
for the first time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
str
|
PyTorch device ( |
'cpu'
|
batch_size
|
int
|
Recordings per forward pass. |
32
|
preload
|
bool
|
If |
False
|
Source code in ecgen_eval/metrics/encoders/ecgfm.py
encode
¶
Encode ECG signals into embedding vectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signals
|
(ndarray, shape(N, L, T))
|
|
required |
Returns:
| Type | Description |
|---|---|
(ndarray, shape(N, D))
|
|