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 *
```
``` 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.0099999904632568, 0.8962054252624512)
Let’s see how good it is:
``` python
learn = Learner(dls, siamese, metrics=accuracy)
learn.validate()
```
(#2) [0.5453092455863953,0.8877550959587097]
``` python
learn.show_results()
```

Not bad, but we can do better with finetuning:
``` python
learn.fit(5, 1e-4)
learn.validate()
```
(#2) [0.26150667667388916,0.954081654548645]
``` python
learn.show_results()
```

We can also consider the distribution of feature-space distances
compared to the decision threshold:
``` python
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.
Raw data
{
"_id": null,
"home_page": "https://github.com/Irad-Zehavi/similarity-learning",
"name": "similarity-learning",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "nbdev jupyter notebook python",
"author": "iradz",
"author_email": "irad.zehavi@outlook.com",
"download_url": "https://files.pythonhosted.org/packages/9e/22/e31b169acd14a3be1552444275cdabc484480af5a2463e070844d52aa92b/similarity-learning-0.0.4.tar.gz",
"platform": null,
"description": "similarity-learning\n================\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\n## Docs\n\nSee https://irad-zehavi.github.io/similarity-learning/\n\n## Install\n\n``` sh\npip install similarity_learning\n```\n\n## How to use\n\nAs an nbdev library, `similarity_learning` supports `import *` (without\nimporting unwanted symbols):\n\n``` python\nfrom similarity_learning.all import *\n```\n\nNow we can train a pair-matcher. First let\u2019s construct dataloaders of\npairs:\n\n``` python\nfrom fastai.vision.all import *\n```\n\n``` python\npairs = Pairs(Imagenette(160), .1)\ndls = pairs.dls(after_item=Resize(128),\n after_batch=Normalize.from_stats(*imagenet_stats))\n```\n\nTo get quick results, we can use the body of a pretrained model as a\nbackbone for our Siamese neural network:\n\n``` python\nclassifier = resnet34(weights=ResNet34_Weights.DEFAULT)\nsiamese = ThresholdSiamese(create_body(model=classifier, cut=-1)).to(dls.device)\nsiamese.fit_threshold(dls.train)\n```\n\n (1.0099999904632568, 0.8962054252624512)\n\nLet\u2019s see how good it is:\n\n``` python\nlearn = Learner(dls, siamese, metrics=accuracy)\nlearn.validate()\n```\n\n (#2) [0.5453092455863953,0.8877550959587097]\n\n``` python\nlearn.show_results()\n```\n\n\n\nNot bad, but we can do better with finetuning:\n\n``` python\nlearn.fit(5, 1e-4)\nlearn.validate()\n```\n\n (#2) [0.26150667667388916,0.954081654548645]\n\n``` python\nlearn.show_results()\n```\n\n\n\nWe can also consider the distribution of feature-space distances\ncompared to the decision threshold:\n\n``` python\nsiamese.plot_distance_histogram(dls.valid)\n```\n\n\n\nSee the rest of the docs for more examples, including more\nvisualizations, comparison of loss functions, and facial recognition.\n\n\n",
"bugtrack_url": null,
"license": "Apache Software License 2.0",
"summary": "A fastai based framework for similarity learning",
"version": "0.0.4",
"project_urls": {
"Homepage": "https://github.com/Irad-Zehavi/similarity-learning"
},
"split_keywords": [
"nbdev",
"jupyter",
"notebook",
"python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a37daa220fe06e5b24833c33866706bdde1e7cc6e6dc057dbe943933606dc66b",
"md5": "5da32a5d57814b35396f1bbcaf78c6fa",
"sha256": "4000cb5b013803b8df9c9bf4dee6e5c712e725e194ceaa254ea6f1add1553c14"
},
"downloads": -1,
"filename": "similarity_learning-0.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5da32a5d57814b35396f1bbcaf78c6fa",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 22583,
"upload_time": "2023-06-10T10:07:01",
"upload_time_iso_8601": "2023-06-10T10:07:01.140486Z",
"url": "https://files.pythonhosted.org/packages/a3/7d/aa220fe06e5b24833c33866706bdde1e7cc6e6dc057dbe943933606dc66b/similarity_learning-0.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9e22e31b169acd14a3be1552444275cdabc484480af5a2463e070844d52aa92b",
"md5": "32d00f72e8da7ca23fd97f96dcca6bcc",
"sha256": "951dd1c853449b9f1798aa73a6c8a8e56c3c6c9281c26ee009924f63158489f9"
},
"downloads": -1,
"filename": "similarity-learning-0.0.4.tar.gz",
"has_sig": false,
"md5_digest": "32d00f72e8da7ca23fd97f96dcca6bcc",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 22545,
"upload_time": "2023-06-10T10:07:02",
"upload_time_iso_8601": "2023-06-10T10:07:02.880972Z",
"url": "https://files.pythonhosted.org/packages/9e/22/e31b169acd14a3be1552444275cdabc484480af5a2463e070844d52aa92b/similarity-learning-0.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-10 10:07:02",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Irad-Zehavi",
"github_project": "similarity-learning",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "similarity-learning"
}