Metadata-Version: 2.5
Name: seetapsych-gaze-follow
Version: 0.0.3
Summary: Gaze following estimation modules for SeetaPsych
Project-URL: Homepage, https://github.com/seetapsych/seetapsych-gaze-follow
Project-URL: Repository, https://github.com/seetapsych/seetapsych-gaze-follow
Project-URL: Issues, https://github.com/seetapsych/seetapsych-gaze-follow/issues
License: BSD 3-Clause License
        
        Copyright (c) 2026, Visual Information Processing and Learning (VIPL) group,
        Institute of Computing Technology, Chinese Academy of Sciences, Beijing, China;
        Southeast University, China;
        Beijing Seetatech Co., Ltd.
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its
           contributors may be used to endorse or promote products derived from
           this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
        LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
        CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
        SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
        INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
        CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
        ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        POSSIBILITY OF SUCH DAMAGE.
License-File: LICENSE
Requires-Python: >=3.10
Requires-Dist: seetapsych-lib
Provides-Extra: all
Requires-Dist: einops>=0.8.2; extra == 'all'
Requires-Dist: hydra-core>=1.3.5; extra == 'all'
Requires-Dist: timm>=1.0.28; extra == 'all'
Requires-Dist: torch>=2.9.1; extra == 'all'
Requires-Dist: torchvision>=0.24.1; extra == 'all'
Requires-Dist: ultralytics>=8.4.123; extra == 'all'
Provides-Extra: dev
Requires-Dist: bandit>=1.7; extra == 'dev'
Requires-Dist: build>=1.4.4; extra == 'dev'
Requires-Dist: einops>=0.8.2; extra == 'dev'
Requires-Dist: hydra-core>=1.3.5; extra == 'dev'
Requires-Dist: mypy>=1.11; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Requires-Dist: scipy-stubs>=1.15.3.0; extra == 'dev'
Requires-Dist: timm>=1.0.28; extra == 'dev'
Requires-Dist: torch>=2.9.1; extra == 'dev'
Requires-Dist: torchvision>=0.24.1; extra == 'dev'
Requires-Dist: twine>=6.2.0; extra == 'dev'
Requires-Dist: ultralytics>=8.4.123; extra == 'dev'
Description-Content-Type: text/markdown

# SeetaPsych Gaze Follow

> Gaze following estimation modules for SeetaPsych. Detects heads in scene and estimates where each person is looking (gaze point on image plane, and social gaze relations between people).

## Usage

This project is already included in the seetapsych-lib default configuration. Download and use it via `seetapsych-manager download`.

