Skip to content

Commit a0ecf19

Browse files
committed
[A] Add one test and update codes
1 parent b0fb288 commit a0ecf19

16 files changed

Lines changed: 171 additions & 40 deletions

File tree

.github/workflows/cpu-ci.yml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
python-version: ["3.10", "3.12"]
16-
os: ["ubuntu-latest", "ubuntu-24.04-arm", "macos-13", "macos-latest"] # , "macos-15" # replace with "macos-latest" if needed
16+
os: ["ubuntu-22.04","ubuntu-24.04", "macos-13", "macos-latest"] # "ubuntu-24.04-arm", # replace with "macos-latest" if needed
1717

1818
runs-on: ${{ matrix.os }}
1919

2020
steps:
2121
- name: Checkout Repository
2222
uses: actions/checkout@v4
23+
with:
24+
lfs: true
2325

2426
- name: Set up Python ${{ matrix.python-version }}
2527
uses: actions/setup-python@v5
@@ -29,6 +31,7 @@ jobs:
2931

3032
- name: Install Dependencies
3133
run: |
34+
sudo apt install -y libturbojpeg exiftool ffmpeg libheif-dev poppler-utils
3235
python -m pip install -U pip wheel "numpy>=2" "cython>=3.0.12" "setuptools>=69"
3336
python setup.py build_ext --inplace
3437
python -m pip install .
@@ -42,20 +45,20 @@ jobs:
4245
run: |
4346
mkdir -p tests/coverage
4447
python -m pip install pytest pytest-cov typeguard
45-
python -m pytest tests \
46-
--junitxml=tests/coverage/cov-junitxml.xml \
47-
--cov=pyface \
48-
| tee tests/coverage/cov.txt
48+
python -m pytest tests --junitxml=tests/coverage/cov-junitxml.xml --cov=pyface
4949
50-
- name: Pytest Coverage Comment
50+
- name: Surface failing tests
5151
if: always()
52-
id: coverageComment
53-
uses: MishaKav/pytest-coverage-comment@main
52+
uses: pmeier/pytest-results-action@main
5453
with:
55-
github-token: ${{ secrets.GITHUB_TOKEN }}
56-
pytest-coverage-path: tests/coverage/cov.txt
57-
junitxml-path: tests/coverage/cov-junitxml.xml
54+
path: tests/coverage/cov-junitxml.xml
55+
summary: true
56+
display-options: fEX
57+
fail-on-empty: true
58+
title: Test results
5859

5960
- name: Clean artifacts
6061
if: always()
61-
run: rm -rf dist wheelhouse build *.egg-info
62+
run: |
63+
rm -rf dist wheelhouse build *.egg-info
64+
rm -rf ${{ github.workspace }}

.github/workflows/cuda-ci.yml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
steps:
2020
- name: Checkout Repository
2121
uses: actions/checkout@v4
22+
with:
23+
lfs: true
2224

2325
- name: Set up Python ${{ matrix.python-version }}
2426
uses: actions/setup-python@v5
@@ -41,20 +43,20 @@ jobs:
4143
run: |
4244
mkdir -p tests/coverage
4345
python -m pip install pytest pytest-cov typeguard
44-
python -m pytest tests \
45-
--junitxml=tests/coverage/cov-junitxml.xml \
46-
--cov=pyface \
47-
| tee tests/coverage/cov.txt
46+
python -m pytest tests --junitxml=tests/coverage/cov-junitxml.xml --cov=pyface
4847
49-
- name: Pytest Coverage Comment
48+
- name: Surface failing tests
5049
if: always()
51-
id: coverageComment
52-
uses: MishaKav/pytest-coverage-comment@main
50+
uses: pmeier/pytest-results-action@main
5351
with:
54-
github-token: ${{ secrets.GITHUB_TOKEN }}
55-
pytest-coverage-path: tests/coverage/cov.txt
56-
junitxml-path: tests/coverage/cov-junitxml.xml
52+
path: tests/coverage/cov-junitxml.xml
53+
summary: true
54+
display-options: fEX
55+
fail-on-empty: true
56+
title: Test results
5757

5858
- name: Clean artifacts
5959
if: always()
60-
run: rm -rf dist wheelhouse build *.egg-info
60+
run: |
61+
rm -rf dist wheelhouse build *.egg-info
62+
rm -rf ${{ github.workspace }}

pyface/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .components import *
22
from .face_service import *
33
from .object import *
4-
from .utils import download_models
4+
from .utils import *
55

66
__version__ = "0.1.2"

