qualia_vision/
vggface2_taxonomy.rs1use crate::semantic::q_hash;
7
8pub const VGGFACE2_IDENTITY_COUNT: usize = 9131;
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum VGGFace2Pose {
14 Frontal = 0,
15 ThreeQuarter = 1,
16 Profile = 2,
17}
18
19impl VGGFace2Pose {
20 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
30pub fn format_vggface2_subject_id(identity_idx: u32) -> String {
32 format!("n{:06}", identity_idx.saturating_add(1))
33}
34
35pub fn q_hash_vggface2_subject(subject_id: &str) -> u64 {
37 q_hash(subject_id)
38}
39
40pub fn lookup_vggface2_subject_hash(identity_idx: u32) -> u64 {
42 q_hash(&format_vggface2_subject_id(identity_idx))
43}
44
45pub 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}