Fix detect.py URL inference (#5525)
* Fix detect.py URL inference Allows detect.py to run inference on remote URL sources, i.e.: ```python !python detect.py --weights yolov5s.pt --source https://ultralytics.com/assets/zidane.jpg # image URL !python detect.py --weights yolov5s.pt --source https://ultralytics.com/assets/decelera_landscape.mov # video URL ``` * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
853505339a
commit
5f603a9dba
15
detect.py
15
detect.py
|
|
@ -24,10 +24,10 @@ if str(ROOT) not in sys.path:
|
||||||
ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative
|
ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative
|
||||||
|
|
||||||
from models.experimental import attempt_load
|
from models.experimental import attempt_load
|
||||||
from utils.datasets import LoadImages, LoadStreams
|
from utils.datasets import IMG_FORMATS, VID_FORMATS, LoadImages, LoadStreams
|
||||||
from utils.general import (LOGGER, apply_classifier, check_img_size, check_imshow, check_requirements, check_suffix,
|
from utils.general import (LOGGER, apply_classifier, check_file, check_img_size, check_imshow, check_requirements,
|
||||||
colorstr, increment_path, non_max_suppression, print_args, save_one_box, scale_coords,
|
check_suffix, colorstr, increment_path, non_max_suppression, print_args, save_one_box,
|
||||||
strip_optimizer, xyxy2xywh)
|
scale_coords, strip_optimizer, xyxy2xywh)
|
||||||
from utils.plots import Annotator, colors
|
from utils.plots import Annotator, colors
|
||||||
from utils.torch_utils import load_classifier, select_device, time_sync
|
from utils.torch_utils import load_classifier, select_device, time_sync
|
||||||
|
|
||||||
|
|
@ -61,8 +61,11 @@ def run(weights=ROOT / 'yolov5s.pt', # model.pt path(s)
|
||||||
):
|
):
|
||||||
source = str(source)
|
source = str(source)
|
||||||
save_img = not nosave and not source.endswith('.txt') # save inference images
|
save_img = not nosave and not source.endswith('.txt') # save inference images
|
||||||
webcam = source.isnumeric() or source.endswith('.txt') or source.lower().startswith(
|
is_file = Path(source).suffix[1:] in (IMG_FORMATS + VID_FORMATS)
|
||||||
('rtsp://', 'rtmp://', 'http://', 'https://'))
|
is_url = source.lower().startswith(('rtsp://', 'rtmp://', 'http://', 'https://'))
|
||||||
|
webcam = source.isnumeric() or source.endswith('.txt') or (is_url and not is_file)
|
||||||
|
if is_url and is_file:
|
||||||
|
source = check_file(source) # download
|
||||||
|
|
||||||
# Directories
|
# Directories
|
||||||
save_dir = increment_path(Path(project) / name, exist_ok=exist_ok) # increment run
|
save_dir = increment_path(Path(project) / name, exist_ok=exist_ok) # increment run
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue