Skip to main content

qualia_vision/
vggface2_taxonomy.rs

1//! Oxford VGGFace2 Facial Recognition Taxonomy & Epistemic Identity Resolver.
2//!
3//! Provides zero-allocation FNV-1a IRI hashing, subject index mapping (`n000001`..`n009131`),
4//! pose classification, and privacy-preserving identity hash resolution for VGGFace2 (9,131 identities).
5
6use crate::semantic::q_hash;
7
8/// Total number of unique subject identities in Oxford VGGFace2 dataset.
9pub const VGGFACE2_IDENTITY_COUNT: usize = 9131;
10
11/// Facial pose orientation classification.
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum VGGFace2Pose {
14    Frontal = 0,
15    ThreeQuarter = 1,
16    Profile = 2,
17}
18
19impl VGGFace2Pose {
20    /// `&str` form.
21    pub fn as_str(self) -> &'static str {
22        match self {
23            Self::Frontal => "frontal",
24            Self::ThreeQuarter => "three_quarter",
25            Self::Profile => "profile",
26        }
27    }
28}
29
30/// Format an identity index (0..9130) into its canonical VGGFace2 subject ID string (e.g. `n000001`).
31pub fn format_vggface2_subject_id(identity_idx: u32) -> String {
32    format!("n{:06}", identity_idx.saturating_add(1))
33}
34
35/// Compute the deterministic 64-bit FNV-1a subject identity hash for a VGGFace2 subject ID.
36pub fn q_hash_vggface2_subject(subject_id: &str) -> u64 {
37    q_hash(subject_id)
38}
39
40/// Compute the deterministic 64-bit FNV-1a subject identity hash directly from numeric index (0..9130).
41pub fn lookup_vggface2_subject_hash(identity_idx: u32) -> u64 {
42    q_hash(&format_vggface2_subject_id(identity_idx))
43}
44
45/// Total count of registered VGGFace2 subject identities.
46pub fn vggface2_identity_count() -> usize {
47    VGGFACE2_IDENTITY_COUNT
48}
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_vggface2_taxonomy_formatting_and_hashing() {
56        assert_eq!(format_vggface2_subject_id(0), "n000001");
57        assert_eq!(format_vggface2_subject_id(9130), "n009131");
58
59        let h1 = q_hash_vggface2_subject("n000001");
60        let h2 = lookup_vggface2_subject_hash(0);
61        assert_eq!(h1, h2);
62        assert_ne!(h1, 0);
63
64        assert_eq!(vggface2_identity_count(), 9131);
65        assert_eq!(VGGFace2Pose::Frontal.as_str(), "frontal");
66    }
67}