Metadata-Version: 2.1
Name: similarity-learning
Version: 0.0.3
Summary: A fastai based framework for similarity learning
Home-page: https://github.com/Irad-Zehavi/similarity-learning
Author: iradz
Author-email: irad.zehavi@outlook.com
License: Apache Software License 2.0
Keywords: nbdev jupyter notebook python
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: License :: OSI Approved :: Apache Software License
Requires-Python: >=3.7
Description-Content-Type: text/markdown
Requires-Dist: facenet-pytorch
Requires-Dist: fastai
Requires-Dist: fastai-datasets
Requires-Dist: matplotlib
Provides-Extra: dev
Requires-Dist: ipympl ; extra == 'dev'

similarity-learning
================

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Docs

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

## Install

``` sh
pip install similarity_learning
```

## How to use

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

``` python
from similarity_learning.all import *
```

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

``` python
from fastai.vision.all import *

from fastai_datasets.all import *
```

``` python
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:

``` python
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:

``` python
learn = Learner(dls, siamese, metrics=accuracy)
learn.validate()
```

    (#2) [0.5608958601951599,0.8239796161651611]

``` python
learn.show_results()
```

![](index_files/figure-commonmark/cell-7-output-2.png)

Not bad, but we can do better with finetuning:

``` python
learn.fit(5, 1e-4)
learn.validate()
```

    (#2) [0.2924809157848358,0.9387755393981934]

``` python
learn.show_results()
```

![](index_files/figure-commonmark/cell-9-output-2.png)

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

``` python
siamese.plot_distance_histogram(dls.valid)
```

![](index_files/figure-commonmark/cell-10-output-2.png)

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


