Spaces:
Sleeping
Sleeping
Download ml/common/model_loader.py from HighFive52/ml-api: direct link, hf CLI and curl.
- Browser
- Download file 881 Bytes
-
https://huggingface.co/spaces/HighFive52/ml-api/resolve/main/ml/common/model_loader.py
- Command line
-
hf download hf://spaces/HighFive52/ml-api/ml/common/model_loader.py
-
curl -L -o model_loader.py https://huggingface.co/spaces/HighFive52/ml-api/resolve/main/ml/common/model_loader.py
881 Bytes
| import joblib | |
| import os | |
| import torch | |
| from ml.spaceship.spaceship_transformers import ( | |
| LogicalImputeTransformer, | |
| FeatureEngineer, | |
| Log1pTransformer, | |
| to_str, | |
| ) | |
| from ml.digits.mnist_model import MNISTModel | |
| def load_spaceship_models(models_dir): | |
| tuned_models = {} | |
| model_names = ["xgb_tuned", "lgbm_tuned", "hgb_tuned"] | |
| for name in model_names: | |
| path = os.path.join(models_dir, "spaceship", f"{name}.pkl") | |
| tuned_models[name] = joblib.load(path) | |
| return tuned_models | |
| def load_digit_model(models_dir): | |
| checkpoint = torch.load( | |
| os.path.join(models_dir, "digit_recognizer", "mnist_checkpoint.pth"), | |
| map_location="cpu", | |
| ) | |
| model = MNISTModel(dropout_rate=checkpoint["dropout"]) | |
| model.load_state_dict(checkpoint["model_state_dict"]) | |
| model.eval() | |
| return model | |