Unverified 提交 f3085acc authored 作者: Glenn Jocher's avatar Glenn Jocher 提交者: GitHub

Enable ONNX `--half` FP16 inference (#6268)

* Enable ONNX ``--half` FP16 inference * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ciCo-authored-by: 's avatarpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
上级 b3eaf500
...@@ -94,7 +94,7 @@ def run(weights=ROOT / 'yolov5s.pt', # model.pt path(s) ...@@ -94,7 +94,7 @@ def run(weights=ROOT / 'yolov5s.pt', # model.pt path(s)
imgsz = check_img_size(imgsz, s=stride) # check image size imgsz = check_img_size(imgsz, s=stride) # check image size
# Half # Half
half &= (pt or jit or engine) and device.type != 'cpu' # half precision only supported by PyTorch on CUDA half &= (pt or jit or onnx or engine) and device.type != 'cpu' # FP16 supported on limited backends with CUDA
if pt or jit: if pt or jit:
model.model.half() if half else model.model.float() model.model.half() if half else model.model.float()
......
...@@ -1099,4 +1099,4 @@ ...@@ -1099,4 +1099,4 @@
"outputs": [] "outputs": []
} }
] ]
} }
\ No newline at end of file
...@@ -137,9 +137,9 @@ def run(data, ...@@ -137,9 +137,9 @@ def run(data,
# Load model # Load model
model = DetectMultiBackend(weights, device=device, dnn=dnn, data=data) model = DetectMultiBackend(weights, device=device, dnn=dnn, data=data)
stride, pt, jit, engine = model.stride, model.pt, model.jit, model.engine stride, pt, jit, onnx, engine = model.stride, model.pt, model.jit, model.onnx, model.engine
imgsz = check_img_size(imgsz, s=stride) # check image size imgsz = check_img_size(imgsz, s=stride) # check image size
half &= (pt or jit or engine) and device.type != 'cpu' # half precision only supported by PyTorch on CUDA half &= (pt or jit or onnx or engine) and device.type != 'cpu' # FP16 supported on limited backends with CUDA
if pt or jit: if pt or jit:
model.model.half() if half else model.model.float() model.model.half() if half else model.model.float()
elif engine: elif engine:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论