Unverified 提交 938efe5d authored 作者: Andrei Ionut Damian's avatar Andrei Ionut Damian 提交者: GitHub

update `detect.py` in order to support torch script (#5109)

* update detect.py in order to support torch script This change assumes the torchscrip file was previously saved with `export.py` * update `detect.py` for torchscript support Simple update for torchscript support. Assumes the torchscript file has been generated with `export.py` * Cleanup Co-authored-by: 's avatarGlenn Jocher <glenn.jocher@ultralytics.com>
上级 0bf24cf6
...@@ -79,7 +79,7 @@ def run(weights=ROOT / 'yolov5s.pt', # model.pt path(s) ...@@ -79,7 +79,7 @@ def run(weights=ROOT / 'yolov5s.pt', # model.pt path(s)
pt, onnx, tflite, pb, saved_model = (suffix == x for x in suffixes) # backend booleans pt, onnx, tflite, pb, saved_model = (suffix == x for x in suffixes) # backend booleans
stride, names = 64, [f'class{i}' for i in range(1000)] # assign defaults stride, names = 64, [f'class{i}' for i in range(1000)] # assign defaults
if pt: if pt:
model = attempt_load(weights, map_location=device) # load FP32 model model = torch.jit.load(w) if 'torchscript' in w else attempt_load(weights, map_location=device)
stride = int(model.stride.max()) # model stride stride = int(model.stride.max()) # model stride
names = model.module.names if hasattr(model, 'module') else model.names # get class names names = model.module.names if hasattr(model, 'module') else model.names # get class names
if half: if half:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论