hifd 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. hifd-0.1.0/CHANGELOG.md +25 -0
  2. hifd-0.1.0/LICENSE +21 -0
  3. hifd-0.1.0/PKG-INFO +153 -0
  4. hifd-0.1.0/README.md +98 -0
  5. hifd-0.1.0/docs/schema.md +122 -0
  6. hifd-0.1.0/pyproject.toml +75 -0
  7. hifd-0.1.0/src/hifd/__init__.py +77 -0
  8. hifd-0.1.0/src/hifd/aggregation.py +87 -0
  9. hifd-0.1.0/src/hifd/cli.py +182 -0
  10. hifd-0.1.0/src/hifd/composite.py +64 -0
  11. hifd-0.1.0/src/hifd/constants.py +32 -0
  12. hifd-0.1.0/src/hifd/io.py +223 -0
  13. hifd-0.1.0/src/hifd/pipeline.py +391 -0
  14. hifd-0.1.0/src/hifd/py.typed +0 -0
  15. hifd-0.1.0/src/hifd/scores/__init__.py +0 -0
  16. hifd-0.1.0/src/hifd/scores/agreement.py +109 -0
  17. hifd-0.1.0/src/hifd/scores/privacy.py +38 -0
  18. hifd-0.1.0/src/hifd/scores/quality.py +28 -0
  19. hifd-0.1.0/tests/__init__.py +0 -0
  20. hifd-0.1.0/tests/_build_fixtures.py +127 -0
  21. hifd-0.1.0/tests/_estimators_fixture.txt +56 -0
  22. hifd-0.1.0/tests/conftest.py +13 -0
  23. hifd-0.1.0/tests/fixtures/mini/estimators.yaml +56 -0
  24. hifd-0.1.0/tests/fixtures/mini/expected.json +22 -0
  25. hifd-0.1.0/tests/fixtures/mini/methods/methodA/age/deid.json +17 -0
  26. hifd-0.1.0/tests/fixtures/mini/methods/methodA/ethnicity/deid.json +34 -0
  27. hifd-0.1.0/tests/fixtures/mini/methods/methodA/face_embedding/adaface_deid.json +29 -0
  28. hifd-0.1.0/tests/fixtures/mini/methods/methodA/face_embedding/arcface_deid.json +29 -0
  29. hifd-0.1.0/tests/fixtures/mini/methods/methodA/face_embedding/cosface_deid.json +29 -0
  30. hifd-0.1.0/tests/fixtures/mini/methods/methodA/gaze/deid.json +29 -0
  31. hifd-0.1.0/tests/fixtures/mini/methods/methodA/gender/deid.json +30 -0
  32. hifd-0.1.0/tests/fixtures/mini/methods/methodA/landmark/deid.json +68 -0
  33. hifd-0.1.0/tests/fixtures/mini/methods/methodA/macro_exp/deid.json +30 -0
  34. hifd-0.1.0/tests/fixtures/mini/methods/methodA/micro_exp/deid.json +30 -0
  35. hifd-0.1.0/tests/fixtures/mini/methods/methodA/niqe/deid.json +17 -0
  36. hifd-0.1.0/tests/fixtures/mini/methods/methodA/rppg/deid.json +207 -0
  37. hifd-0.1.0/tests/fixtures/mini/methods/methodB/age/deid.json +17 -0
  38. hifd-0.1.0/tests/fixtures/mini/methods/methodB/ethnicity/deid.json +34 -0
  39. hifd-0.1.0/tests/fixtures/mini/methods/methodB/face_embedding/adaface_deid.json +29 -0
  40. hifd-0.1.0/tests/fixtures/mini/methods/methodB/face_embedding/arcface_deid.json +29 -0
  41. hifd-0.1.0/tests/fixtures/mini/methods/methodB/face_embedding/cosface_deid.json +29 -0
  42. hifd-0.1.0/tests/fixtures/mini/methods/methodB/gaze/deid.json +29 -0
  43. hifd-0.1.0/tests/fixtures/mini/methods/methodB/gender/deid.json +30 -0
  44. hifd-0.1.0/tests/fixtures/mini/methods/methodB/landmark/deid.json +68 -0
  45. hifd-0.1.0/tests/fixtures/mini/methods/methodB/macro_exp/deid.json +30 -0
  46. hifd-0.1.0/tests/fixtures/mini/methods/methodB/micro_exp/deid.json +30 -0
  47. hifd-0.1.0/tests/fixtures/mini/methods/methodB/niqe/deid.json +17 -0
  48. hifd-0.1.0/tests/fixtures/mini/methods/methodB/rppg/deid.json +207 -0
  49. hifd-0.1.0/tests/fixtures/mini/methods.yaml +7 -0
  50. hifd-0.1.0/tests/fixtures/mini/utilface/age/orig.json +17 -0
  51. hifd-0.1.0/tests/fixtures/mini/utilface/ethnicity/orig.json +34 -0
  52. hifd-0.1.0/tests/fixtures/mini/utilface/face_embedding/adaface_orig.json +29 -0
  53. hifd-0.1.0/tests/fixtures/mini/utilface/face_embedding/arcface_orig.json +29 -0
  54. hifd-0.1.0/tests/fixtures/mini/utilface/face_embedding/cosface_orig.json +29 -0
  55. hifd-0.1.0/tests/fixtures/mini/utilface/gaze/orig.json +29 -0
  56. hifd-0.1.0/tests/fixtures/mini/utilface/gender/orig.json +30 -0
  57. hifd-0.1.0/tests/fixtures/mini/utilface/landmark/orig.json +68 -0
  58. hifd-0.1.0/tests/fixtures/mini/utilface/macro_exp/orig.json +30 -0
  59. hifd-0.1.0/tests/fixtures/mini/utilface/micro_exp/orig.json +30 -0
  60. hifd-0.1.0/tests/fixtures/mini/utilface/rppg/orig.json +207 -0
  61. hifd-0.1.0/tests/test_aggregation.py +54 -0
  62. hifd-0.1.0/tests/test_agreement.py +148 -0
  63. hifd-0.1.0/tests/test_cli.py +191 -0
  64. hifd-0.1.0/tests/test_composite.py +68 -0
  65. hifd-0.1.0/tests/test_constants.py +65 -0
  66. hifd-0.1.0/tests/test_io.py +193 -0
  67. hifd-0.1.0/tests/test_pipeline.py +67 -0
  68. hifd-0.1.0/tests/test_privacy.py +47 -0
  69. hifd-0.1.0/tests/test_quality.py +41 -0
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+
3
+ All notable changes to `hifd` will be documented here. This project follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and adheres to
5
+ [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0] — 2026-05-23
10
+
11
+ ### Added
12
+ - Initial release.
13
+ - Per-task agreement primitives: `score_age`, `score_categorical`,
14
+ `score_landmark`, `score_gaze`, `score_bvp`, `score_hr`.
15
+ - Privacy (`privacy_score`, `privacy_ensemble`) and quality (`quality_score`)
16
+ primitives, with batch variants for the scalar-input ones.
17
+ - Utility levels `U1` / `U2` / `U3` and per-method aggregation.
18
+ - Composite HiFD score (`composite`, `compose_profiles`) under three default
19
+ application profiles (Privacy-First, Balanced, Clinical).
20
+ - JSON envelope IO (schema version `1.0`) with full validation.
21
+ - High-level `run_pipeline` orchestrator producing per_sample / per_method /
22
+ composite CSVs plus a LaTeX-ready composite table.
23
+ - `hifd` CLI: `validate`, `compute-agreements`, `aggregate`, `compose`,
24
+ `run-all`, `version`.
25
+ - PEP 561 type information (`py.typed`).
hifd-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 InfraFace
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
hifd-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,153 @@
1
+ Metadata-Version: 2.4
2
+ Name: hifd
3
+ Version: 0.1.0
4
+ Summary: HiFD: a holistic metric for face de-identification evaluation.
5
+ Project-URL: Homepage, https://github.com/infraface/hifd
6
+ Project-URL: Documentation, https://github.com/infraface/hifd#readme
7
+ Project-URL: Issues, https://github.com/infraface/hifd/issues
8
+ Project-URL: Source, https://github.com/infraface/hifd
9
+ Author-email: Hui Wei <huiwei.truth@gmail.com>
10
+ License: MIT License
11
+
12
+ Copyright (c) 2026 InfraFace
13
+
14
+ Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ of this software and associated documentation files (the "Software"), to deal
16
+ in the Software without restriction, including without limitation the rights
17
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ copies of the Software, and to permit persons to whom the Software is
19
+ furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all
22
+ copies or substantial portions of the Software.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
+ SOFTWARE.
31
+ License-File: LICENSE
32
+ Keywords: benchmark,computer-vision,face-de-identification,metric,privacy
33
+ Classifier: Development Status :: 4 - Beta
34
+ Classifier: Intended Audience :: Science/Research
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Classifier: Programming Language :: Python :: 3
37
+ Classifier: Programming Language :: Python :: 3.10
38
+ Classifier: Programming Language :: Python :: 3.11
39
+ Classifier: Programming Language :: Python :: 3.12
40
+ Classifier: Programming Language :: Python :: 3.13
41
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
42
+ Requires-Python: >=3.10
43
+ Requires-Dist: numpy>=1.24
44
+ Requires-Dist: pandas>=2.0
45
+ Requires-Dist: pyyaml>=6.0
46
+ Provides-Extra: dev
47
+ Requires-Dist: build>=1.0; extra == 'dev'
48
+ Requires-Dist: mypy>=1.8; extra == 'dev'
49
+ Requires-Dist: pytest-cov>=4.1; extra == 'dev'
50
+ Requires-Dist: pytest>=7.4; extra == 'dev'
51
+ Requires-Dist: ruff>=0.5; extra == 'dev'
52
+ Requires-Dist: twine>=5.0; extra == 'dev'
53
+ Requires-Dist: types-pyyaml>=6.0; extra == 'dev'
54
+ Description-Content-Type: text/markdown
55
+
56
+ # hifd
57
+
58
+ [![CI](https://github.com/infraface/hifd/actions/workflows/ci.yml/badge.svg)](https://github.com/infraface/hifd/actions/workflows/ci.yml)
59
+
60
+ **HiFD** is a holistic metric for evaluating face de-identification methods.
61
+ It combines privacy (face-recognition resistance), perceptual quality, and
62
+ three levels of utility preservation (macro cues, fine-grained cues,
63
+ physiological signals) into a single composite score.
64
+
65
+ This package provides the **scoring core**: given JSON files of pre-computed
66
+ estimator predictions on (a) original images and (b) de-identified outputs,
67
+ `hifd` produces per-sample agreement scores, per-method utility levels,
68
+ ensemble privacy, quality, and composite HiFD scores under three application
69
+ profiles (Privacy-First, Balanced, Clinical).
70
+
71
+ The package does **not** run the estimators themselves — you bring your own
72
+ predictions in the [documented JSON schema](docs/schema.md).
73
+
74
+ ## Install
75
+
76
+ ```bash
77
+ pip install hifd
78
+ ```
79
+
80
+ Runtime requirements: Python ≥ 3.10, numpy, pandas, pyyaml.
81
+
82
+ ## Quickstart (CLI)
83
+
84
+ ```bash
85
+ hifd run-all \
86
+ --methods methods.yaml \
87
+ --estimators estimators.yaml \
88
+ --data-dir predictions/ \
89
+ --out scores/
90
+ ```
91
+
92
+ Produces:
93
+
94
+ ```
95
+ scores/
96
+ ├── per_sample/per_sample_agreements.csv
97
+ ├── per_method/per_method_aggregated.csv
98
+ ├── per_method/method_level.csv
99
+ ├── tables/composite.csv
100
+ └── tables/composite.tex
101
+ ```
102
+
103
+ ## Quickstart (Python API)
104
+
105
+ ```python
106
+ import hifd
107
+ import numpy as np
108
+
109
+ # Per-task primitives (scalar)
110
+ hifd.score_age(35.0, 36.0) # 0.99
111
+ hifd.score_gaze([0, 0, 1], [0, 0.1, 1]) # ≈ 0.937
112
+
113
+ # Batch variants for scalar-input primitives
114
+ hifd.batch_score_age(np.array([35.0]), np.array([36.0])) # ndarray([0.99])
115
+ # Also: batch_score_categorical, batch_score_hr, batch_privacy_score,
116
+ # batch_quality_score, batch_U1, batch_U2, batch_U3
117
+ # (Geometric primitives — score_landmark, score_gaze, score_bvp — have no
118
+ # batch form because their inputs are per-sample variable-shape arrays.)
119
+
120
+ # Composite under a profile
121
+ hifd.composite(P=0.7, Q=0.8, U1=0.6, U2=0.5, U3=0.4,
122
+ weights=hifd.DEFAULT_PROFILES["balanced"])
123
+
124
+ # Full pipeline
125
+ r = hifd.run_pipeline(
126
+ methods_config="methods.yaml",
127
+ estimators_config="estimators.yaml",
128
+ data_dir="predictions/",
129
+ out_dir="scores/",
130
+ )
131
+ print(r.composite_df)
132
+ ```
133
+
134
+ ## Input format
135
+
136
+ See [docs/schema.md](docs/schema.md) for the JSON envelope spec and one example
137
+ per task type.
138
+
139
+ ## Defaults
140
+
141
+ Constants and profiles ship as immutable mappings:
142
+
143
+ ```python
144
+ hifd.DEFAULT_CONSTANTS["tau_HR"] # 20.0
145
+ hifd.DEFAULT_PROFILES["balanced"] # {"P": 0.2, "Q": 0.2, "U1": 0.2, ...}
146
+ ```
147
+
148
+ To override, build a plain dict and pass it (`run_pipeline(constants=...)`) or
149
+ provide `--constants my.yaml` on the CLI.
150
+
151
+ ## Citation
152
+
153
+ If you use HiFD in published work, please cite the paper [TBD].
hifd-0.1.0/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # hifd
2
+
3
+ [![CI](https://github.com/infraface/hifd/actions/workflows/ci.yml/badge.svg)](https://github.com/infraface/hifd/actions/workflows/ci.yml)
4
+
5
+ **HiFD** is a holistic metric for evaluating face de-identification methods.
6
+ It combines privacy (face-recognition resistance), perceptual quality, and
7
+ three levels of utility preservation (macro cues, fine-grained cues,
8
+ physiological signals) into a single composite score.
9
+
10
+ This package provides the **scoring core**: given JSON files of pre-computed
11
+ estimator predictions on (a) original images and (b) de-identified outputs,
12
+ `hifd` produces per-sample agreement scores, per-method utility levels,
13
+ ensemble privacy, quality, and composite HiFD scores under three application
14
+ profiles (Privacy-First, Balanced, Clinical).
15
+
16
+ The package does **not** run the estimators themselves — you bring your own
17
+ predictions in the [documented JSON schema](docs/schema.md).
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ pip install hifd
23
+ ```
24
+
25
+ Runtime requirements: Python ≥ 3.10, numpy, pandas, pyyaml.
26
+
27
+ ## Quickstart (CLI)
28
+
29
+ ```bash
30
+ hifd run-all \
31
+ --methods methods.yaml \
32
+ --estimators estimators.yaml \
33
+ --data-dir predictions/ \
34
+ --out scores/
35
+ ```
36
+
37
+ Produces:
38
+
39
+ ```
40
+ scores/
41
+ ├── per_sample/per_sample_agreements.csv
42
+ ├── per_method/per_method_aggregated.csv
43
+ ├── per_method/method_level.csv
44
+ ├── tables/composite.csv
45
+ └── tables/composite.tex
46
+ ```
47
+
48
+ ## Quickstart (Python API)
49
+
50
+ ```python
51
+ import hifd
52
+ import numpy as np
53
+
54
+ # Per-task primitives (scalar)
55
+ hifd.score_age(35.0, 36.0) # 0.99
56
+ hifd.score_gaze([0, 0, 1], [0, 0.1, 1]) # ≈ 0.937
57
+
58
+ # Batch variants for scalar-input primitives
59
+ hifd.batch_score_age(np.array([35.0]), np.array([36.0])) # ndarray([0.99])
60
+ # Also: batch_score_categorical, batch_score_hr, batch_privacy_score,
61
+ # batch_quality_score, batch_U1, batch_U2, batch_U3
62
+ # (Geometric primitives — score_landmark, score_gaze, score_bvp — have no
63
+ # batch form because their inputs are per-sample variable-shape arrays.)
64
+
65
+ # Composite under a profile
66
+ hifd.composite(P=0.7, Q=0.8, U1=0.6, U2=0.5, U3=0.4,
67
+ weights=hifd.DEFAULT_PROFILES["balanced"])
68
+
69
+ # Full pipeline
70
+ r = hifd.run_pipeline(
71
+ methods_config="methods.yaml",
72
+ estimators_config="estimators.yaml",
73
+ data_dir="predictions/",
74
+ out_dir="scores/",
75
+ )
76
+ print(r.composite_df)
77
+ ```
78
+
79
+ ## Input format
80
+
81
+ See [docs/schema.md](docs/schema.md) for the JSON envelope spec and one example
82
+ per task type.
83
+
84
+ ## Defaults
85
+
86
+ Constants and profiles ship as immutable mappings:
87
+
88
+ ```python
89
+ hifd.DEFAULT_CONSTANTS["tau_HR"] # 20.0
90
+ hifd.DEFAULT_PROFILES["balanced"] # {"P": 0.2, "Q": 0.2, "U1": 0.2, ...}
91
+ ```
92
+
93
+ To override, build a plain dict and pass it (`run_pipeline(constants=...)`) or
94
+ provide `--constants my.yaml` on the CLI.
95
+
96
+ ## Citation
97
+
98
+ If you use HiFD in published work, please cite the paper [TBD].
@@ -0,0 +1,122 @@
1
+ # JSON envelope (schema version 1.0)
2
+
3
+ Every prediction file is a JSON object with this envelope:
4
+
5
+ ```json
6
+ {
7
+ "task": "age",
8
+ "source": "original",
9
+ "estimator": "mivolo",
10
+ "schema_version": "1.0",
11
+ "predictions": { "<sample_id>": { ... }, ... }
12
+ }
13
+ ```
14
+
15
+ - `task` — one of: `age`, `gender`, `ethnicity`, `macro_exp`, `micro_exp`,
16
+ `landmark`, `gaze`, `rppg`, `face_embedding`, `niqe`.
17
+ - `source` — `original` for the un-modified images, `deid` for the
18
+ de-identified outputs.
19
+ - `estimator` — a free-form string identifying the model.
20
+ - `schema_version` — must be exactly `"1.0"` for this release.
21
+ - `predictions` — a dict mapping sample IDs to task-specific payloads (below).
22
+
23
+ Categorical tasks also require a top-level `class_names: [...]` list whose
24
+ order matches the per-sample `probs` arrays. rPPG files may include a top-level
25
+ `fps` integer.
26
+
27
+ ## Per-task payloads
28
+
29
+ ### `age`
30
+
31
+ ```json
32
+ {"value": 32.5}
33
+ ```
34
+
35
+ ### `gender` / `ethnicity` / `macro_exp` / `micro_exp`
36
+
37
+ ```json
38
+ {"probs": [0.92, 0.08]}
39
+ ```
40
+
41
+ `probs` must sum to ~1 (off by < 1e-4 is auto-renormalized with a warning);
42
+ length must equal the envelope's `class_names`.
43
+
44
+ ### `landmark`
45
+
46
+ ```json
47
+ {
48
+ "points": [[10.0, 20.0], [30.0, 40.0], ...],
49
+ "left_eye_center": [45.0, 50.0],
50
+ "right_eye_center": [75.0, 50.0]
51
+ }
52
+ ```
53
+
54
+ Original and de-id must have the same number of points per sample.
55
+
56
+ ### `gaze`
57
+
58
+ ```json
59
+ {"direction": [0.0, 0.0, 1.0]}
60
+ ```
61
+
62
+ A 3-vector. Normalization is applied internally; magnitude doesn't matter.
63
+
64
+ ### `rppg`
65
+
66
+ ```json
67
+ {"bvp": [0.1, 0.2, ...], "hr_bpm": 72.0, "fps": 30}
68
+ ```
69
+
70
+ `fps` may also be set at the envelope top-level. Original and de-id must
71
+ match `fps`; BVP lengths may differ by up to 1 second.
72
+
73
+ ### `face_embedding`
74
+
75
+ ```json
76
+ {"embedding": [0.013, -0.241, ...]}
77
+ ```
78
+
79
+ D-dimensional vector. Normalization is applied internally.
80
+
81
+ ### `niqe`
82
+
83
+ ```json
84
+ {"niqe": 3.42}
85
+ ```
86
+
87
+ NIQE is no-reference, so only the de-id file is read.
88
+
89
+ ## Multiple estimators per task
90
+
91
+ Tasks may have several estimator JSONs (e.g. `face_embedding` typically has
92
+ `arcface_*`, `cosface_*`, `adaface_*`). They are listed in
93
+ `estimators.yaml`:
94
+
95
+ ```yaml
96
+ tasks:
97
+ face_embedding:
98
+ estimators:
99
+ - name: arcface
100
+ orig_json: face_embedding/arcface_orig.json
101
+ deid_json: face_embedding/arcface_deid.json
102
+ - name: cosface
103
+ orig_json: face_embedding/cosface_orig.json
104
+ deid_json: face_embedding/cosface_deid.json
105
+ ```
106
+
107
+ ## methods.yaml
108
+
109
+ ```yaml
110
+ original:
111
+ base_path: utilface
112
+ methods:
113
+ - name: MyMethod
114
+ base_path: methods/MyMethod
115
+ ```
116
+
117
+ Paths are relative to `--data-dir`.
118
+
119
+ ## Compatibility
120
+
121
+ A loader that sees a `schema_version` other than `"1.0"` raises `ValueError`.
122
+ Bumping the schema is a major-version event.
@@ -0,0 +1,75 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.21"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "hifd"
7
+ version = "0.1.0"
8
+ description = "HiFD: a holistic metric for face de-identification evaluation."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = { file = "LICENSE" }
12
+ authors = [{ name = "Hui Wei", email = "huiwei.truth@gmail.com" }]
13
+ keywords = ["face-de-identification", "privacy", "metric", "benchmark", "computer-vision"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Science/Research",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Topic :: Scientific/Engineering :: Image Recognition",
24
+ ]
25
+
26
+ dependencies = [
27
+ "numpy>=1.24",
28
+ "pandas>=2.0",
29
+ "pyyaml>=6.0",
30
+ ]
31
+
32
+ [project.optional-dependencies]
33
+ dev = [
34
+ "pytest>=7.4",
35
+ "pytest-cov>=4.1",
36
+ "mypy>=1.8",
37
+ "ruff>=0.5",
38
+ "types-PyYAML>=6.0",
39
+ "build>=1.0",
40
+ "twine>=5.0",
41
+ ]
42
+
43
+ [project.scripts]
44
+ hifd = "hifd.cli:main"
45
+
46
+ [project.urls]
47
+ Homepage = "https://github.com/infraface/hifd"
48
+ Documentation = "https://github.com/infraface/hifd#readme"
49
+ Issues = "https://github.com/infraface/hifd/issues"
50
+ Source = "https://github.com/infraface/hifd"
51
+
52
+ [tool.hatch.build.targets.wheel]
53
+ packages = ["src/hifd"]
54
+
55
+ [tool.hatch.build.targets.wheel.force-include]
56
+ "src/hifd/py.typed" = "hifd/py.typed"
57
+
58
+ [tool.hatch.build.targets.sdist]
59
+ include = ["src/hifd", "tests", "README.md", "LICENSE", "CHANGELOG.md", "docs"]
60
+
61
+ [tool.pytest.ini_options]
62
+ testpaths = ["tests"]
63
+ addopts = "-ra --strict-markers"
64
+
65
+ [tool.ruff]
66
+ target-version = "py310"
67
+ line-length = 100
68
+
69
+ [tool.ruff.lint]
70
+ select = ["E", "F", "I", "B", "UP", "SIM", "RUF"]
71
+
72
+ [tool.mypy]
73
+ python_version = "3.10"
74
+ strict = true
75
+ files = ["src/hifd"]
@@ -0,0 +1,77 @@
1
+ """HiFD: a holistic metric for face de-identification evaluation."""
2
+
3
+ from __future__ import annotations
4
+
5
+ __version__ = "0.1.0"
6
+
7
+ from .aggregation import (
8
+ U1,
9
+ U2,
10
+ U3,
11
+ aggregate_method_scores,
12
+ batch_U1,
13
+ batch_U2,
14
+ batch_U3,
15
+ )
16
+ from .composite import compose_profiles, composite, load_profiles_yaml
17
+ from .constants import DEFAULT_CONSTANTS, DEFAULT_PROFILES, SCHEMA_VERSION
18
+ from .io import load_pair, load_predictions, validate_pair
19
+ from .pipeline import (
20
+ PipelineResult,
21
+ aggregate,
22
+ compose,
23
+ compute_agreements,
24
+ run_pipeline,
25
+ )
26
+ from .scores.agreement import (
27
+ batch_score_age,
28
+ batch_score_categorical,
29
+ batch_score_hr,
30
+ score_age,
31
+ score_bvp,
32
+ score_categorical,
33
+ score_gaze,
34
+ score_hr,
35
+ score_landmark,
36
+ )
37
+ from .scores.privacy import batch_privacy_score, privacy_ensemble, privacy_score
38
+ from .scores.quality import batch_quality_score, quality_score
39
+
40
+ __all__ = [
41
+ "DEFAULT_CONSTANTS",
42
+ "DEFAULT_PROFILES",
43
+ "SCHEMA_VERSION",
44
+ "U1",
45
+ "U2",
46
+ "U3",
47
+ "PipelineResult",
48
+ "__version__",
49
+ "aggregate",
50
+ "aggregate_method_scores",
51
+ "batch_U1",
52
+ "batch_U2",
53
+ "batch_U3",
54
+ "batch_privacy_score",
55
+ "batch_quality_score",
56
+ "batch_score_age",
57
+ "batch_score_categorical",
58
+ "batch_score_hr",
59
+ "compose",
60
+ "compose_profiles",
61
+ "composite",
62
+ "compute_agreements",
63
+ "load_pair",
64
+ "load_predictions",
65
+ "load_profiles_yaml",
66
+ "privacy_ensemble",
67
+ "privacy_score",
68
+ "quality_score",
69
+ "run_pipeline",
70
+ "score_age",
71
+ "score_bvp",
72
+ "score_categorical",
73
+ "score_gaze",
74
+ "score_hr",
75
+ "score_landmark",
76
+ "validate_pair",
77
+ ]
@@ -0,0 +1,87 @@
1
+ """Utility-level aggregation: per-sample U1/U2/U3 and per-method aggregation."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, cast
6
+
7
+ import numpy as np
8
+ import pandas as pd # type: ignore[import-untyped]
9
+ from numpy.typing import NDArray
10
+
11
+ # ----- 5.1 Per-sample level scores -------------------------------------------
12
+
13
+ def U1(s_age: float, s_gender: float, s_eth: float, s_macro: float, s_lmk: float) -> float:
14
+ return float(np.mean([s_age, s_gender, s_eth, s_macro, s_lmk]))
15
+
16
+
17
+ def U2(s_gaze: float, s_me: float | None = None) -> float:
18
+ if s_me is not None:
19
+ return 0.5 * (s_gaze + s_me)
20
+ return s_gaze
21
+
22
+
23
+ def U3(bvp_scores: list[float], hr_scores: list[float]) -> float:
24
+ per_est = 0.5 * (np.asarray(bvp_scores) + np.asarray(hr_scores))
25
+ return float(np.mean(per_est))
26
+
27
+
28
+ # ----- Vectorized versions ---------------------------------------------------
29
+
30
+ def batch_U1(
31
+ s_age: NDArray[np.floating[Any]],
32
+ s_gender: NDArray[np.floating[Any]],
33
+ s_eth: NDArray[np.floating[Any]],
34
+ s_macro: NDArray[np.floating[Any]],
35
+ s_lmk: NDArray[np.floating[Any]],
36
+ ) -> NDArray[np.floating[Any]]:
37
+ return cast(
38
+ NDArray[np.floating[Any]],
39
+ np.mean(np.stack([s_age, s_gender, s_eth, s_macro, s_lmk], axis=0), axis=0),
40
+ )
41
+
42
+
43
+ def batch_U2(
44
+ s_gaze: NDArray[np.floating[Any]], s_me: NDArray[np.floating[Any]] | None = None
45
+ ) -> NDArray[np.floating[Any]]:
46
+ if s_me is not None:
47
+ return cast(NDArray[np.floating[Any]], 0.5 * (s_gaze + s_me))
48
+ return cast(NDArray[np.floating[Any]], np.copy(s_gaze))
49
+
50
+
51
+ def batch_U3(
52
+ bvp_per_est: list[NDArray[np.floating[Any]]],
53
+ hr_per_est: list[NDArray[np.floating[Any]]],
54
+ ) -> NDArray[np.floating[Any]]:
55
+ combined = [0.5 * (b + h) for b, h in zip(bvp_per_est, hr_per_est, strict=False)]
56
+ return cast(
57
+ NDArray[np.floating[Any]], np.mean(np.stack(combined, axis=0), axis=0)
58
+ )
59
+
60
+
61
+ # ----- 5.2 Per-method aggregation --------------------------------------------
62
+
63
+ _DIMENSION_MAP = {
64
+ "age": "L1", "gender": "L1", "ethnicity": "L1", "macro_exp": "L1", "landmark": "L1",
65
+ "gaze": "L2", "micro_exp": "L2",
66
+ "bvp": "L3", "hr": "L3",
67
+ "P": "Privacy", "Q": "Quality",
68
+ "U1": "L1", "U2": "L2", "U3": "L3",
69
+ }
70
+
71
+
72
+ def aggregate_method_scores(
73
+ per_sample: dict[str, NDArray[np.floating[Any]]], method_name: str
74
+ ) -> pd.DataFrame:
75
+ """Aggregate per-sample arrays into a method-level dataframe."""
76
+ rows = [
77
+ {
78
+ "method": method_name,
79
+ "dimension": _DIMENSION_MAP.get(name, "Other"),
80
+ "sub_score": name,
81
+ "value": float(np.mean(arr)),
82
+ "n_samples": len(arr),
83
+ "std": float(np.std(arr)),
84
+ }
85
+ for name, arr in per_sample.items()
86
+ ]
87
+ return pd.DataFrame(rows)