Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

GitHub issues GitHub pull requests GitHub contributors GitHub forks GitHub stars GitHub watchers License

Project logo

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 Feature

Our other projects

Introduction

The wildlife-tools library 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 the wildlife-datasets library, which acts as dataset repository. All datasets there can be used in combination with WildlifeDataset component, which serves for loading extracting images and image tensors other tasks.

More information can be found in Documentation

Installation

To install wildlife-tools, you can build it from scratch or use pre-build Pypi package.

Using Pypi

pip install wildlife-tools

Building from scratch

Clone the repository using git and install it.

git clone git@github.com:WildlifeDatasets/wildlife-tools.git

cd wildlife-tools
pip install -e .

Modules in the in the wildlife-tools

  • The data module provides tools for creating instances of the WildlifeDataset.
  • The train module offers tools for fine-tuning feature extractors on the WildlifeDataset.
  • The features module provides tools for extracting features from the WildlifeDataset using various extractors.
  • The similarity module provides tools for constructing a similarity matrix from query and database features.
  • The inference module 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]

Example

1. Create WildlifeDataset

Using metadata from wildlife-datasets, create WildlifeDataset object for the MacaqueFaces dataset.

from wildlife_datasets.datasets import MacaqueFaces
from wildlife_tools.data import WildlifeDataset
import torchvision.transforms as T

metadata = 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 features

Extract features using MegaDescriptor Tiny, downloaded from HuggingFace hub.

from wildlife_tools.features import DeepFeatures

name = '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 similarity

Calculate cosine similarity between query and database deep features.

from wildlife_tools.similarity import CosineSimilarity

similarity_function = CosineSimilarity()
similarity = similarity_function(query, database)

4. Evaluate

Use 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)

Citation

If 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}
}

Metadata

Release files for wildlife-tools 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wildlife-tools 0.0.9
File Size Uploaded Provenance
wildlife-tools-0.0.9.tar.gz 22.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for wildlife-tools 0.0.9
File Interpreter ABI Platform
wildlife_tools-0.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 47.8 kB

Release files / wildlife-tools-0.0.9.tar.gz

Download URL wildlife-tools-0.0.9.tar.gz
Size 22.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6800b8282149a6af75c07d8ddae339ac4b5cbc2e82790bc5893bcf5f5fb61e82
BLAKE2b-256 checksum
How to use checksums
4d7109a64ca02da9d4f4cbd75a02ec934904ea1a69aa5cbf26e9e5f53f37e2da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.4

Release files / wildlife_tools-0.0.9-py3-none-any.whl

Download URL wildlife_tools-0.0.9-py3-none-any.whl
Size 25.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b9913bddc9c497e9e0616cce0ac7a794d467c891515cd15abb2e5a8d262f54b0
BLAKE2b-256 checksum
How to use checksums
18af623183cbca07bc009cec54c58a0e840fe99cf4937176bc5cc3eefeed4f73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.4

Security for wildlife-tools 0.0.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page