For usage, refer to [SeetaPsych](https://github.com/seetapsych/seetapsych-lib).

Install optional algorithm dependencies:

```bash
uv pip install seetapsych-gaze-follow[all]
```

The algorithm modules automatically download model weights from ModelScope on first use, so the initial run may be slower due to model downloading.

You can additionally add this algorithm module using the following methods.

### WebUI

Run `seetapsych-webui` with the `--files` argument to use it.

```
seetapsych-webui --files \
  seetapsych_gaze_follow/modules/head_detection.yml \
  seetapsych_gaze_follow/modules/cosi.yml
```

### Programmatic Usage

Add the following code in your program to use this algorithm module.

```python
from seetapsych_lib.runtime.factory import Factory
from seetapsych_lib.runtime.pipeline import Pipeline

factory = Factory()
factory.load_file_modules("seetapsych_gaze_follow/modules/head_detection.yml")
factory.load_file_modules("seetapsych_gaze_follow/modules/cosi.yml")

pipeline = Pipeline(factory, ...)

pipeline.add_attributes("head/detection", "head/gaze_point")
# Or for dyadic social gaze:
# pipeline.add_attributes('head/detection', 'head/social_gaze')
```

### Module Catalog

| YAML Path | Packages |
|---|---|
| [head_detection.yml](seetapsych_gaze_follow/modules/head_detection.yml) | HeadDetection-CoSIGaze, HeadSelection |
| [cosi.yml](seetapsych_gaze_follow/modules/cosi.yml) | SceneGazeFollow-CoSIGaze, SocialGaze-CoSIGaze |

## Module Pipeline

The gaze following pipeline consists of two stages loaded from separate module configs:

1. **HeadDetection** ([head_detection.yml](seetapsych_gaze_follow/modules/head_detection.yml)) — multi-head detector, plus an optional HeadSelection post-processor.
2. **CoSI** ([cosi.yml](seetapsych_gaze_follow/modules/cosi.yml)) — confidence-coordinated spatial integration model for gaze point and social gaze relation prediction.

Dependency graph:
- `head/detection` → `head/gaze_point` (single-person gaze following)
- `head/detection` → `head/social_gaze` (dyadic social gaze, requires ≥ 2 detected heads)

### HeadDetection

Ultralytics multi-person head detector with pluggable selection/sorting post-process, used as the front-end for CoSI gaze-following models.

Module config: [head_detection.yml](seetapsych_gaze_follow/modules/head_detection.yml)

| Package Name | Provides Attributes | Requires Attributes |
|---|---|---|
| HeadDetection-CoSIGaze | head/detection | *(none)* |
| HeadSelection | head/selection, head/detection | head/detection |

#### HeadDetection-CoSIGaze

**Description**: multi-person head detector with configurable confidence and NMS thresholds; produces head bounding boxes consumed by CoSI gaze-following and social-gaze packages.

**Parameters**

| Name | Type | Default | Description |
|---|---|---|---|
| img_size | integer | 640 | Input image size for inference, larger values improve small-head recall but increase latency and VRAM usage; keep as multiples of 32 (640 is a balanced default). |
| conf | number | 0.25 | Minimum detection confidence threshold, raise to reduce false positives in crowded scenes (0.35-0.5 typical), lower to recover faraway/occluded heads (0.15-0.2). |
| iou | number | 0.45 | NMS IoU threshold for duplicate suppression, lower (0.3-0.4) removes more overlapping boxes for dense crowds, higher (0.5-0.6) keeps more candidates for closely-spaced heads. |
| max_det | integer | 20 | Maximum detection boxes kept per frame after NMS; set to the expected upper bound of simultaneous people in the scene (e.g. 2-4 for dyads, 10-20 for audiences) to avoid noisy downstream cost. |

**Models**

| Name | Recommended |
|---|---|
| seeta-gaze-follow-yolo_head.pt | ✓ |

#### HeadSelection

**Description**: Post-process that selects top-N head detections by size or confidence, then reorders them spatially (left-right/top-bottom) before passing to downstream gaze-following or social-gaze modules.

**Parameters**

| Name | Type | Default | Selection | Description |
|---|---|---|---|---|
| count | integer | 1 | — | Number of heads to keep after selection; match the number of tracked people in the scene, e.g. 1 for single-target, 2 for dyadic social-gaze analysis. |
| method | selection | max_size | max_size, max_confidence | Criterion used to pick the top-N heads. Use max_size to prefer closest/largest heads (dominant foreground person); use max_confidence when occlusion is rare and detector score is trustworthy. |
| sort | selection | left-right | left-right, right-left, top-bottom, bottom-top | Spatial order applied after selection. left-right matches screen reading order and is recommended for dyadic social-gaze (left = principal, right = associate); top-bottom is better for vertically stacked layouts. |

**Models**: *(none)*

### CoSIGaze

Confidence-coordinated Spatial Integration (CoSI) transformer for multi-person gaze following and dyadic social-gaze relation classification from a single RGB scene image.

Module config: [cosi.yml](seetapsych_gaze_follow/modules/cosi.yml)

| Package Name | Provides Attributes | Requires Attributes |
|---|---|---|
| SceneGazeFollow-CoSIGaze | head/gaze_point | head/detection |
| SocialGaze-CoSIGaze | head/social_gaze | head/detection |

#### SceneGazeFollow-CoSIGaze

**Description**: Per-head scene-level gaze-following with CoSI transformer; for every input head box returns a 2D gaze target point (gaze_point_px) and a per-pixel gaze heatmap on the original scene image.

**Parameters**: *(none)*

**Models**

| Name | Recommended |
|---|---|
| seeta-gaze-follow-cosi_weights.pth | ✓ |

#### SocialGaze-CoSIGaze

**Description**: Dyadic social-gaze relation classifier using the shared CoSI transformer backbone; picks the top-2 most confident heads ordered horizontally (left = principal, right = associate) and predicts a 5-class relation, plus per-person gaze point and heatmap.

**Parameters**: *(none)*

**Models**

| Name | Recommended |
|---|---|
| seeta-gaze-follow-cosi_weights.pth | ✓ |

**SocialGaze class mapping** (social_gaze_id → social_gaze_label):

| ID | Label |
|---|---|
| 0 | share |
| 1 | mutual |
| 2 | single |
| 3 | miss |
| 4 | void |