pyface/components/face_depth/tddfav2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class TDDFAV2:
198198
def __init__(
199199
self,
200200
model_path: Optional[Union[str, cb.Path]] = None,
201-
model_version: str = "tddfav2_mbv1_fp32",
201+
model_name: str = "tddfav2_mbv1_fp32",
202202
batch_size: int = 1,
203203
gpu_id: int = 0,
204204
backend: str = "cuda",
@@ -207,8 +207,8 @@ def __init__(
207207
):
208208
if model_path is None:
209209
model_path = download_model_and_return_model_fpath(
210-
repo_id=self.repo_ids[model_version],
211-
model_fname=f"{model_version}.onnx",
210+
repo_id=self.repo_ids[model_name],
211+
model_fname=f"{model_name}.onnx",
212212
)
213213
self.model_path = model_path
214214
self.batch_size = batch_size

pyface/components/face_detection/scrfd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class SCRFD:
100100
def __init__(
101101
self,
102102
model_path: str = None,
103-
model_version: str = "scrfd_10g_gnkps_fp32",
103+
model_name: str = "scrfd_10g_gnkps_fp32",
104104
batch_size: int = 1,
105105
inp_size: Optional[Tuple[int, int]] = (480, 640), # best settings for the model
106106
score_th: Optional[float] = None,
@@ -111,8 +111,8 @@ def __init__(
111111
):
112112
if model_path is None:
113113
model_path = download_model_and_return_model_fpath(
114-
repo_id=self.repo_ids[model_version],
115-
model_fname=f"{model_version}.onnx",
114+
repo_id=self.repo_ids[model_name],
115+
model_fname=f"{model_name}.onnx",
116116
)
117117
self.model_path = model_path
118118
self.engine = cb.ONNXEngine(

pyface/components/face_gender.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class GenderDetector:
4949
def __init__(
5050
self,
5151
model_path: str = None,
52-
model_version: str = "gender_detection_lcnet_050",
52+
model_name: str = "gender_detection_lcnet_050",
5353
batch_size: int = 1,
5454
gpu_id: int = 0,
5555
backend: str = "cuda",
@@ -58,8 +58,8 @@ def __init__(
5858
):
5959
if model_path is None:
6060
model_path = download_model_and_return_model_fpath(
61-
repo_id=self.repo_ids[model_version],
62-
model_fname=f"{model_version}.onnx",
61+
repo_id=self.repo_ids[model_name],
62+
model_fname=f"{model_name}.onnx",
6363
)
6464
self.model_path = model_path
6565
self.engine = cb.ONNXEngine(

pyface/components/face_landmark/coordinate_reg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CoordinateReg:
3636
def __init__(
3737
self,
3838
model_path: Optional[str] = None,
39-
model_version: str = "coordinate_reg_mbv1_fp32",
39+
model_name: str = "coordinate_reg_mbv1_fp32",
4040
gpu_id: int = 0,
4141
backend: str = "cuda",
4242
session_option: Dict[str, Any] = {},
@@ -46,8 +46,8 @@ def __init__(
4646
):
4747
if model_path is None:
4848
model_path = download_model_and_return_model_fpath(
49-
repo_id=self.repo_ids[model_version],
50-
model_fname=f"{model_version}.onnx",
49+
repo_id=self.repo_ids[model_name],
50+
model_fname=f"{model_name}.onnx",
5151
)
5252
self.model_path = model_path
5353
self.engine = cb.ONNXEngine(

pyface/components/face_recognition/arcface.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ArcFace:
1717
def __init__(
1818
self,
1919
model_path: Optional[str] = None,
20-
model_version: str = "wf42m_pfc03_vit-l_fp32",
20+
model_name: str = "wf42m_pfc03_vit-l_fp32",
2121
batch_size: int = 1,
2222
enable_flip: bool = False,
2323
gpu_id: int = 0,
@@ -27,8 +27,8 @@ def __init__(
2727
):
2828
if model_path is None:
2929
model_path = download_model_and_return_model_fpath(
30-
repo_id=self.repo_ids[model_version],
31-
model_fname=f"{model_version}.onnx",
30+
repo_id=self.repo_ids[model_name],
31+
model_fname=f"{model_name}.onnx",
3232
)
3333
self.model_path = model_path
3434
self.engine = cb.ONNXEngine(
@@ -43,7 +43,7 @@ def __init__(
4343
self.metadata["Mean"] = [127.5, 127.5, 127.5]
4444
self.metadata["Std"] = [128, 128, 128]
4545
self.metadata["ColorMode"] = "rgb"
46-
self.metadata["Version"] = self.versions[model_version]
46+
self.metadata["Version"] = self.versions[model_name]
4747
self.metadata.freeze()
4848
self.initialize()
4949

pyface/utils.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,40 @@
1+
import capybara as cb
2+
import onnxruntime as ort
3+
14
from .components.face_depth.tddfav2 import TDDFAV2
25
from .components.face_detection.scrfd import SCRFD
36
from .components.face_gender import GenderDetector
47
from .components.face_landmark.coordinate_reg import CoordinateReg
58
from .components.face_recognition.arcface import ArcFace
69

10+
__all__ = [
11+
"download_models",
12+
"get_ort_backend",
13+
]
14+
715

816
def download_models():
917
TDDFAV2.download_models()
1018
SCRFD.download_models()
1119
GenderDetector.download_models()
1220
CoordinateReg.download_models()
1321
ArcFace.download_models()
22+
23+
24+
def cuda_avaliable():
25+
providers = ort.get_available_providers()
26+
return "CUDAExecutionProvider" in providers
27+
28+
29+
def coreml_avaliable():
30+
providers = ort.get_available_providers()
31+
return "CoreMLExecutionProvider" in providers
32+
33+
34+
def get_ort_backend():
35+
if cuda_avaliable():
36+
return cb.Backend.cuda
37+
elif coreml_avaliable():
38+
return cb.Backend.coreml
39+
else:
40+
return cb.Backend.cpu

tests/resources/EmmaWatson1.png

Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)