PeekingDuck

repository·main·Indexed 41 days ago

https://github.com/aisingapore/peekingduck

An open-source, modular Python framework for building real-time Computer Vision (CV) inference pipelines. It enables developers to integrate SOTA models for object detection, pose estimation, tracking, and crowd counting. Features include a CLI for project initialization and execution, an interactive GUI Viewer for pipeline management and video analysis, and support for optimized TensorRT models (such as MoveNet and YOLOX) on NVIDIA GPUs.

Tokens
32.8K
Snippets
102
Records
155
Agent score
52%

What's inside PeekingDuck

  1. Explore PeekingDuck Computer Vision use cases

    main

    PeekingDuck provides out-of-the-box solutions for various Computer Vision (CV) problems. You can use these pre-built capabilities or mix and match different PeekingDuck nodes to create your own pipelines. Use cases are categorized into three main areas:

    Privacy Protection

    • Faces: Protecting identity by detecting/blurring faces.
    • License Plates: Protecting privacy related to vehicle identification.
    • People and Screens: Protecting privacy related to people and digital screens.

    Smart Monitoring

    • Crowd Counting: Estimating the number of people in a scene.
    • Object Counting (Present): Counting specific objects currently in view.
    • Object Counting (Over Time): Tracking object counts across a temporal sequence.
    • People Counting (Over Time): Tracking the number of people passing through or present over time.
    • Zone Counting: Counting objects or people within specific defined zones.

    COVID-19 Prevention and Control

    • Face Mask Detection: Identifying if individuals are wearing masks.
    • Group Size Checking: Monitoring the size of groups to ensure compliance.
    • Social Distancing: Detecting if individuals are maintaining appropriate distance from one another.
  2. Built-in data types in PeekingDuck

    main

    PeekingDuck nodes recognize several built-in data types for passing information through a pipeline. These types include spatial data (bboxes, masks, keypoints, zones), metadata (filename, fps, saved_video_fps), and statistical aggregations (count, cum_avg, cum_max, cum_min, density_map).

    Users can also define custom data types when creating custom nodes to extend the pipeline's capabilities.

  3. How Object Counting (Present) works

    main

    The Object Counting (Present) solution is composed of three functional stages:

    1. Object Detection: Uses a model (like model.yolo) to identify bounding boxes [x1, y1, x2, y2] for specific object categories in the video feed.
    2. Count Detections: The dabble.bbox_count node sums the number of bounding boxes detected for the specified object category.
    3. Calculate Statistics: The dabble.statistics node processes the counts from each frame to calculate cumulative metrics: cum_avg (cumulative average), cum_max (cumulative maximum), and cum_min (cumulative minimum).

    This is distinct from advanced counting tasks like tracking objects over time or counting within specific zones.

  4. Use Object Detection for Social Distancing (Resource-Limited Devices)

    main

    If you are running on resource-constrained hardware like a Raspberry Pi, you can replace pose estimation with object detection. This is often more efficient as lightweight object detectors typically perform better than lightweight pose estimation models.

    Implementation Steps:

    1. Replace the model.posenet node with an object detection model node.
    2. Replace the dabble.keypoints_to_3d_loc node with the dabble.bbox_to_3d_loc node.

    Trade-offs:

    • Accuracy: Distance estimation will be less accurate because the bounding box height changes if a person sits or bends, whereas pose estimation relies on skeletal points.
  5. Data type conventions for custom object detection models

    main

    When building custom object detection model nodes in PeekingDuck, you should adhere to the project's standard data type conventions to ensure compatibility with existing nodes (like input.visual for reading sources or draw.bbox for visualization).

    Input Requirements:

    • Receive the img data type.
    • The img data must be in BGR format.

    Output Requirements: Your model should produce the following data types:

    • bboxes: A NumPy array of the expected shape.
    • bbox_labels: Labels associated with the bounding boxes.
    • bbox_scores: Confidence scores for the detections.
  6. How privacy protection works in PeekingDuck

    main

    The privacy protection solution follows a two-step process:

    1. Segmentation: An instance segmentation model (like model.mask_rcnn) identifies the masks for sensitive objects such as persons, laptops, or computer screens. The mask is a single-channel binary image where 1 indicates the presence of the object class and 0 indicates absence.
    2. De-identification: The draw.instance_mask node applies a Gaussian blur or a mosaic (pixelation) effect to the pixels where the mask value is 1.
  7. Compare model.yolo_face and model.mtcnn nodes

    main

    When implementing face detection, choose between these two nodes based on your requirements:

    • model.yolo_face: Use this if you need to classify whether a face is wearing a mask or not. It uses YOLOv4/YOLOv4-tiny to identify bounding boxes and assign classes (no_mask = 0 or mask = 1).
    • model.mtcnn: Use this if you only need to detect the presence of human faces without the need for mask classification.
  8. How People Counting (Over Time) works

    main

    The people counting over time use case follows a three-step process:

    1. Human Detection: Uses the model.jde node to detect persons and provide bounding box coordinates [x1, y1, x2, y2].
    2. Appearance Embedding Tracking: Uses a metric learning algorithm with triplet loss, the Hungarian algorithm for assignment, and a Kalman filter for trajectory smoothing. This assigns a unique ID to each detected person.
    3. Incrementing the Count: New unique persons are assigned monotonically increasing integer IDs starting from 0. The total count of unique persons is calculated as the cumulative maximum (cum_max) of these IDs.
  9. Create custom PeekingDuck nodes

    main
    While PeekingDuck offers many built-in nodes for the use cases mentioned above, you can extend the library by creating your own custom nodes. This allows you to tailor the CV pipeline to your specific requirements. For detailed instructions on how to implement a custom node, refer to the custom nodes tutorial in the documentation.