Skip to content

Add python sample for face detection and age classification using HF models#595

Merged
tjanczak merged 6 commits intomainfrom
face_detection_python_sample
Feb 12, 2026
Merged

Add python sample for face detection and age classification using HF models#595
tjanczak merged 6 commits intomainfrom
face_detection_python_sample

Conversation

@tjanczak
Copy link
Contributor

@tjanczak tjanczak commented Feb 4, 2026

…models.

Description

Please include a summary of the changes and the related issue. List any dependencies that are required for this change.

Fixes # (issue)

Any Newly Introduced Dependencies

Please describe any newly introduced 3rd party dependencies in this change. List their name, license information and how they are used in the project.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Checklist:

  • I agree to use the MIT license for my code changes.
  • I have not introduced any 3rd party components incompatible with MIT.
  • I have not included any company confidential information, trade secret, password or security token.
  • I have performed a self-review of my code.

gi.require_version("GstAnalytics", "1.0")
from gi.repository import GLib, Gst, GstAnalytics
from huggingface_hub import hf_hub_download
from ultralytics import YOLO
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pylint] reported by reviewdog 🐶
C0413: Import "from ultralytics import YOLO" should be placed at the top of the module (wrong-import-position)

from ultralytics import YOLO

# wrapper to run the gstreamer pipeline loop
def pipeline_loop(pipeline):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pylint] reported by reviewdog 🐶
C0116: Missing function or method docstring (missing-function-docstring)

sys.stderr.write("Input video file does not exist\n")
sys.exit(1)
else:
default_video_url = "https://videos.pexels.com/video-files/18553046/18553046-hd_1280_720_30fps.mp4"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pylint] reported by reviewdog 🐶
C0301: Line too long (107/100) (line-too-long)

import subprocess
import urllib.request
import gi
from gi.repository import Gst
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pylint] reported by reviewdog 🐶
E0611: No name 'Gst' in module 'gi.repository' (no-name-in-module)



# Prepare input video file; download default if none provided
def prepare_input_video(args):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pylint] reported by reviewdog 🐶
C0116: Missing function or method docstring (missing-function-docstring)



# wrapper to run the gstreamer pipeline loop
def pipeline_loop(pipeline):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pylint] reported by reviewdog 🐶
C0116: Missing function or method docstring (missing-function-docstring)



# Download PyTorch models, convert to OpenVINO IR, create and run gstreamer pipeline
def main(input_video):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pylint] reported by reviewdog 🐶
C0116: Missing function or method docstring (missing-function-docstring)

Use optimum-cli to download the face age classifier from Hugging Face and export it to OpenVINO IR.

**STEP 3 — Build and run the pipeline**
Construct a GStreamer pipeline with `gvadetect` and `gvaclassify`, run inference, and write an annotated MP4 output.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add mention about DL Streamer -->
'Construct a GStreamer pipeline with DL Streamer gvadetect and gvaclassify elements'...


## Sample Output

The script prints the pipeline string and produces an output video annotated with detections and classification results.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding screenshot from the sample, to visualize the final effect.

Copy link
Contributor

@tbujewsk tbujewsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but please see my comments.

@tjanczak tjanczak merged commit aac775e into main Feb 12, 2026
31 of 35 checks passed
@tjanczak tjanczak deleted the face_detection_python_sample branch February 12, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants