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: 2,267 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 | """Export an inference-only float16 TFLite model and verify parity."""
import argparse
import json
from pathlib import Path
import numpy as np
from src.common import configure
def main():
p = argparse.ArgumentParser()
p.add_argument("--model-dir", default="artifacts/release")
args = p.parse_args()
configure()
import tensorflow as tf
out = Path(args.model_dir)
model = tf.keras.models.load_model(out / "model.keras", compile=False)
# Rebuild graph with training=False so augmentation/dropout never enter inference graph.
inputs = tf.keras.Input((64, 64, 3), batch_size=1)
inference = tf.keras.Model(inputs, model(inputs, training=False))
converter = tf.lite.TFLiteConverter.from_keras_model(inference)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.target_spec.supported_types = [tf.float16]
data = converter.convert()
(out / "model.float16.tflite").write_bytes(data)
interpreter = tf.lite.Interpreter(model_content=data)
interpreter.allocate_tensors()
from src.dataset import load_data
cfg = json.loads((out / "training_config.json").read_text())
splits, _ = load_data(cfg["data_dir"], cfg["seed"])
samples = splits["test"][0][:16].astype("float32")
errors = []
for image in samples:
x = image[None]
interpreter.set_tensor(interpreter.get_input_details()[0]["index"], x)
interpreter.invoke()
actual = interpreter.get_tensor(interpreter.get_output_details()[0]["index"])
expected = np.asarray(inference(x, training=False))
errors.append(float(np.max(np.abs(actual - expected))))
if not np.allclose(actual, expected, atol=0.005):
raise RuntimeError(f"TFLite parity failed: {errors[-1]}")
delta = max(errors)
(out / "export.json").write_text(
json.dumps(
{
"format": "TFLite float16",
"bytes": len(data),
"max_absolute_error": delta,
"parity_input": "first 16 held-out test patches",
"samples": len(samples),
},
indent=2,
)
)
print("TFLite export verified:", len(data), "bytes; max error", delta)
if __name__ == "__main__":
main()
|