--- license: cc-by-nc-sa-4.0 pipeline_tag: image-feature-extraction tags: [numismatics, coins, ancient-coins, image-retrieval, dinov2, onnx] base_model: - timm/vit_base_patch14_reg4_dinov2.lvd142m - timm/vit_small_patch14_reg4_dinov2.lvd142m --- # Sema 1.0 Sema identifies the type of an ancient coin from a photograph of one side. It was made for [Solidi](https://github.com/Angoooose/solidi), a catalogue of ancient coin types built from Nomisma.org and the museum collections linked to it. It is two models fine-tuned from DINOv2. **Sema 1 Small** turns a photograph into a vector, and is small enough to run in a web browser. The **search index** holds one vector for each side of 28,137 coin types, made with the larger **Sema 1 Base** from the photographs of every coin of that type. Identifying a coin is finding the nearest vectors. ## Files | Path | What it is | |---|---| | `browser/model-int8.onnx` | Sema 1 Small in ONNX, weights stored as one byte each, with the index's turn built in: 224px pixels in, a unit vector out | | `browser/index.bin`, `browser/index.json` | the search index, product-quantised, and how to read it | | `browser/manifest.json` | the release: every file's size and sha256 | | `small/model.safetensors`, `small/config.json` | Sema 1 Small: `vit_small_patch14_reg4_dinov2.lvd142m` at 224px, with a layer into Sema 1 Base's space (384 to 768 numbers) | | `base/model.safetensors`, `base/config.json` | Sema 1 Base: `vit_base_patch14_reg4_dinov2.lvd142m` at 336px | The `browser/` folder is the release exactly as Solidi's site serves it. Its index can only be searched with the ONNX model next to it, which ends with the same turn. The safetensors weights give the models' raw vectors, for further training or other uses. ## How well it works Graded on 5,770 coins from 9 collections that were never trained on or indexed, so no test coin shares a photographer, background or lighting with the index. Each was searched among all 28,137 types using both of its sides, with the browser's model (model-int8.onnx) through ONNX Runtime: | Measure | Score | |---|---| | Right type first | 52.9% | | Right type in the first 10 | 83.7% | | Right design in the first 10 | 92.5% | A design groups types with the same denomination, portrait and reverse description; many types differ only in a mint mark or an officina letter, which a photograph may not show. Sema knows only the types with photographed coins in the collections below, mostly Roman and Greek. It expects one side of one coin, cropped close. ## Use ```python import json import numpy as np import onnxruntime from huggingface_hub import snapshot_download from PIL import Image folder = snapshot_download("solidiorg/sema", revision="v1.0", allow_patterns="browser/*") model = onnxruntime.InferenceSession(f"{folder}/browser/model-int8.onnx") layout = json.load(open(f"{folder}/browser/index.json")) raw = open(f"{folder}/browser/index.bin", "rb").read() # The index: patterns [parts, patterns, width] as 32-bit numbers, then one byte per part for # every type's obverse, then every type's reverse. parts, count = layout["parts"], layout["patterns"] width = layout["dims"] // parts cut = parts * count * width * 4 patterns = np.frombuffer(raw[:cut], "