Skip to main content

Glasses classification, detection, and segmentation.

Project description

Glasses Detector

Colab Docs PyPI Python CUDA DOI License

Banner

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.


Classification 👓 transparent 🕶️ opaque 🥽 anyshadows
Detection 🤓 worn 👓 standalone 👀 eye-area
Segmentation 😎 full 🖼️ frames 🦿 legs 🔍 lenses 👥 shadows

$\color{gray}{\textit{Note: }\text{refer to}}$ Glasses Detector Features $\color{gray}{\text{for visual examples.}}$

Installation

[!IMPORTANT] Minimum version of Python 3.12 is REQUIRED. Also, you may want to install Pytorch 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 and see Quick Start for usage (also check Glasses Detector Installation for more details):

pip install glasses-detector

You can also install it from the source:

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 section to see how to run training and testing.

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, however, if you have conda, then you can simply use it to create a new environment, for example:

conda create -n glasses-detector python=3.12
conda activate glasses-detector 

To set-up the datasets, refer to 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:

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 and Command Line Examples 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:

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):

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 and Python Script Examples for more details.

Demo

Feel free to play around with some demo image files. For example, after installing through pip, you can run:

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 which can be also accessed via Google Colab.

Credits

For references and citation, please see Glasses Detector Credits.

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

glasses_detector-1.0.2.tar.gz (87.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

glasses_detector-1.0.2-py3-none-any.whl (73.8 kB view details)

Uploaded Python 3

File details

Details for the file glasses_detector-1.0.2.tar.gz.

File metadata

  • Download URL: glasses_detector-1.0.2.tar.gz
  • Upload date:
  • Size: 87.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for glasses_detector-1.0.2.tar.gz
Algorithm Hash digest
SHA256 73d2b2d4781a10cbde5b73cb2d05426b659bcec019ce383ae6e2d988c779ab2e
MD5 0cc200fa68c834a4c2d24c292ea8079c
BLAKE2b-256 a98b77af91f8236bf60c5278fb166972c1f18374c712c4362a3358d803f154e0

See more details on using hashes here.

File details

Details for the file glasses_detector-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for glasses_detector-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3d49cef8fb4def940b5766ea18a1dffb7b0c70edfb26a45f8dc45290327e645b
MD5 44475339a5103e0464e0122f89be60be
BLAKE2b-256 f015913e8ca96d0c8c4c537f5b789787ba3fdad5b381ca72323c5d6399121a0b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page