Package: wildlife-tools
A tool-kit for Wildlife Individual Identification that provides a wide variety of pre-trained models for inference and fine-tuning.Documentation·Report Bug·Request FeatureOur other projectsMegaDescriptorWildlife DatasetsIntroductionThewildlife-toolslibrary offers a simple interface for various tasks in the Wildlife Re-Identification domain. It covers use cases such as training, feature extraction, similarity calculation, image retrieval, and classification. It complements thewildlife-datasetslibrary, which acts as dataset repository. All datasets there can be used in combination withWildlifeDatasetcomponent, which serves for loading extracting images and image tensors other tasks.More information can be found inDocumentationInstallationTo installwildlife-tools, you can build it from scratch or use pre-build Pypi package.Using Pypipip install wildlife-toolsBuilding from scratchClone the repository usinggitand install it.git clone git@github.com:WildlifeDatasets/wildlife-tools.git

cd wildlife-tools
pip install -e .Modules in the in thewildlife-toolsThedatamodule provides tools for creating instances of theWildlifeDataset.Thetrainmodule offers tools for fine-tuning feature extractors on theWildlifeDataset.Thefeaturesmodule provides tools for extracting features from theWildlifeDatasetusing various extractors.Thesimilaritymodule provides tools for constructing a similarity matrix from query and database features.Theinferencemodule offers tools for creating predictions using the similarity matrix.Relations between modules:graph TD;
      A[Data]-->|WildlifeDataset|B[Features]
      A-->|WildlifeDataset|C;
      C[Train]-->|finetuned extractor|B;
      B-->|query and database features|D[Similarity]
      D-->|similarity matrix|E[Inference]Example1. CreateWildlifeDatasetUsing metadata fromwildlife-datasets, createWildlifeDatasetobject for the MacaqueFaces dataset.fromwildlife_datasets.datasetsimportMacaqueFacesfromwildlife_tools.dataimportWildlifeDatasetimporttorchvision.transformsasTmetadata=MacaqueFaces('datasets/MacaqueFaces')transform=T.Compose([T.Resize([224,224]),T.ToTensor(),T.Normalize(mean=(0.485,0.456,0.406),std=(0.229,0.224,0.225))])dataset=WildlifeDataset(metadata.df,metadata.root,transform=transform)Optionally, split metadata into subsets. In this example, query is first 100 images and rest are in database.dataset_database=WildlifeDataset(metadata.df.iloc[100:,:],metadata.root,transform=transform)dataset_query=WildlifeDataset(metadata.df.iloc[:100,:],metadata.root,transform=transform)2. Extract featuresExtract features using MegaDescriptor Tiny, downloaded from HuggingFace hub.fromwildlife_tools.featuresimportDeepFeaturesname='hf-hub:BVRA/MegaDescriptor-T-224'extractor=DeepFeatures(timm.create_model(name,num_classes=0,pretrained=True))query,database=extractor(dataset_query),extractor(dataset_database)3. Calculate similarityCalculate cosine similarity between query and database deep features.fromwildlife_tools.similarityimportCosineSimilaritysimilarity_function=CosineSimilarity()similarity=similarity_function(query,database)4. EvaluateUse the cosine similarity in nearest neigbour classifier and get predictions.classifier=KnnClassifier(k=1,database_labels=dataset_database.labels_string)predictions=classifier(similarity['cosine'])accuracy=np.mean(dataset_database.labels_string==predictions)CitationIf you like our package, please cite us.@InProceedings{Cermak_2024_WACV,
    author    = {\v{C}erm\'ak, Vojt\v{e}ch and Picek, Luk\'a\v{s} and Adam, Luk\'a\v{s} and Papafitsoros, Kostas},
    title     = {{WildlifeDatasets: An Open-Source Toolkit for Animal Re-Identification}},
    booktitle = {Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (WACV)},
    month     = {January},
    year      = {2024},
    pages     = {5953-5963}
}