Loading .github/workflows/export.yml +3 −1 Original line number Diff line number Diff line Loading @@ -17,7 +17,9 @@ jobs: - '3.8' model-name: # - 'lpips' - 'monochrome' # - 'monochrome' - 'person_detect' - 'face_detect' steps: - name: Checkout code Loading zoo/detection/onnx.py 0 → 100644 +15 −0 Original line number Diff line number Diff line import os.path from hbutils.system import copy from hbutils.testing import isolated_directory from ultralytics import YOLO def export_yolo_to_onnx(yolo: YOLO, onnx_filename, opset_version: int = 14, no_optimize: bool = False): _current_path = os.path.abspath(os.curdir) with isolated_directory(): copy( yolo.export(format='onnx', dynamic=True, simplify=not no_optimize, opset=opset_version), os.path.join(_current_path, onnx_filename) ) zoo/face_detect.py 0 → 100644 +43 −0 Original line number Diff line number Diff line import os.path from functools import partial from typing import List import click from huggingface_hub import hf_hub_download from tqdm.auto import tqdm from ultralytics import YOLO from .detection.onnx import export_yolo_to_onnx from .utils import GLOBAL_CONTEXT_SETTINGS from .utils import print_version as _origin_print_version print_version = partial(_origin_print_version, 'zoo.face_detect') @click.group(context_settings={**GLOBAL_CONTEXT_SETTINGS}) @click.option('-v', '--version', is_flag=True, callback=print_version, expose_value=False, is_eager=True, help="Show version information.") def cli(): pass # pragma: no cover _KNOWN_CKPTS: List[str] = [ 'face_detect_best_s.pt', ] @cli.command('export', help='Export all models as onnx.', context_settings={**GLOBAL_CONTEXT_SETTINGS}) @click.option('--output_dir', '-O', 'output_dir', type=click.Path(file_okay=False), required=True, help='Output directory of all models.', show_default=True) def export(output_dir: str): for ckpt in tqdm(_KNOWN_CKPTS): yolo = YOLO(hf_hub_download('deepghs/imgutils-models', f'face_detect/{ckpt}')) filebody, _ = os.path.splitext(ckpt) output_file = os.path.join(output_dir, f'{filebody}.onnx') export_yolo_to_onnx(yolo, output_file) if __name__ == '__main__': cli() zoo/person_detect.py 0 → 100644 +43 −0 Original line number Diff line number Diff line import os.path from functools import partial from typing import List import click from huggingface_hub import hf_hub_download from tqdm.auto import tqdm from ultralytics import YOLO from .detection.onnx import export_yolo_to_onnx from .utils import GLOBAL_CONTEXT_SETTINGS from .utils import print_version as _origin_print_version print_version = partial(_origin_print_version, 'zoo.person_detect') @click.group(context_settings={**GLOBAL_CONTEXT_SETTINGS}) @click.option('-v', '--version', is_flag=True, callback=print_version, expose_value=False, is_eager=True, help="Show version information.") def cli(): pass # pragma: no cover _KNOWN_CKPTS: List[str] = [ 'person_detect_best_s.pt', ] @cli.command('export', help='Export all models as onnx.', context_settings={**GLOBAL_CONTEXT_SETTINGS}) @click.option('--output_dir', '-O', 'output_dir', type=click.Path(file_okay=False), required=True, help='Output directory of all models.', show_default=True) def export(output_dir: str): for ckpt in tqdm(_KNOWN_CKPTS): yolo = YOLO(hf_hub_download('deepghs/imgutils-models', f'person_detect/{ckpt}')) filebody, _ = os.path.splitext(ckpt) output_file = os.path.join(output_dir, f'{filebody}.onnx') export_yolo_to_onnx(yolo, output_file) if __name__ == '__main__': cli() Loading
.github/workflows/export.yml +3 −1 Original line number Diff line number Diff line Loading @@ -17,7 +17,9 @@ jobs: - '3.8' model-name: # - 'lpips' - 'monochrome' # - 'monochrome' - 'person_detect' - 'face_detect' steps: - name: Checkout code Loading
zoo/detection/onnx.py 0 → 100644 +15 −0 Original line number Diff line number Diff line import os.path from hbutils.system import copy from hbutils.testing import isolated_directory from ultralytics import YOLO def export_yolo_to_onnx(yolo: YOLO, onnx_filename, opset_version: int = 14, no_optimize: bool = False): _current_path = os.path.abspath(os.curdir) with isolated_directory(): copy( yolo.export(format='onnx', dynamic=True, simplify=not no_optimize, opset=opset_version), os.path.join(_current_path, onnx_filename) )
zoo/face_detect.py 0 → 100644 +43 −0 Original line number Diff line number Diff line import os.path from functools import partial from typing import List import click from huggingface_hub import hf_hub_download from tqdm.auto import tqdm from ultralytics import YOLO from .detection.onnx import export_yolo_to_onnx from .utils import GLOBAL_CONTEXT_SETTINGS from .utils import print_version as _origin_print_version print_version = partial(_origin_print_version, 'zoo.face_detect') @click.group(context_settings={**GLOBAL_CONTEXT_SETTINGS}) @click.option('-v', '--version', is_flag=True, callback=print_version, expose_value=False, is_eager=True, help="Show version information.") def cli(): pass # pragma: no cover _KNOWN_CKPTS: List[str] = [ 'face_detect_best_s.pt', ] @cli.command('export', help='Export all models as onnx.', context_settings={**GLOBAL_CONTEXT_SETTINGS}) @click.option('--output_dir', '-O', 'output_dir', type=click.Path(file_okay=False), required=True, help='Output directory of all models.', show_default=True) def export(output_dir: str): for ckpt in tqdm(_KNOWN_CKPTS): yolo = YOLO(hf_hub_download('deepghs/imgutils-models', f'face_detect/{ckpt}')) filebody, _ = os.path.splitext(ckpt) output_file = os.path.join(output_dir, f'{filebody}.onnx') export_yolo_to_onnx(yolo, output_file) if __name__ == '__main__': cli()
zoo/person_detect.py 0 → 100644 +43 −0 Original line number Diff line number Diff line import os.path from functools import partial from typing import List import click from huggingface_hub import hf_hub_download from tqdm.auto import tqdm from ultralytics import YOLO from .detection.onnx import export_yolo_to_onnx from .utils import GLOBAL_CONTEXT_SETTINGS from .utils import print_version as _origin_print_version print_version = partial(_origin_print_version, 'zoo.person_detect') @click.group(context_settings={**GLOBAL_CONTEXT_SETTINGS}) @click.option('-v', '--version', is_flag=True, callback=print_version, expose_value=False, is_eager=True, help="Show version information.") def cli(): pass # pragma: no cover _KNOWN_CKPTS: List[str] = [ 'person_detect_best_s.pt', ] @cli.command('export', help='Export all models as onnx.', context_settings={**GLOBAL_CONTEXT_SETTINGS}) @click.option('--output_dir', '-O', 'output_dir', type=click.Path(file_okay=False), required=True, help='Output directory of all models.', show_default=True) def export(output_dir: str): for ckpt in tqdm(_KNOWN_CKPTS): yolo = YOLO(hf_hub_download('deepghs/imgutils-models', f'person_detect/{ckpt}')) filebody, _ = os.path.splitext(ckpt) output_file = os.path.join(output_dir, f'{filebody}.onnx') export_yolo_to_onnx(yolo, output_file) if __name__ == '__main__': cli()