ljchang commited on
Commit
f40915c
1 Parent(s): 0417726

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +41 -0
README.md CHANGED
@@ -45,5 +45,46 @@ If you use the Retinaface model in your research or application, please cite the
45
  }
46
  ```
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  ## Acknowledgements
49
  We thank the contributors and the open-source community for their valuable support in developing this model. Special thanks to the authors of the original Retinaface paper, the WIDER FACE dataset, and biubug6 for sharing weights and code.
 
45
  }
46
  ```
47
 
48
+ ## Example Useage
49
+
50
+ ```python
51
+ import os
52
+ import torch
53
+ import json
54
+ from PIL import Image
55
+ from huggingface_hub import hf_hub_download
56
+ from feat.face_detectors.Retinaface.Retinaface_model import RetinaFace, postprocess_retinaface
57
+ from feat.utils.io import get_resource_path, get_test_data_path
58
+ from feat.utils.image_operations import convert_image_to_tensor, convert_color_vector_to_tensor
59
+
60
+ device = 'cpu'
61
+
62
+ # Download Model Weights and Config File
63
+ face_config_file = hf_hub_download(
64
+ repo_id="py-feat/retinaface",
65
+ filename="config.json",
66
+ cache_dir=get_resource_path(),
67
+ )
68
+ with open(face_config_file, "r") as f:
69
+ face_config = json.load(f)
70
+
71
+ face_model_file = hf_hub_download(repo_id='py-feat/retinaface',
72
+ filename="mobilenet0.25_Final.pth",
73
+ cache_dir=get_resource_path())
74
+ face_checkpoint = torch.load(face_model_file, map_location=device, weights_only=True)
75
+ face_detector = RetinaFace(cfg=face_config, phase="test")
76
+ face_detector.load_state_dict(face_checkpoint)
77
+ face_detector.eval()
78
+ face_detector.to(device)
79
+
80
+ # Run Inference
81
+ frame = Image.open(os.path.join(get_test_data_path(), "multi_face.jpg"))
82
+ single_frame = torch.sub(frame, convert_color_vector_to_tensor(np.array([123, 117, 104])))
83
+ predicted_locations, predicted_scores, predicted_landmarks = face_detector.forward(single_frame.to(device))
84
+ face_output = postprocess_retinaface(predicted_locations, predicted_scores, predicted_landmarks, face_config, single_frame, device=device)
85
+
86
+
87
+ ```
88
+
89
  ## Acknowledgements
90
  We thank the contributors and the open-source community for their valuable support in developing this model. Special thanks to the authors of the original Retinaface paper, the WIDER FACE dataset, and biubug6 for sharing weights and code.