A fastai based framework for similarity learning
Project description
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 *
from fastai_datasets.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.0399999618530273, 0.8839285969734192)
Let’s see how good it is:
learn = Learner(dls, siamese, metrics=accuracy)
learn.validate()
(#2) [0.5608958601951599,0.8239796161651611]
learn.show_results()
Not bad, but we can do better with finetuning:
learn.fit(5, 1e-4)
learn.validate()
(#2) [0.2924809157848358,0.9387755393981934]
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.
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
Built Distribution
File details
Details for the file similarity-learning-0.0.3.tar.gz
.
File metadata
- Download URL: similarity-learning-0.0.3.tar.gz
- Upload date:
- Size: 22.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ca4b961ce8b9e89c2f5026da6b19cedb018cfb652b4e2008fec83c17ca8e8ed |
|
MD5 | cce11d8717ebcfddf84e0ffc6ccc5faf |
|
BLAKE2b-256 | c6fcee6b8af9bfa927e6e94adcce6dcfba1789268ac7cfdfc6a39240c9035bea |
Provenance
File details
Details for the file similarity_learning-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: similarity_learning-0.0.3-py3-none-any.whl
- Upload date:
- Size: 22.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41158aba7c5cab6c43d209f6d7020b24578d11900d15959fb8f0357efd70fda8 |
|
MD5 | e2df68f2c4d312dcb3396fd2f238d76c |
|
BLAKE2b-256 | 19fb66e8d3ea55d0b4bccc8025c55de8315f6d77ffb0f03c9506366655578d85 |