mantasu / glasses-detector

Glasses detection, classification and segmentation
https://mantasu.github.io/glasses-detector/
MIT License
39 stars 6 forks source link

Eyeglasses Classifier #9

Closed mantasu closed 4 months ago

mantasu commented 7 months ago

Setting up Eyeglasses Classification model

About

Some people asked for a generic glasses classifier (#3, #7, #8), so I released weights for the small eyeglasses classification model. This means you can classify Eyeglasses (sunglasses are excluded) and Anyglasses (sunglasses are included).

Model

The same model architecture was used as for the small sunglasses classifier, i.e., Shufflenet. The datasets used were Face Attributes Grouped, Face Attributes Extra, and Glasses and Coverings. The results on the test set are as follows:

Model type BCE loss $\downarrow$ F1 score $\uparrow$ ROC-AUC score $\uparrow$ Num params $\downarrow$ Model size $\downarrow$
Eyeglasses classifier small 0.1726 0.9217 0.9908 342.82 k 1.34 Mb

Note

Please note that this is just a temporary solution. As noted in #2, the package should be updated in February (non-beta release) with more features, newer models, and better accuracies. Additionally, there will be some architectural changes, thus don't rely on imports or any code used in this beta release - it will be incompatible with v1.0.0.

Setup

Prepare the weights

  1. Download eyeglasses_classifier_shufflenet_v2_x0_5.zip
  2. Unzip and place eyeglasses_classifier_shufflenet_v2_x0_5.pth inside .cache/torch/hub/checkpoints.

Note: your torch hub directory may be elsewhere, you can check that by trying to classify sunglasses. All the models are automatically downloaded there, so just place eyeglasses_classifier_shufflenet_v2_x0_5.pth alongside them.

Run the classifier

  1. You can just run from command-line:
    glasses-detector -i data/demo --kind anyglasses-classifier
  2. OR create a custom script, e.g., classify_if_glasses.py:

    from glasses_detector import AnyglassesClassifier, EyeglassesClassifier
    
    # Constants - change if needed
    CLASSIFIER_CLS = AnyglassesClassifier
    REL_PATH = "data/demo"
    
    # Instantiate and run the classifier (only "small" is available)
    classifier = CLASSIFIER_CLS(base_model="small", pretrained=True).eval()
    classifier.process(REL_PATH)

    and then just run:

    python classify_if_glasses.py