Update TorchScript suffix to *.torchscript (#5856)
This commit is contained in:
1 parent
30db14fea8
commit
00e308f7be
5 files changed
+20
-20
No files matched your search
+6
-6
@@ -279,7 +279,7 @@ class DetectMultiBackend(nn.Module):
|
||||
def __init__(self, weights='yolov5s.pt', device=None, dnn=True):
|
||||
# Usage:
|
||||
# PyTorch: weights = *.pt
|
||||
# TorchScript: *.torchscript.pt
|
||||
# TorchScript: *.torchscript
|
||||
# CoreML: *.mlmodel
|
||||
# TensorFlow: *_saved_model
|
||||
# TensorFlow: *.pb
|
||||
@@ -289,10 +289,10 @@ class DetectMultiBackend(nn.Module):
|
||||
# TensorRT: *.engine
|
||||
super().__init__()
|
||||
w = str(weights[0] if isinstance(weights, list) else weights)
|
||||
suffix, suffixes = Path(w).suffix.lower(), ['.pt', '.onnx', '.engine', '.tflite', '.pb', '', '.mlmodel']
|
||||
suffix = Path(w).suffix.lower()
|
||||
suffixes = ['.pt', '.torchscript', '.onnx', '.engine', '.tflite', '.pb', '', '.mlmodel']
|
||||
check_suffix(w, suffixes) # check weights have acceptable suffix
|
||||
pt, onnx, engine, tflite, pb, saved_model, coreml = (suffix == x for x in suffixes) # backend booleans
|
||||
jit = pt and 'torchscript' in w.lower()
|
||||
pt, jit, onnx, engine, tflite, pb, saved_model, coreml = (suffix == x for x in suffixes) # backend booleans
|
||||
stride, names = 64, [f'class{i}' for i in range(1000)] # assign defaults
|
||||
|
||||
if jit: # TorchScript
|
||||
@@ -304,10 +304,10 @@ class DetectMultiBackend(nn.Module):
|
||||
stride, names = int(d['stride']), d['names']
|
||||
elif pt: # PyTorch
|
||||
from models.experimental import attempt_load # scoped to avoid circular import
|
||||
model = torch.jit.load(w) if 'torchscript' in w else attempt_load(weights, map_location=device)
|
||||
model = attempt_load(weights, map_location=device)
|
||||
stride = int(model.stride.max()) # model stride
|
||||
names = model.module.names if hasattr(model, 'module') else model.names # get class names
|
||||
elif coreml: # CoreML *.mlmodel
|
||||
elif coreml: # CoreML
|
||||
import coremltools as ct
|
||||
model = ct.models.MLModel(w)
|
||||
elif dnn: # ONNX OpenCV DNN
|
||||
|
||||
Reference in new issue
Block a user