avatarAlessandro Lamberti

Summary

The website content provides a tutorial on using the Hydra AI API for facial attributes classification via Python, detailing the setup process, API usage, and the types of analyses possible, including age, gender, emotions, and facial features detection.

Abstract

The article "Facial Attributes Classification Using Python" introduces readers to the Hydra AI API, a tool for facial attributes classification. It outlines the need for such technology in intelligence and security tasks and describes the range of attributes that can be analyzed, such as age, gender, facial keypoints, emotional state, and the presence of features like beards or glasses. The tutorial guides users through setting up a RapidAPI account, subscribing to the Hydra AI API, and installing the necessary Python library, requests. It also provides a code example demonstrating how to send image data to the API for analysis and interpret the JSON response containing detailed information about detected faces, including bounding boxes, emotions, age range, gender, and whether the subject is wearing a mask or has their eyes or mouth open. The author emphasizes the API's capabilities beyond face detection, such as multi-label classification and object detection, and concludes by inviting readers to follow their work and consider membership for full access to their content.

Opinions

  • The author, Alessandro Lamberti, positively promotes the Hydra AI API as a state-of-the-art tool for machine learning and deep learning tasks related to facial analysis.
  • The article suggests that the free tier of the Hydra AI API, offering 100 requests per month, provides a cost-effective way for developers to experiment with facial attributes classification.
  • The author expresses a commitment to further developing Hydra AI, hinting at upcoming features and tasks, including NLP and customized classification/object detection.
  • By encouraging readers to follow their Medium profile, visit their website, and join the Artificialis newsletter, the author conveys an interest in building a community around their work in artificial intelligence.
  • The author endorses a cost-effective AI service, ZAI.chat, as an alternative to ChatGPT Plus (GPT-4), suggesting it as a valuable resource for those interested in AI capabilities.

Facial Attributes Classification Using Python

Photo by Houcine Ncib / Unsplash

Facial attributes classification (FAC) has attracted increasing attention in Computer Vision, especially for intelligence and security tasks. The term ‘facial attributes’ can widely range and it can include:

  • Age and gender classification
  • Facial keypoints detection
  • Opened or closed eyes and mouth
  • Overall detected emotion
  • Other features like beard, hat, glasses detection

In this tutorial, we’ll leverage an API I recently launched, Hydra AI. Hydra AI is meant to provide state of the art machine learning and deep learning models to solve a multitude of tasks:

  • Face detection and facial attributes analysis
  • Multi-label and customized classification and object detection

Get started

To get started, you’ll need a RapidAPI account, and you’ll have to subscribe to the Hydra AI API linked above.

A credit card is required, but you won’t be charged unless you go over the free tier limits, which is 100 requests/month at the time of writing.

Screenshot by author

Once subscribed, save the API key and don’t share it with others.

Using the API

If you don’t have it already, you will need to install the requests library:

pip3 install requests

To start using the API and analyze facial attributes of people in images, go to your editor of choice and start writing:

As you see, you can either use an image URL or a base64-encoded image, and this is the type of response you can expect:

{
      "success": true,
      "ndetected_faces": 1,
      "detected_faces": [
        {
          "box": {
            "top": 17,
            "left": 76,
            "width": 89,
            "height": 89
          },
          "info": {
            "emotions": {
              "angry": 0.05401921272277832,
              "disgust": 0.0007156527135521173,
              "fear": 0.03044717200100422,
              "happy": 0.5950002670288086,
              "sad": 0.06611847877502441,
              "surprise": 0.031093424186110497,
              "neutral": 0.22260591387748718
            },
            "age": "19-25",
            "gender": "F",
            "mask": {
              "has_mask": false,
              "confidence": 0.9902580976486206
            },
            "eyes": {
              "closed_eyes": false
            },
            "mouth": {
              "is_smiling": false,
              "is_open": false
            }
          }
        }
      ],
      "total_inference_time": 3664.666175842285
    }

That’s it! You now have access to a multitude of information regarding detected faces in images.

Conclusion

Hydra AI v1 was recently released, I’ll keep working on it to provide even more facial analysis features, and more tasks including: multi-label and customized classification/object detection, NLP tasks, and more!

If you liked the post, consider following me on Medium and my website: alessandroai.com.

You can join Artificialis newsletter, here.

You can also support my work directly and get unlimited access by becoming a Medium member through my referral link here!

Originally published at https://www.alessandroai.com on April 4, 2022.

Machine Learning
Tutorial
Data Science
API
Technology
Recommended from ReadMedium