File size: 659 Bytes
ea93121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""TensorRT conversion utility wrapper."""

from __future__ import annotations

import shutil
import subprocess
from pathlib import Path


def convert(onnx: Path, engine: Path) -> None:
    """Convert ONNX to TensorRT engine when trtexec exists; fallback to copy."""
    engine.parent.mkdir(parents=True, exist_ok=True)
    trtexec = shutil.which("trtexec")
    if trtexec:
        subprocess.check_call([trtexec, f"--onnx={onnx}", f"--saveEngine={engine}", "--fp16"])
        return
    shutil.copyfile(onnx, engine)


if __name__ == "__main__":
    convert(Path("artifacts/models/iresnet100_arcface.onnx"), Path("artifacts/models/iresnet100_arcface.plan"))