Image Classification
Keras
LiteRT
English
computer-vision
satellite-imagery
tensorflow
remote-sensing
land-cover-classification
Instructions to use Mirutex/Celyrix-1.0-Vision with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use Mirutex/Celyrix-1.0-Vision with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://Mirutex/Celyrix-1.0-Vision") - Notebooks
- Google Colab
- Kaggle
Download src/train.py from Mirutex/Celyrix-1.0-Vision: direct link, hf CLI and curl.
- Browser
- Download file 3.83 kB
-
https://huggingface.co/Mirutex/Celyrix-1.0-Vision/resolve/main/src/train.py
- Command line
-
hf download hf://Mirutex/Celyrix-1.0-Vision/src/train.py
-
curl -L -o train.py https://huggingface.co/Mirutex/Celyrix-1.0-Vision/resolve/main/src/train.py
3.83 kB
| import argparse | |
| import importlib.metadata | |
| import json | |
| import time | |
| from pathlib import Path | |
| import numpy as np | |
| import yaml | |
| from src.common import CLASSES, configure | |
| from src.dataset import load_data, pipeline | |
| from src.model import build_model | |
| def main(): | |
| p = argparse.ArgumentParser( | |
| description="Train CELYRIX from scratch on real EuroSAT RGB." | |
| ) | |
| p.add_argument("--config", default="configs/training.yaml") | |
| for key, typ in [ | |
| ("batch-size", int), | |
| ("epochs", int), | |
| ("learning-rate", float), | |
| ("seed", int), | |
| ("sample-limit", int), | |
| ]: | |
| p.add_argument("--" + key, type=typ) | |
| p.add_argument("--output-dir") | |
| args = vars(p.parse_args()) | |
| cfg = yaml.safe_load(Path(args.pop("config")).read_text()) | |
| cfg.update({k: v for k, v in args.items() if v is not None}) | |
| if cfg["sample_limit"] and cfg["sample_limit"] < 5: | |
| p.error("sample limit must be at least five") | |
| device = configure(cfg["seed"]) | |
| import tensorflow as tf | |
| out = Path(cfg["output_dir"]) | |
| out.mkdir(parents=True, exist_ok=True) | |
| start = time.monotonic() | |
| splits, provenance = load_data(cfg["data_dir"], cfg["seed"]) | |
| x, y = splits["train"] | |
| if cfg["sample_limit"] and cfg["sample_limit"] < len(y): | |
| from sklearn.model_selection import train_test_split | |
| selected, _ = train_test_split( | |
| np.arange(len(y)), | |
| train_size=cfg["sample_limit"], | |
| stratify=y, | |
| random_state=cfg["seed"], | |
| ) | |
| x, y = x[selected], y[selected] | |
| provenance["training_subset"] = selected.tolist() | |
| model = build_model(cfg["seed"]) | |
| model.compile( | |
| optimizer=tf.keras.optimizers.Adam(cfg["learning_rate"]), | |
| loss="sparse_categorical_crossentropy", | |
| metrics=["accuracy"], | |
| ) | |
| model.summary() | |
| history = model.fit( | |
| pipeline(x, y, cfg["batch_size"], True, cfg["seed"]), | |
| validation_data=pipeline(*splits["validation"], cfg["batch_size"]), | |
| epochs=cfg["epochs"], | |
| callbacks=[ | |
| tf.keras.callbacks.ModelCheckpoint( | |
| str(out / "model.keras"), monitor="val_loss", save_best_only=True | |
| ), | |
| tf.keras.callbacks.EarlyStopping( | |
| monitor="val_loss", patience=cfg["patience"], restore_best_weights=True | |
| ), | |
| tf.keras.callbacks.ReduceLROnPlateau( | |
| monitor="val_loss", factor=0.5, patience=3, min_lr=1e-5 | |
| ), | |
| tf.keras.callbacks.CSVLogger(str(out / "training.csv")), | |
| ], | |
| verbose=2, | |
| shuffle=False, | |
| ) | |
| (out / "history.json").write_text(json.dumps(history.history, indent=2)) | |
| (out / "class_mapping.json").write_text( | |
| json.dumps(dict(enumerate(CLASSES)), indent=2) | |
| ) | |
| (out / "provenance.json").write_text(json.dumps(provenance, indent=2)) | |
| (out / "training_config.json").write_text(json.dumps(cfg, indent=2)) | |
| versions = { | |
| d.metadata["Name"]: d.version for d in importlib.metadata.distributions() | |
| } | |
| (out / "environment.json").write_text( | |
| json.dumps({"packages": versions, **device}, indent=2) | |
| ) | |
| (out / "training_summary.json").write_text( | |
| json.dumps( | |
| { | |
| "duration_seconds": time.monotonic() - start, | |
| "epochs_completed": len(history.epoch), | |
| "best_epoch": int(np.argmin(history.history["val_loss"])) + 1, | |
| "training_samples": len(y), | |
| "parameters": model.count_params(), | |
| "model_bytes": (out / "model.keras").stat().st_size, | |
| "initialization": "random; no pretrained weights", | |
| }, | |
| indent=2, | |
| ) | |
| ) | |
| print("Saved real trained model:", out / "model.keras") | |
| if __name__ == "__main__": | |
| main() | |