--- license: cc-by-nc-4.0 library_name: pytorch pipeline_tag: image-feature-extraction base_model: BVRA/MegaDescriptor-L-384 datasets: - Made-In-Alexandria-AI/ApexID-Dataset tags: - animal-re-identification - re-identification - wildlife - metric-learning - apexid - megadescriptor - swin-transformer --- # ApexID MegaDescriptor-L encoder [Project page](https://mia-ai-team.github.io/ApexID-Hierarchical-Learning-for-Multi-Species-Animal-Re-Identification-Official-Repo/) · [Code](https://github.com/MIA-AI-Team/ApexID-Hierarchical-Learning-for-Multi-Species-Animal-Re-Identification-Official-Repo) · [Dataset](https://huggingface.co/datasets/Made-In-Alexandria-AI/ApexID-Dataset) · Paper: arXiv link coming soon This is the MegaDescriptor-L image encoder from *ApexID: Hierarchical Learning for Multi-Species Animal Re-Identification*, trained with the ApexID Hierarchical Loss. It maps a segmented animal image to an L2-normalized embedding, so individuals of any species can be matched by cosine similarity. In the paper it gives +7.17 Rank-1 over the original MegaDescriptor-L checkpoint and +2.98 over the best baseline loss on the same backbone. The other ApexID encoders are [ApexID_ConvNext_Backbone](https://huggingface.co/Made-In-Alexandria-AI/ApexID_ConvNext_Backbone) and [ApexID_MiewID_Backbone](https://huggingface.co/Made-In-Alexandria-AI/ApexID_MiewID_Backbone). ## Model details | | | | --- | --- | | Architecture | MegaDescriptor-L | | Initialization | [BVRA/MegaDescriptor-L-384](https://huggingface.co/BVRA/MegaDescriptor-L-384) at revision `33b3c6f4ee0c386a4126cc3dcd23843920613fa1` | | Parameters | 195.20M | | Embedding | 1536-d, L2-normalized | | Input | 384 × 384 RGB, normalized with mean (0.5, 0.5, 0.5) and std (0.5, 0.5, 0.5) | | File | `best_backbone.pt` (PyTorch state dict) | | Matching config | [`configs/megadescriptor_l/apexid_hierarchical.yaml`](https://github.com/MIA-AI-Team/ApexID-Hierarchical-Learning-for-Multi-Species-Animal-Re-Identification-Official-Repo/blob/main/configs/megadescriptor_l/apexid_hierarchical.yaml) | ## Usage Install the [ApexID repository](https://github.com/MIA-AI-Team/ApexID-Hierarchical-Learning-for-Multi-Species-Animal-Re-Identification-Official-Repo) and run from its root: ```python import numpy as np import torch from PIL import Image from huggingface_hub import hf_hub_download from apexid.data import build_eval_transforms from apexid.evaluation.embeddings import ApexIDModelAdapter from apexid.utils.config import load_config config = load_config(config_path="configs/megadescriptor_l/apexid_hierarchical.yaml") weights = hf_hub_download("Made-In-Alexandria-AI/ApexID_MegaDescriptor_Backbone", "best_backbone.pt") device = torch.device("cuda" if torch.cuda.is_available() else "cpu") model = ApexIDModelAdapter.from_checkpoint(config, weights, device).model transform = build_eval_transforms(config=config) rgb = np.asarray(Image.open("animal.png").convert("RGB")) # a segmented foreground works best with torch.inference_mode(): embedding = model(transform(image=rgb)["image"][None].to(device)) # shape (1, 1536) ``` ## Results Closed-set retrieval, averaged over four external datasets (ELPephants, GCN-ID, Bristol Gorillas and private jaguar data) and five observation-disjoint split seeds, in percent. All rows use the MegaDescriptor-L backbone. | Model | Rank-1 | mAP | mINP | | --- | ---: | ---: | ---: | | Pretrained MegaDescriptor-L | 54.01 | 23.62 | 10.66 | | ArcFace | 58.20 | 27.13 | 13.05 | | Dynamic ArcFace | 55.44 | 25.51 | 11.75 | | SphereFace2 | 57.13 | 26.61 | 12.47 | | **ApexID Hierarchical (this model)** | 61.18 | 29.07 | 14.69 | Transfer to ELPephants, a category absent from all animal Re-ID training, in percent: | Model | Rank-1 | mAP | | --- | ---: | ---: | | Original MegaDescriptor-L checkpoint | 8.63 | 3.34 | | ApexID Hierarchical (this model) | 13.79 | 4.94 | The [project page](https://mia-ai-team.github.io/ApexID-Hierarchical-Learning-for-Multi-Species-Animal-Re-Identification-Official-Repo/) has the full fourteen-configuration comparison, the open-set evaluation and ScoreCAM maps. ## Intended use and limitations The encoder is meant for research on individual animal re-identification: ranking a gallery of known individuals against a query image, or clustering images of unknown individuals. It works best on segmented foregrounds like those it was trained on. Absolute scores on unseen species remain low, and open-set results vary by dataset, so verify matches with an expert before acting on them. ## Training data The encoder was trained on the ApexID corpus: 132,533 curated images of 13,348 identities from 19 public animal re-identification datasets. See the [dataset card](https://huggingface.co/datasets/Made-In-Alexandria-AI/ApexID-Dataset) for sources, licenses and splits. ## License The ApexID code is MIT-licensed. These weights are fine-tuned from [BVRA/MegaDescriptor-L-384](https://huggingface.co/BVRA/MegaDescriptor-L-384) and keep its CC BY-NC 4.0 license: non-commercial use only, with attribution. ## Citation ```bibtex @article{elkerdany2026apexid, title = {ApexID: Hierarchical Learning for Multi-Species Animal Re-Identification}, author = {Elkerdany, Seifeldin and ElBassat, Mohamed and Abouelhamd, Gamal and Elkady, Assem and Ghoneim, Jana and Mahmood, Matin and Martin, Abigail Allen and de Melo, Gerard and Rueda-Toicen, Antonio}, journal = {arXiv preprint}, year = {2026} } ```