Skip to main content

A foundational model based for low-level representation similarity metrics

Project description

fmllpsm: Foundational Model Low-Level Perceptual Similarity Metric

PyPI version License

fmllpsm is a Python library that provides a high-level interface for calculating image similarity using deep features from foundational models (e.g., DINOv1). It follows a modular architecture based on Domain-Driven Design (DDD) and Clean Architecture, making it easy for researchers to extend with new backbones or statistical metrics.

This project is a refactored and production-ready implementation of the research conducted in the ZS-IQA repository.


🚀 Quick Start

Installation

pip install fmllpsm

Note: Ensure you have PyTorch and Transformers installed. See pyproject.toml for version requirements.

Basic Usage

import torch
from fmllpsm import FMLLPSM

# 1. Initialize the metric (DINOv1 is supported natively)
# Device is automatically handled, but you can specify "cuda" or "cpu"
fllpsm = FMLLPSM("DINOv1", device="cuda")

# 2. Prepare your images (Tensors: N x C x H x W, normalized to [-1, 1] or [0, 1])
ref_img = torch.randn(1, 3, 224, 224).to("cuda")
gen_img = torch.randn(1, 3, 224, 224).to("cuda")

# 3. Compute the similarity loss
loss = fllpsm(ref_img, gen_img)

print(f"Similarity Loss: {loss.item():.6f}")

🏗️ Architecture

The package is built using Domain-Driven Design (DDD) principles to ensure high maintainability and extensibility for researchers:

  • Domain Layer: Defines pure interfaces for FeatureExtractor and SimilarityMetric.
  • Infrastructure Layer: Contains concrete implementations like DINOv1Extractor and LearnedMetric (LPIPS-style).
  • Application Layer: Orchestrates the evaluation logic through a QualityService.
  • Interfaces Layer: Provides a simplified FMLLPSM facade for common use cases.
graph TD
    User["Researcher/User"] --> Facade["FMLLPSM Facade"]
    Facade --> App["Application Service"]
    App --> Domain["Domain Interfaces"]
    Domain -.-> Infra["Infrastructure Impls (DINO, LPIPS)"]

🔬 Scientific Background

The core metric uses a Learned LPIPS-style distance calculated over DINOv1 ViT-Base features. The formula involves:

  1. Normalization of features on a unit hypersphere.
  2. Weighted Squared Difference across multiple layers (2, 5, 8, 11).
  3. Spatial Averaging to produce a robust perceptual score.

This approach allows for zero-shot image quality assessment that correlates highly with human subjective scores (MOS) across standard datasets like LIVE, TID2013, and PIPAL.


📝 Roadmap

  • DINOv1 Backbone Support
  • LPIPS-style Learned Metric
  • Statistical Proof Metrics (KL Divergence, Wasserstein Distance)
  • Support for CLIP and ConvNeXt backbones
  • Pre-trained weights for specific downstream tasks

⚖️ License

Distributed under the BSD 2-Clause License. See LICENSE for more information.


🤝 Citation

If you use this work in your research, please cite the original ZS-IQA paper:

@article{fmllpsm2024,
  title={Foundational Model Low-Level Perceptual Similarity Metrics},
  author={Chogerlate and Ghildyal, Abhijay},
  journal={TBD},
  year={2026}
}

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

fmllpsm-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

fmllpsm-0.1.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file fmllpsm-0.1.0.tar.gz.

File metadata

  • Download URL: fmllpsm-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fmllpsm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b9bacfdf5520ff60f3b2c2ce04edad4731562c13bf952fa44c471ec03aec43d6
MD5 4a91e783e33fd3c91641b2754e9e91b3
BLAKE2b-256 0034664f46cfd626595cb3ff0bdbb6fdc986c1eef05f4e8e3cff2dfa9de7dd94

See more details on using hashes here.

File details

Details for the file fmllpsm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fmllpsm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fmllpsm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e31801be8e40e3c3dbcb1045e490e7885c8a9c10eb7d42e89df5aa1addc76373
MD5 7f66879b192593ea919cd0ccf8982e49
BLAKE2b-256 5dea1f70dffb894b5ac4bf8a8fb3322ccb60e718d8b4c4606757e77e5776d45b

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