glenn-jocher pre-commit-ci[bot] commited on
Commit
75bbaa8
·
unverified ·
1 Parent(s): 6a67594

Reject webcam inference on Colab/Kaggle (#8209)

Browse files

* Reject webcam inference on Colab/Kaggle

Improve user error understanding for https://github.com/ultralytics/yolov5/issues/8180

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* cleanup

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

Files changed (1) hide show
  1. utils/dataloaders.py +4 -1
utils/dataloaders.py CHANGED
@@ -28,7 +28,7 @@ from tqdm import tqdm
28
 
29
  from utils.augmentations import Albumentations, augment_hsv, copy_paste, letterbox, mixup, random_perspective
30
  from utils.general import (DATASETS_DIR, LOGGER, NUM_THREADS, check_dataset, check_requirements, check_yaml, clean_str,
31
- cv2, segments2boxes, xyn2xy, xywh2xyxy, xywhn2xyxy, xyxy2xywhn)
32
  from utils.torch_utils import torch_distributed_zero_first
33
 
34
  # Parameters
@@ -321,6 +321,9 @@ class LoadStreams:
321
  import pafy
322
  s = pafy.new(s).getbest(preftype="mp4").url # YouTube URL
323
  s = eval(s) if s.isnumeric() else s # i.e. s = '0' local webcam
 
 
 
324
  cap = cv2.VideoCapture(s)
325
  assert cap.isOpened(), f'{st}Failed to open {s}'
326
  w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
 
28
 
29
  from utils.augmentations import Albumentations, augment_hsv, copy_paste, letterbox, mixup, random_perspective
30
  from utils.general import (DATASETS_DIR, LOGGER, NUM_THREADS, check_dataset, check_requirements, check_yaml, clean_str,
31
+ cv2, is_colab, is_kaggle, segments2boxes, xyn2xy, xywh2xyxy, xywhn2xyxy, xyxy2xywhn)
32
  from utils.torch_utils import torch_distributed_zero_first
33
 
34
  # Parameters
 
321
  import pafy
322
  s = pafy.new(s).getbest(preftype="mp4").url # YouTube URL
323
  s = eval(s) if s.isnumeric() else s # i.e. s = '0' local webcam
324
+ if s == 0:
325
+ assert not is_colab(), '--source 0 webcam unsupported on Colab. Rerun command in a local environment.'
326
+ assert not is_kaggle(), '--source 0 webcam unsupported on Kaggle. Rerun command in a local environment.'
327
  cap = cv2.VideoCapture(s)
328
  assert cap.isOpened(), f'{st}Failed to open {s}'
329
  w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))