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
File size: 3,833 Bytes
17124c2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | 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()
|