Skip to main content

Tools for the competition

Project description

Forgeryscope

Forgeryscope is a Python package for scientific image forgery detection. It contains tools for panel detection, embedding, and image/panel matching.

This is a simplified and refactored version of my winning solution for the Kaggle Scientific Image Forgery Detection competition.

For the full competition approach and design notes, see SOLUTION.md.

Features

  • Panel detection with YOLO-based extractors
  • Image embeddings with PyTorch/timm checkpoints
  • Panel matching with LightGlue, SIFT, ALIKED, and geometry helpers
  • On-demand model download from GitHub Releases

Linux Installation

Create and activate a virtual environment:

python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip

Install Forgeryscope from PyPI:

pip install forgeryscope

The package is available on PyPI: https://pypi.org/project/forgeryscope/

To install the latest version directly from GitHub:

pip install git+https://github.com/vlad3996/forgeryscope.git

If you work from a local clone:

git clone https://github.com/vlad3996/forgeryscope.git
cd forgeryscope
pip install -e .

Model Weights

Model weights are not stored in git and are not bundled into the Python package. They are downloaded on first use and cached locally.

Upload these files as assets to a GitHub Release, for example release tag models-v1:

  • yolo_panel_extractor.pt
  • yolo_lane_extractor.pt
  • aliked_wblot.pth
  • wblot_duplicate_embedder.ckpt
  • wblot_overlap_embedder.ckpt
  • wblot_lane_embedder.ckpt
  • micro_overlap_embedder.ckpt

Then set the model URL in your Linux shell:

export FORGERYSCOPE_MODEL_BASE_URL="https://github.com/vlad3996/forgeryscope/releases/download/models-v1"

The first run downloads each requested file to:

~/.cache/forgeryscope

To use a different cache directory:

export FORGERYSCOPE_CACHE_DIR="/path/to/cache"

Quick Start

from ultralytics import YOLO

from forgeryscope import (
    Embedder,
    LightGlueOverlap,
    PanelExtractor,
    get_model_path,
    load_aliked_wblot_weights,
)

device = "cuda"

panel_extractor = PanelExtractor(
    weights_path="yolo_panel_extractor",
    device=device,
    conf_threshold=0.7,
    iou_threshold=0.4,
    verbose=False,
)
panel_extractor.EXCLUDED_LABELS = {"Graphs", "Flow Cytometry", "Body Imaging"}

lane_extractor = YOLO(get_model_path("yolo_lane_extractor"))

matcher_micro = LightGlueOverlap(
    max_keypoints=4096,
    matcher_features="sift",
    device=device,
    depth_confidence=0.9,
    width_confidence=0.9,
    verbose=False,
)

matcher_blot = LightGlueOverlap(
    max_keypoints=512,
    matcher_features="aliked",
    device=device,
    depth_confidence=-1,
    width_confidence=-1,
    estimator_method="MAGSAC",
    reprojThreshold=3.0,
    estimator_confidence=0.9999,
    estimator_maxIters=5000,
    estimator_refineIters=10,
    verbose=False,
)
load_aliked_wblot_weights(matcher_blot)

wblot_duplicate_embedder = Embedder("wblot_duplicate_embedder", device=device, verbose=False)
wblot_overlap_embedder = Embedder("wblot_overlap_embedder", device=device, verbose=False)
wblot_lane_embedder = Embedder("wblot_lane_embedder", device=device, verbose=False)
micro_overlap_embedder = Embedder("micro_overlap_embedder", device=device, verbose=False)

You can also pass a local checkpoint path instead of a model name:

embedder = Embedder("/path/to/wblot_duplicate_embedder.ckpt", device="cuda", verbose=False)

Available Model Names

  • yolo_panel_extractor
  • yolo_lane_extractor
  • aliked_wblot
  • wblot_duplicate_embedder
  • wblot_overlap_embedder
  • wblot_lane_embedder
  • micro_overlap_embedder

Publishing Notes

Keep checkpoints/ ignored by git. Large .pt, .pth, and .ckpt files should live in GitHub Releases, not in normal repository history.

When a checkpoint changes:

  1. Upload the new file to a new GitHub Release tag.
  2. Update FORGERYSCOPE_MODEL_BASE_URL to the new release URL.
  3. Update the SHA256 value in forgeryscope/model_zoo.py.

Requirements

  • Python >= 3.8
  • PyTorch >= 1.9.0
  • torchvision >= 0.10.0
  • OpenCV >= 4.5.0
  • Dependencies listed in pyproject.toml

License

This project is licensed under the MIT License. See LICENSE.

Author

Uladzislau Leketush (vlad.leketush@gmail.com)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

forgeryscope-0.0.3.tar.gz (31.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

forgeryscope-0.0.3-py3-none-any.whl (32.8 kB view details)

Uploaded Python 3

File details

Details for the file forgeryscope-0.0.3.tar.gz.

File metadata

  • Download URL: forgeryscope-0.0.3.tar.gz
  • Upload date:
  • Size: 31.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for forgeryscope-0.0.3.tar.gz
Algorithm Hash digest
SHA256 26d725ded5db64df0e993bcf2d55464976c4df657dcbcabfb4e768a8796e4e1f
MD5 5c5614df790aef0ca87d0e7814da7cc3
BLAKE2b-256 a21c11296bf89ab8998874952ca4dbc16476eb2eccf576da069d537ae5b953b1

See more details on using hashes here.

File details

Details for the file forgeryscope-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: forgeryscope-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 32.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for forgeryscope-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6d0310d7e5028d944a462965d51e2e642029fc5582f52e9ad17cc5aca330115c
MD5 b8c81ed49d9b3b685a5131d17718f158
BLAKE2b-256 62ba4d0dda7cebea8b7dae09ef66cb720d68f05430a51151da1d2be0a3dd143f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page