Allow --weights URL (#5991)
This commit is contained in:
1 parent
b7d18f3636
commit
da9a1b719b
2 files changed
+8
-5
No files matched your search
+2
-2
@@ -296,7 +296,7 @@ class DetectMultiBackend(nn.Module):
|
|||||||
check_suffix(w, suffixes) # check weights have acceptable suffix
|
check_suffix(w, suffixes) # check weights have acceptable suffix
|
||||||
pt, jit, onnx, engine, tflite, pb, saved_model, coreml = (suffix == x for x in suffixes) # backend booleans
|
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
|
stride, names = 64, [f'class{i}' for i in range(1000)] # assign defaults
|
||||||
attempt_download(w) # download if not local
|
w = attempt_download(w) # download if not local
|
||||||
|
|
||||||
if jit: # TorchScript
|
if jit: # TorchScript
|
||||||
LOGGER.info(f'Loading {w} for TorchScript inference...')
|
LOGGER.info(f'Loading {w} for TorchScript inference...')
|
||||||
@@ -306,7 +306,7 @@ class DetectMultiBackend(nn.Module):
|
|||||||
d = json.loads(extra_files['config.txt']) # extra_files dict
|
d = json.loads(extra_files['config.txt']) # extra_files dict
|
||||||
stride, names = int(d['stride']), d['names']
|
stride, names = int(d['stride']), d['names']
|
||||||
elif pt: # PyTorch
|
elif pt: # PyTorch
|
||||||
model = attempt_load(weights, map_location=device)
|
model = attempt_load(weights if isinstance(weights, list) else w, 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
|
||||||
self.model = model # explicitly assign for to(), cpu(), cuda(), half()
|
self.model = model # explicitly assign for to(), cpu(), cuda(), half()
|
||||||
|
|||||||
+6
-3
@@ -49,9 +49,12 @@ def attempt_download(file, repo='ultralytics/yolov5'): # from utils.downloads i
|
|||||||
name = Path(urllib.parse.unquote(str(file))).name # decode '%2F' to '/' etc.
|
name = Path(urllib.parse.unquote(str(file))).name # decode '%2F' to '/' etc.
|
||||||
if str(file).startswith(('http:/', 'https:/')): # download
|
if str(file).startswith(('http:/', 'https:/')): # download
|
||||||
url = str(file).replace(':/', '://') # Pathlib turns :// -> :/
|
url = str(file).replace(':/', '://') # Pathlib turns :// -> :/
|
||||||
name = name.split('?')[0] # parse authentication https://url.com/file.txt?auth...
|
file = name.split('?')[0] # parse authentication https://url.com/file.txt?auth...
|
||||||
safe_download(file=name, url=url, min_bytes=1E5)
|
if Path(file).is_file():
|
||||||
return name
|
print(f'Found {url} locally at {file}') # file already exists
|
||||||
|
else:
|
||||||
|
safe_download(file=file, url=url, min_bytes=1E5)
|
||||||
|
return file
|
||||||
|
|
||||||
# GitHub assets
|
# GitHub assets
|
||||||
file.parent.mkdir(parents=True, exist_ok=True) # make parent dir (if required)
|
file.parent.mkdir(parents=True, exist_ok=True) # make parent dir (if required)
|
||||||
|
|||||||
Reference in new issue
Block a user