11import sys
22import numpy as np
3+ import pytest
34from pathlib import Path
45from PIL import Image
56
1314result_dir .mkdir (parents = True , exist_ok = True )
1415ref_dir = root_dir / "tests" / "reference"
1516
17+ @pytest .fixture
18+ def device (pytestconfig ):
19+ if pytestconfig .getoption ("ci" ):
20+ return Device .init (Backend .cpu )
21+ return Device .init ()
22+
1623
1724def compare_images (name : str , result : Image .Image , tolerance : float = 0.015 ):
1825 name = f"{ name } -gpu.png"
@@ -32,9 +39,8 @@ def compare_images(name: str, result: Image.Image, tolerance: float = 0.015):
3239 raise AssertionError (f"Images differ: RMSE={ rmse } exceeds tolerance={ tolerance } " )
3340
3441
35- def test_sam ():
36- dev = Device .init (Backend .gpu )
37- model = Model .load (model_dir / "MobileSAM-F16.gguf" , dev )
42+ def test_sam (device : Device ):
43+ model = Model .load (model_dir / "MobileSAM-F16.gguf" , device )
3844 assert model .arch is Arch .sam
3945
4046 img = Image .open (str (image_dir / "cat-and-hat.jpg" ))
@@ -43,27 +49,24 @@ def test_sam():
4349 compare_images ("mobile_sam-box" , result_box )
4450 compare_images ("mobile_sam-point" , result_point )
4551
46- def test_birefnet ():
47- dev = Device .init (Backend .gpu )
48- model = Model .load (model_dir / "BiRefNet-lite-F16.gguf" , dev )
52+ def test_birefnet (device : Device ):
53+ model = Model .load (model_dir / "BiRefNet-lite-F16.gguf" , device )
4954 assert model .arch is Arch .birefnet
5055
5156 img = Image .open (str (image_dir / "wardrobe.jpg" ))
5257 result = model .compute (img )
5358 compare_images ("birefnet" , result )
5459
55- def test_depth_anything ():
56- dev = Device .init (Backend .gpu )
57- model = Model .load (model_dir / "Depth-Anything-V2-Small-F16.gguf" , dev )
60+ def test_depth_anything (device : Device ):
61+ model = Model .load (model_dir / "Depth-Anything-V2-Small-F16.gguf" , device )
5862 assert model .arch is Arch .depth_anything
5963
6064 img = Image .open (str (image_dir / "wardrobe.jpg" ))
6165 result = model .compute (img )
6266 compare_images ("depth-anything" , result )
6367
64- def test_migan ():
65- dev = Device .init (Backend .gpu )
66- model = Model .load (model_dir / "MIGAN-512-places2-F16.gguf" , dev )
68+ def test_migan (device : Device ):
69+ model = Model .load (model_dir / "MIGAN-512-places2-F16.gguf" , device )
6770 assert model .arch is Arch .migan
6871
6972 img = Image .open (str (image_dir / "bench-image.jpg" )).convert ("RGBA" )
@@ -72,9 +75,8 @@ def test_migan():
7275 result = Image .alpha_composite (img , result )
7376 compare_images ("migan" , result )
7477
75- def test_esrgan ():
76- dev = Device .init (Backend .gpu )
77- model = Model .load (str (model_dir / "RealESRGAN-x4plus_anime-6B-F16.gguf" ), dev )
78+ def test_esrgan (device : Device ):
79+ model = Model .load (str (model_dir / "RealESRGAN-x4plus_anime-6B-F16.gguf" ), device )
7880 assert model .arch is Arch .esrgan
7981
8082 img = Image .open (str (image_dir / "vase-and-bowl.jpg" ))
0 commit comments