|
| 1 | +import pathlib |
| 2 | +import urllib.request |
| 3 | + |
| 4 | +import numpy as np |
| 5 | +import pytest |
| 6 | + |
| 7 | +from cebra.integrations.sklearn.cebra import CEBRA |
| 8 | + |
| 9 | +MODEL_VARIANTS = [ |
| 10 | + "cebra-0.4.0-scikit-learn-1.4", "cebra-0.4.0-scikit-learn-1.6", |
| 11 | + "cebra-rc-scikit-learn-1.4", "cebra-rc-scikit-learn-1.6" |
| 12 | +] |
| 13 | + |
| 14 | + |
| 15 | +@pytest.mark.parametrize("model_variant", MODEL_VARIANTS) |
| 16 | +def test_load_legacy_model(model_variant): |
| 17 | + """Test loading a legacy CEBRA model.""" |
| 18 | + |
| 19 | + X = np.random.normal(0, 1, (1000, 30)) |
| 20 | + |
| 21 | + model_path = pathlib.Path( |
| 22 | + __file__ |
| 23 | + ).parent / "_build_legacy_model" / f"cebra_model_{model_variant}.pt" |
| 24 | + |
| 25 | + if not model_path.exists(): |
| 26 | + url = f"https://cebra.fra1.digitaloceanspaces.com/cebra_model_{model_variant}.pt" |
| 27 | + urllib.request.urlretrieve(url, model_path) |
| 28 | + |
| 29 | + loaded_model = CEBRA.load(model_path) |
| 30 | + |
| 31 | + assert loaded_model.model_architecture == "offset10-model" |
| 32 | + assert loaded_model.output_dimension == 8 |
| 33 | + assert loaded_model.num_hidden_units == 16 |
| 34 | + assert loaded_model.time_offsets == 10 |
| 35 | + |
| 36 | + output = loaded_model.transform(X) |
| 37 | + assert isinstance(output, np.ndarray) |
| 38 | + assert output.shape[1] == loaded_model.output_dimension |
| 39 | + |
| 40 | + assert hasattr(loaded_model, "state_dict_") |
| 41 | + assert hasattr(loaded_model, "n_features_") |
0 commit comments