<h1 align="center"><img src="https://raw.githubusercontent.com/mantasu/glasses-detector/main/docs/_static/img/logo-light.png" width=27px height=27px> Glasses Detector</h1>
<div align="center">
[](https://colab.research.google.com/github/mantasu/glasses-detector/blob/main/notebooks/demo.ipynb)
[](https://mantasu.github.io/glasses-detector/)
[](https://pypi.org/project/glasses-detector/)
[](https://docs.python.org/3/)
[](https://developer.nvidia.com/cuda-toolkit)
[](https://zenodo.org/badge/latestdoi/610509640)
[](https://opensource.org/licenses/MIT)

</div>
## About
Package for processing images with different types of glasses and their parts. It provides a quick way to use the pre-trained models for **3** kinds of tasks, each divided into multiple categories, for instance, *classification of sunglasses* or *segmentation of glasses frames*.
<br>
<div align="center">
<table align="center"><tbody>
<tr><td><strong>Classification</string></td> <td> 👓 <em>transparent</em> 🕶️ <em>opaque</em> 🥽 <em>any</em> ➿<em>shadows</em></td></tr>
<tr><td><strong>Detection</string></td> <td> 🤓 <em>worn</em> 👓 <em>standalone</em> 👀 <em>eye-area</em></td></tr>
<tr><td><strong>Segmentation</string></td> <td> 😎 <em>full</em> 🖼️ <em>frames</em> 🦿 <em>legs</em> 🔍 <em>lenses</em> 👥 <em>shadows</em></td></tr>
</tbody></table>
$\color{gray}{\textit{Note: }\text{refer to}}$ [Glasses Detector Features](https://mantasu.github.io/glasses-detector/docs/features.html) $\color{gray}{\text{for visual examples.}}$
</div>
## Installation
> [!IMPORTANT]
> Minimum version of [Python 3.12](https://www.python.org/downloads/release/python-3120/) is required. Also, you may want to install [Pytorch](https://pytorch.org/get-started/locally/) (select *Nightly* for compatibility) in advance to select specific configuration for your device and environment.
### Pip Package
If you only need the library with pre-trained models, just install the [pip package](https://pypi.org/project/glasses-detector/) and see **Quick Start** for usage (also check [Glasses Detector Installation](https://mantasu.github.io/glasses-detector/docs/features.html) for more details):
```bash
pip install glasses-detector
```
You can also install it from the source:
```bash
git clone https://github.com/mantasu/glasses-detector
cd glasses-detector && pip install .
```
### Local Project
If you want to train your own models on the given datasets (or on some other datasets), just clone the project and install training requirements, then see **[Running](https://github.com/mantasu/glasses-detector?tab=readme-ov-file#running)** section to see how to run training and testing.
```bash
git clone https://github.com/mantasu/glasses-detector
cd glasses-detector && pip install -r requirements.txt
```
You can create a virtual environment for your packages via [venv](https://docs.python.org/3/library/venv.html), however, if you have conda, then you can simply use it to create a new environment, for example:
```bash
conda create -n glasses-detector python=3.12
conda activate glasses-detector
```
> To set-up the datasets, refer to **[Data](https://github.com/mantasu/glasses-detector?tab=readme-ov-file#data)** section.
## Quick Start
### Command Line
You can run predictions via the command line. For example, classification of a single image and segmentation of images inside a directory can be performed by running:
```bash
glasses-detector -i path/to/img.jpg -t classification -d cuda -f int # Prints 1 or 0
glasses-detector -i path/to/img_dir -t segmentation -f mask -e .jpg # Generates masks
```
> [!TIP]
> You can also specify things like `--output-path`, `--size`, `--batch-size` etc. Check the [Glasses Detector CLI](https://mantasu.github.io/glasses-detector/docs/cli.html) and [Command Line Examples](https://mantasu.github.io/glasses-detector/docs/examples.html#command-line) for more details.
### Python Script
You can import the package and its models via the python script for more flexibility. Here is an example of how to classify people wearing sunglasses:
```python
from glasses_detector import GlassesClassifier
# Generates a CSV with each line "<img_name.jpg>,<True|False>"
classifier = GlassesClassifier(size="small", kind="sunglasses")
classifier.process_dir("path/to/dir", "path/to/preds.csv", format="bool")
```
And here is a more efficient way to process a dir for detection task (only single bbox per image is currently supported):
```python
from glasses_detector import GlassesDetector
# Generates dir_preds with bboxes as .txt for each img
detector = GlassesDetector(kind="eyes", device="cuda")
detector.process_dir("path/to/dir", ext=".txt", batch_size=64)
```
> [!TIP]
> Again, there are a lot more things that can be specified, for instance, `output_size` and `pbar`. It is also possible to directly output the results or save them in a variable. See [Glasses Detector API](https://mantasu.github.io/glasses-detector/docs/api.html) and [Python Script Examples](https://mantasu.github.io/glasses-detector/docs/examples.html#python-script) for more details.
### Demo
Feel free to play around with some [demo image files](https://github.com/mantasu/glasses-detector/demo/). For example, after installing through [pip](https://pypi.org/project/glasses-detector/), you can run:
```bash
git clone https://github.com/mantasu/glasses-detector && cd glasses-detector/data
glasses-detector -i demo -o demo_labels.csv --task classification:eyeglasses
```
You can also check out the [demo notebook](https://github.com/mantasu/glasses-detector/notebooks/demo.ipynb) which can be also accessed via [Google Colab](https://colab.research.google.com/github/mantasu/glasses-detector/blob/master/notebooks/demo.ipynb).
## Credits
For references and citation, please see [Glasses Detector Credits](https://mantasu.github.io/glasses-detector/docs/credits.html).
Raw data
{
"_id": null,
"home_page": "https://github.com/mantasu/glasses-detector",
"name": "glasses-detector",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": "",
"keywords": "python,pytorch,torchvision,computer,vision,image,face,eyes,transparent,opaque,glasses,googles,spectacles,eyeglasses,sunglasses,frames,lenses,legs,shadows,binary,identification,identifier,classification,classifier,segmentation,segmenter,detection,detector,cuda,mps,gpu",
"author": "Mantas Bir\u0161kus",
"author_email": "mantix7@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/05/83/e516b2c3513848f16fa58b1597107718efb98e511c846f05e5356824847d/glasses-detector-1.0.1.tar.gz",
"platform": null,
"description": "\n<h1 align=\"center\"><img src=\"https://raw.githubusercontent.com/mantasu/glasses-detector/main/docs/_static/img/logo-light.png\" width=27px height=27px> Glasses Detector</h1>\n\n<div align=\"center\">\n\n[](https://colab.research.google.com/github/mantasu/glasses-detector/blob/main/notebooks/demo.ipynb)\n[](https://mantasu.github.io/glasses-detector/)\n[](https://pypi.org/project/glasses-detector/)\n[](https://docs.python.org/3/)\n[](https://developer.nvidia.com/cuda-toolkit)\n[](https://zenodo.org/badge/latestdoi/610509640)\n[](https://opensource.org/licenses/MIT)\n\n\n\n</div>\n\n## About\n\nPackage for processing images with different types of glasses and their parts. It provides a quick way to use the pre-trained models for **3** kinds of tasks, each divided into multiple categories, for instance, *classification of sunglasses* or *segmentation of glasses frames*.\n\n<br>\n\n<div align=\"center\">\n\n<table align=\"center\"><tbody>\n <tr><td><strong>Classification</string></td> <td> \ud83d\udc53 <em>transparent</em> \ud83d\udd76\ufe0f <em>opaque</em> \ud83e\udd7d <em>any</em> \u27bf<em>shadows</em></td></tr>\n <tr><td><strong>Detection</string></td> <td> \ud83e\udd13 <em>worn</em> \ud83d\udc53 <em>standalone</em> \ud83d\udc40 <em>eye-area</em></td></tr>\n <tr><td><strong>Segmentation</string></td> <td> \ud83d\ude0e <em>full</em> \ud83d\uddbc\ufe0f <em>frames</em> \ud83e\uddbf <em>legs</em> \ud83d\udd0d <em>lenses</em> \ud83d\udc65 <em>shadows</em></td></tr>\n</tbody></table>\n\n$\\color{gray}{\\textit{Note: }\\text{refer to}}$ [Glasses Detector Features](https://mantasu.github.io/glasses-detector/docs/features.html) $\\color{gray}{\\text{for visual examples.}}$\n\n</div>\n\n## Installation\n\n> [!IMPORTANT]\n> Minimum version of [Python 3.12](https://www.python.org/downloads/release/python-3120/) is required. Also, you may want to install [Pytorch](https://pytorch.org/get-started/locally/) (select *Nightly* for compatibility) in advance to select specific configuration for your device and environment.\n\n### Pip Package\n\nIf you only need the library with pre-trained models, just install the [pip package](https://pypi.org/project/glasses-detector/) and see **Quick Start** for usage (also check [Glasses Detector Installation](https://mantasu.github.io/glasses-detector/docs/features.html) for more details):\n\n```bash\npip install glasses-detector\n```\n\nYou can also install it from the source:\n\n```bash\ngit clone https://github.com/mantasu/glasses-detector\ncd glasses-detector && pip install .\n```\n\n### Local Project\n\nIf you want to train your own models on the given datasets (or on some other datasets), just clone the project and install training requirements, then see **[Running](https://github.com/mantasu/glasses-detector?tab=readme-ov-file#running)** section to see how to run training and testing.\n\n```bash\ngit clone https://github.com/mantasu/glasses-detector\ncd glasses-detector && pip install -r requirements.txt\n```\n\nYou can create a virtual environment for your packages via [venv](https://docs.python.org/3/library/venv.html), however, if you have conda, then you can simply use it to create a new environment, for example:\n\n```bash\nconda create -n glasses-detector python=3.12\nconda activate glasses-detector \n```\n\n> To set-up the datasets, refer to **[Data](https://github.com/mantasu/glasses-detector?tab=readme-ov-file#data)** section.\n\n## Quick Start\n\n### Command Line\n\nYou can run predictions via the command line. For example, classification of a single image and segmentation of images inside a directory can be performed by running:\n\n```bash\nglasses-detector -i path/to/img.jpg -t classification -d cuda -f int # Prints 1 or 0\nglasses-detector -i path/to/img_dir -t segmentation -f mask -e .jpg # Generates masks\n```\n\n> [!TIP]\n> You can also specify things like `--output-path`, `--size`, `--batch-size` etc. Check the [Glasses Detector CLI](https://mantasu.github.io/glasses-detector/docs/cli.html) and [Command Line Examples](https://mantasu.github.io/glasses-detector/docs/examples.html#command-line) for more details.\n\n### Python Script\n\nYou can import the package and its models via the python script for more flexibility. Here is an example of how to classify people wearing sunglasses:\n\n```python\nfrom glasses_detector import GlassesClassifier\n\n# Generates a CSV with each line \"<img_name.jpg>,<True|False>\"\nclassifier = GlassesClassifier(size=\"small\", kind=\"sunglasses\")\nclassifier.process_dir(\"path/to/dir\", \"path/to/preds.csv\", format=\"bool\")\n```\n\nAnd here is a more efficient way to process a dir for detection task (only single bbox per image is currently supported):\n\n```python\nfrom glasses_detector import GlassesDetector\n\n# Generates dir_preds with bboxes as .txt for each img\ndetector = GlassesDetector(kind=\"eyes\", device=\"cuda\")\ndetector.process_dir(\"path/to/dir\", ext=\".txt\", batch_size=64)\n```\n\n> [!TIP]\n> Again, there are a lot more things that can be specified, for instance, `output_size` and `pbar`. It is also possible to directly output the results or save them in a variable. See [Glasses Detector API](https://mantasu.github.io/glasses-detector/docs/api.html) and [Python Script Examples](https://mantasu.github.io/glasses-detector/docs/examples.html#python-script) for more details.\n\n### Demo\n\nFeel free to play around with some [demo image files](https://github.com/mantasu/glasses-detector/demo/). For example, after installing through [pip](https://pypi.org/project/glasses-detector/), you can run:\n\n```bash\ngit clone https://github.com/mantasu/glasses-detector && cd glasses-detector/data\nglasses-detector -i demo -o demo_labels.csv --task classification:eyeglasses\n```\n\nYou can also check out the [demo notebook](https://github.com/mantasu/glasses-detector/notebooks/demo.ipynb) which can be also accessed via [Google Colab](https://colab.research.google.com/github/mantasu/glasses-detector/blob/master/notebooks/demo.ipynb).\n\n## Credits\n\nFor references and citation, please see [Glasses Detector Credits](https://mantasu.github.io/glasses-detector/docs/credits.html).\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Glasses classification, detection, and segmentation.",
"version": "1.0.1",
"project_urls": {
"Bug Tracker": "https://github.com/mantasu/glasses-detector/issues",
"Documentation": "https://mantasu.github.io/glasses-detector",
"Homepage": "https://github.com/mantasu/glasses-detector"
},
"split_keywords": [
"python",
"pytorch",
"torchvision",
"computer",
"vision",
"image",
"face",
"eyes",
"transparent",
"opaque",
"glasses",
"googles",
"spectacles",
"eyeglasses",
"sunglasses",
"frames",
"lenses",
"legs",
"shadows",
"binary",
"identification",
"identifier",
"classification",
"classifier",
"segmentation",
"segmenter",
"detection",
"detector",
"cuda",
"mps",
"gpu"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4fef9814e49ca8297ecc1b408c095ec33126dae386259e83ef82f08db8c607a9",
"md5": "eacc6a6c28521ec5fa54c9a4f80bed7d",
"sha256": "adc7d49ca3bd4577195b554ff403ecb62410a811205e8bad67d6ceac1fe01954"
},
"downloads": -1,
"filename": "glasses_detector-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "eacc6a6c28521ec5fa54c9a4f80bed7d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12",
"size": 73661,
"upload_time": "2024-03-06T07:17:01",
"upload_time_iso_8601": "2024-03-06T07:17:01.735787Z",
"url": "https://files.pythonhosted.org/packages/4f/ef/9814e49ca8297ecc1b408c095ec33126dae386259e83ef82f08db8c607a9/glasses_detector-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0583e516b2c3513848f16fa58b1597107718efb98e511c846f05e5356824847d",
"md5": "3a63380396e9346b1b25b1b96ab9d0d1",
"sha256": "3a03b653a5a255115db87f1d1b1ad452e0a0e1ecc96c88d37677b7bb45335272"
},
"downloads": -1,
"filename": "glasses-detector-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "3a63380396e9346b1b25b1b96ab9d0d1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 87590,
"upload_time": "2024-03-06T07:17:04",
"upload_time_iso_8601": "2024-03-06T07:17:04.513162Z",
"url": "https://files.pythonhosted.org/packages/05/83/e516b2c3513848f16fa58b1597107718efb98e511c846f05e5356824847d/glasses-detector-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-06 07:17:04",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mantasu",
"github_project": "glasses-detector",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "glasses-detector"
}