Skip to content

Experiment with eyeglasses image classification with light sized model

Notifications You must be signed in to change notification settings

Dian-Yi/eyeglasses_classifier_lightweight

 
 

Repository files navigation

Eyeglasses detection with model less than 3Mb.

Task definition

We need to create face image classifier to detect eyeglasses. We have following constraints:

  • we want to make our model less than 3Mb, to use it on mobile devices.
  • 100 ms limit to inference (~ GeForce GTX 1080 Ti)

Solution and results

We decided to use SqueezeNet. It has 723 009 parameters for binary case. It will take about 2.75 Mb. We compared performance and inference time of ResNet-18 and SqueezeNet.

Model E[F1-score] Var[F1-score]
ResNet-18 0.997 0.004
SqueezeNet 0.984 0.007

Table 1. Dataset of size 1800. Cross validation over 5 folds.

Model Device Inference time, ms
ResNet-18 K80 4.367
ResNet-18 CPU (Intel Xeon E5-2686 v4) 101
SqueezeNet K80 4.256
SqueezeNet CPU (Intel Xeon E5-2686 v4) 38

Table 2. Inference time for single image

Dataset

To train our model, we used images of size 120x120 from MeGlass dataset. We took just 900 samples of each class. To train model we put our samples to "0" and "1" folders. Both of these folders must be located at the same common folder.

Inference

Using docker

$ docker run -it --rm  -v /images/to/classify:/workspace/images acheshkov/glasses

Your computer

git clone https://github.com/acheshkov/eyeglasses_classifier_lightweight.git
pip install -r requirements.txt
python inference.py --images-path='images/to/classify' --model-params-path='./dist/squeezenet_params'

How to improve inference time

  1. Quantization. Using fewer bits to store model weights.
  2. Pruning. Analyze weights and wipe out those whose values close to zero.
  3. Seek for lighter architecture than SqueezeNet.
  4. We could use smaller input image size.
  5. We could exploit hardware specific optimization

Training

git clone https://github.com/acheshkov/eyeglasses_classifier_lightweight.git
pip install -r requirements.txt
python train.py --epochs=100 --batch-size=40 --images-path='/path/to/dataset'

About

Experiment with eyeglasses image classification with light sized model

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 93.4%
  • Shell 4.1%
  • Dockerfile 2.5%