Add quartz inspection core ignore rules
This commit is contained in:
31
scripts/build_engine.sh
Executable file
31
scripts/build_engine.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
CORE_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||
ONNX_PATH="${1:-${CORE_DIR}/models/yolo26_tile_seg_v3.onnx}"
|
||||
ENGINE_PATH="${2:-${CORE_DIR}/models/yolo26_tile_seg_v3_fp16.trt}"
|
||||
|
||||
TRTEXEC="${TRTEXEC:-}"
|
||||
if [[ -z "${TRTEXEC}" ]]; then
|
||||
if command -v trtexec >/dev/null 2>&1; then
|
||||
TRTEXEC="$(command -v trtexec)"
|
||||
elif [[ -n "${TENSORRT_DIR:-}" && -x "${TENSORRT_DIR}/bin/trtexec" ]]; then
|
||||
TRTEXEC="${TENSORRT_DIR}/bin/trtexec"
|
||||
elif [[ -x "/usr/src/tensorrt/bin/trtexec" ]]; then
|
||||
TRTEXEC="/usr/src/tensorrt/bin/trtexec"
|
||||
else
|
||||
echo "trtexec was not found. Install TensorRT 10+ or set TRTEXEC=/path/to/trtexec." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p "$(dirname "${ENGINE_PATH}")"
|
||||
"${TRTEXEC}" \
|
||||
--onnx="${ONNX_PATH}" \
|
||||
--saveEngine="${ENGINE_PATH}" \
|
||||
--fp16 \
|
||||
--useCudaGraph \
|
||||
--noDataTransfers
|
||||
|
||||
echo "TensorRT engine written to: ${ENGINE_PATH}"
|
||||
59
scripts/export_yolo26_seg_onnx.py
Executable file
59
scripts/export_yolo26_seg_onnx.py
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Export the trained YOLO26 segmentation model to ONNX for TensorRT."""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from ultralytics import YOLO
|
||||
|
||||
|
||||
CORE_DIR = Path(__file__).resolve().parents[1]
|
||||
MODEL = Path(os.environ.get(
|
||||
"YOLO26_MODEL",
|
||||
CORE_DIR / "runs/segment/yolo26_tile_seg_v3/weights/best.pt",
|
||||
))
|
||||
OUT_DIR = CORE_DIR / "models"
|
||||
EXISTING_ONNX = CORE_DIR / "runs/segment/yolo26_tile_seg_v3/weights/best.onnx"
|
||||
|
||||
|
||||
def require_yolo26_support() -> None:
|
||||
from ultralytics.nn.modules import head
|
||||
|
||||
if not hasattr(head, "Segment26"):
|
||||
raise RuntimeError(
|
||||
"This checkpoint uses the YOLO26 Segment26 head, but the active "
|
||||
"ultralytics install does not provide it. Run this script with the "
|
||||
"same YOLO26-capable Python environment used for training."
|
||||
)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
OUT_DIR.mkdir(parents=True, exist_ok=True)
|
||||
target = OUT_DIR / "yolo26_tile_seg_v3.onnx"
|
||||
|
||||
if EXISTING_ONNX.exists():
|
||||
if EXISTING_ONNX.resolve() != target.resolve():
|
||||
target.write_bytes(EXISTING_ONNX.read_bytes())
|
||||
print(f"ONNX copied to: {target}")
|
||||
return
|
||||
|
||||
if not MODEL.exists():
|
||||
raise FileNotFoundError(f"Model checkpoint not found: {MODEL}")
|
||||
require_yolo26_support()
|
||||
model = YOLO(str(MODEL))
|
||||
exported = model.export(
|
||||
format="onnx",
|
||||
imgsz=864,
|
||||
opset=17,
|
||||
simplify=True,
|
||||
dynamic=False,
|
||||
half=False,
|
||||
)
|
||||
exported_path = Path(exported)
|
||||
if exported_path.resolve() != target.resolve():
|
||||
target.write_bytes(exported_path.read_bytes())
|
||||
print(f"ONNX exported to: {target}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user