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 *
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.
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
Hashes for similarity-learning-0.0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 951dd1c853449b9f1798aa73a6c8a8e56c3c6c9281c26ee009924f63158489f9 |
|
MD5 | 32d00f72e8da7ca23fd97f96dcca6bcc |
|
BLAKE2b-256 | 9e22e31b169acd14a3be1552444275cdabc484480af5a2463e070844d52aa92b |
Hashes for similarity_learning-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4000cb5b013803b8df9c9bf4dee6e5c712e725e194ceaa254ea6f1add1553c14 |
|
MD5 | 5da32a5d57814b35396f1bbcaf78c6fa |
|
BLAKE2b-256 | a37daa220fe06e5b24833c33866706bdde1e7cc6e6dc057dbe943933606dc66b |