Skip to main content

similarity-learning

Docs

See https://irad-zehavi.github.io/similarity-learning/

Install

pip install similarity_learning

How to use

As an nbdev library, similarity_learning supports import * (without importing unwanted symbols):

from similarity_learning.all import *

Now we can train a pair-matcher. First let’s construct dataloaders of pairs:

from fastai.vision.all import *
pairs = Pairs(Imagenette(160), .1)
dls = pairs.dls(after_item=Resize(128),
                after_batch=Normalize.from_stats(*imagenet_stats))

To get quick results, we can use the body of a pretrained model as a backbone for our Siamese neural network:

classifier = resnet34(weights=ResNet34_Weights.DEFAULT)
siamese = ThresholdSiamese(create_body(model=classifier, cut=-1)).to(dls.device)
siamese.fit_threshold(dls.train)
(1.0099999904632568, 0.8962054252624512)

Let’s see how good it is:

learn = Learner(dls, siamese, metrics=accuracy)
learn.validate()
(#2) [0.5453092455863953,0.8877550959587097]
learn.show_results()

Not bad, but we can do better with finetuning:

learn.fit(5, 1e-4)
learn.validate()
(#2) [0.26150667667388916,0.954081654548645]
learn.show_results()

We can also consider the distribution of feature-space distances compared to the decision threshold:

siamese.plot_distance_histogram(dls.valid)

See the rest of the docs for more examples, including more visualizations, comparison of loss functions, and facial recognition.

Metadata

Release files for similarity-learning 0.0.4

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

Source distribution (sdist)

Source distribution for similarity-learning 0.0.4
File Size Uploaded Provenance Actions
similarity-learning-0.0.4.tar.gz 22.5 kB Without provenance Details for similarity-learning-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for similarity-learning 0.0.4
File Interpreter ABI Platform Actions
similarity_learning-0.0.4-py3-none-any.whl Python 3 none any Details for similarity_learning-0.0.4-py3-none-any.whl

Total release size: 45.1 kB

Release files / similarity-learning-0.0.4.tar.gz

Download URL similarity-learning-0.0.4.tar.gz
Size 22.5 kB
Tags Source
SHA-256 checksum
How to use checksums
951dd1c853449b9f1798aa73a6c8a8e56c3c6c9281c26ee009924f63158489f9
BLAKE2b-256 checksum
How to use checksums
9e22e31b169acd14a3be1552444275cdabc484480af5a2463e070844d52aa92b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / similarity_learning-0.0.4-py3-none-any.whl

Download URL similarity_learning-0.0.4-py3-none-any.whl
Size 22.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4000cb5b013803b8df9c9bf4dee6e5c712e725e194ceaa254ea6f1add1553c14
BLAKE2b-256 checksum
How to use checksums
a37daa220fe06e5b24833c33866706bdde1e7cc6e6dc057dbe943933606dc66b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Security for similarity-learning 0.0.4

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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