ChenglongMa / SkinToneClassifier

An easy-to-use library for skin tone classification
https://chenglongma.com/SkinToneClassifier/
GNU General Public License v3.0
97 stars 13 forks source link

Skin Tone Classifier Execution in Google Colab" #6

Closed Arslankmb closed 1 year ago

Arslankmb commented 1 year ago

Issue Description:

I encountered an issue when using the Skin Tone Classifier library in a Google Colab environment. The problem appears to be related to Qt platform plugins, and I received the following error messages: qt.qpa.plugin: Could not find the Qt platform plugin "offscreen" in "/usr/local/lib/python3.10/dist-packages/cv2/qt/plugins" This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. Available platform plugins are: xcb.

Steps to Reproduce: Install the Skin Tone Classifier library using pip install skin-tone-classifier --upgrade. Run the following command in a Jupyter Notebook or Google Colab environment: stone -i /path/to/image.jpg --debug

Expected Behavior: I expected the Skin Tone Classifier to process the image and provide results as described in the library's documentation.

Actual Behavior: Instead, I encountered the error messages mentioned above, which prevented the library from functioning correctly.

System Information: Operating System: Google Colab (Colab's default environment) Python Version: 3.10 Skin Tone Classifier Version: 1.0.0

My attempts I attempted to resolve this issue by following the suggestions in the error message, but it did not resolve the problem. The issue seems to be related to the Qt platform plugins, specifically "offscreen."

Please let me know if there are any specific logs or additional information needed to diagnose and address this problem. Thank you for your assistance.

ChenglongMa commented 1 year ago

Hi @Arslankmb, thanks for your feedback!

TL;DR

  1. You can ignore this error because it won't affect the results. You can still find the result files in the debug folder and result.csv.
  2. When you process multiple images, no error will be reported. The error is only popped up when processing one image.
  3. I will fix this issue in the next version.

Thanks!


Detailed explanation

stone was originally designed for command line use, not for Jupyter Notebook, so I hadn't considered this issue before.

I have tested the library in a Google Colab notebook and included some working examples (You can also check it by clicking here). I found that this issue is caused by the OpenCV being incompatible with web browsers (like Google Colab, and Jupyter Notebook).

This issue occurs only when processing a single image, as stone specifically displays the resulting window when only ONE image is being processed.

I will fix this issue in the next version.

Thanks for your attention and patience!

ChenglongMa commented 1 year ago

Hi @Arslankmb,

Finally, I decided to remove this small function. Please run pip install skin-tone-classifier --upgrade to upgrade the library to v1.0.1. It won't show the resulting window when processing a single image and also won't report the error in notebooks.

Thanks!

ChenglongMa commented 1 year ago

For those looking for help and find this: stone now can be imported into other projects or Jupyter Notebook env as a library since version 1.1.0.

Please run the following command to upgrade it to version 1.1.0.

pip install skin-tone-classifier --upgrade

Following README#9-used-as-a-library-by-importing-into-other-projects to import stone, e.g.,

import stone

result = stone.process('example.jpeg', , image_type='color')

Then the result would be:

{
  "basename": "example",
  "extension": ".jpeg",
  "image_type": "color",
  "faces": [
    {
      "dominant_colors": [
        {
          "color": "#D7B19F",
          "percent": "0.62"
        },
        {
          "color": "#7A4E3B",
          "percent": "0.38"
        }
      ],
      "skin_tone": "#BEA07E",
      "tone_label": "CG",
      "accuracy": 82.27,
      "face_id": 1
    }
  ],
  "report_images": {
    "1": null
  }
}

Thanks!