Skip to content

Commit

Permalink
Reject webcam inference on Colab/Kaggle
Browse files Browse the repository at this point in the history
Improve user error understanding for #8180
  • Loading branch information
glenn-jocher committed Jun 14, 2022
1 parent 6a67594 commit 51213e3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions utils/dataloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from utils.augmentations import Albumentations, augment_hsv, copy_paste, letterbox, mixup, random_perspective
from utils.general import (DATASETS_DIR, LOGGER, NUM_THREADS, check_dataset, check_requirements, check_yaml, clean_str,
cv2, segments2boxes, xyn2xy, xywh2xyxy, xywhn2xyxy, xyxy2xywhn)
cv2, is_colab, is_kaggle, segments2boxes, xyn2xy, xywh2xyxy, xywhn2xyxy, xyxy2xywhn)
from utils.torch_utils import torch_distributed_zero_first

# Parameters
Expand Down Expand Up @@ -83,7 +83,7 @@ def exif_transpose(image):
5: Image.TRANSPOSE,
6: Image.ROTATE_270,
7: Image.TRANSVERSE,
8: Image.ROTATE_90,}.get(orientation)
8: Image.ROTATE_90, }.get(orientation)
if method is not None:
image = image.transpose(method)
del exif[0x0112]
Expand Down Expand Up @@ -321,6 +321,9 @@ def __init__(self, sources='streams.txt', img_size=640, stride=32, auto=True):
import pafy
s = pafy.new(s).getbest(preftype="mp4").url # YouTube URL
s = eval(s) if s.isnumeric() else s # i.e. s = '0' local webcam
if s == 0:
assert not is_colab(), '--source 0 webcam inference is not supported on Colab notebooks'
assert not is_kaggle(), '--source 0 webcam inference is not supported on Kaggle notebooks'
cap = cv2.VideoCapture(s)
assert cap.isOpened(), f'{st}Failed to open {s}'
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
Expand Down

0 comments on commit 51213e3

Please sign in to comment.