Support .txt files as a line-by-line media list rather than streams (#10059)
* Update streams.txt default Signed-off-by: Colin Wong <cwongmath@gmail.com> * Change streams list extension to .streams * Read txt as media per line * Missed one * Missed another one * Update dataloaders.py * Update detect.py * Update dataloaders.py * Update detect.py * Update predict.py * Update predict.py * Update README.md Signed-off-by: Colin Wong <cwongmath@gmail.com> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
1 parent
9722e6ffe5
commit
5dc1ce4e86
5 files changed
+22
-12
No files matched your search
@@ -182,14 +182,16 @@ results.print() # or .show(), .save(), .crop(), .pandas(), etc.
|
|||||||
the latest YOLOv5 [release](https://github.com/ultralytics/yolov5/releases) and saving results to `runs/detect`.
|
the latest YOLOv5 [release](https://github.com/ultralytics/yolov5/releases) and saving results to `runs/detect`.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python detect.py --source 0 # webcam
|
python detect.py --weights yolov5s.pt --source 0 # webcam
|
||||||
img.jpg # image
|
img.jpg # image
|
||||||
vid.mp4 # video
|
vid.mp4 # video
|
||||||
screen # screenshot
|
screen # screenshot
|
||||||
path/ # directory
|
path/ # directory
|
||||||
'path/*.jpg' # glob
|
list.txt # list of images
|
||||||
'https://youtu.be/Zgi9g1ksQHc' # YouTube
|
list.streams # list of streams
|
||||||
'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream
|
'path/*.jpg' # glob
|
||||||
|
'https://youtu.be/Zgi9g1ksQHc' # YouTube
|
||||||
|
'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|||||||
+3
-1
@@ -8,6 +8,8 @@ Usage - sources:
|
|||||||
vid.mp4 # video
|
vid.mp4 # video
|
||||||
screen # screenshot
|
screen # screenshot
|
||||||
path/ # directory
|
path/ # directory
|
||||||
|
list.txt # list of images
|
||||||
|
list.streams # list of streams
|
||||||
'path/*.jpg' # glob
|
'path/*.jpg' # glob
|
||||||
'https://youtu.be/Zgi9g1ksQHc' # YouTube
|
'https://youtu.be/Zgi9g1ksQHc' # YouTube
|
||||||
'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream
|
'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream
|
||||||
@@ -74,7 +76,7 @@ def run(
|
|||||||
save_img = not nosave and not source.endswith('.txt') # save inference images
|
save_img = not nosave and not source.endswith('.txt') # save inference images
|
||||||
is_file = Path(source).suffix[1:] in (IMG_FORMATS + VID_FORMATS)
|
is_file = Path(source).suffix[1:] in (IMG_FORMATS + VID_FORMATS)
|
||||||
is_url = source.lower().startswith(('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)
|
webcam = source.isnumeric() or source.endswith('.streams') or (is_url and not is_file)
|
||||||
screenshot = source.lower().startswith('screen')
|
screenshot = source.lower().startswith('screen')
|
||||||
if is_url and is_file:
|
if is_url and is_file:
|
||||||
source = check_file(source) # download
|
source = check_file(source) # download
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ Usage - sources:
|
|||||||
vid.mp4 # video
|
vid.mp4 # video
|
||||||
screen # screenshot
|
screen # screenshot
|
||||||
path/ # directory
|
path/ # directory
|
||||||
|
list.txt # list of images
|
||||||
|
list.streams # list of streams
|
||||||
'path/*.jpg' # glob
|
'path/*.jpg' # glob
|
||||||
'https://youtu.be/Zgi9g1ksQHc' # YouTube
|
'https://youtu.be/Zgi9g1ksQHc' # YouTube
|
||||||
'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream
|
'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream
|
||||||
@@ -82,7 +84,7 @@ def run(
|
|||||||
save_img = not nosave and not source.endswith('.txt') # save inference images
|
save_img = not nosave and not source.endswith('.txt') # save inference images
|
||||||
is_file = Path(source).suffix[1:] in (IMG_FORMATS + VID_FORMATS)
|
is_file = Path(source).suffix[1:] in (IMG_FORMATS + VID_FORMATS)
|
||||||
is_url = source.lower().startswith(('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)
|
webcam = source.isnumeric() or source.endswith('.streams') or (is_url and not is_file)
|
||||||
screenshot = source.lower().startswith('screen')
|
screenshot = source.lower().startswith('screen')
|
||||||
if is_url and is_file:
|
if is_url and is_file:
|
||||||
source = check_file(source) # download
|
source = check_file(source) # download
|
||||||
|
|||||||
+3
-1
@@ -8,6 +8,8 @@ Usage - sources:
|
|||||||
vid.mp4 # video
|
vid.mp4 # video
|
||||||
screen # screenshot
|
screen # screenshot
|
||||||
path/ # directory
|
path/ # directory
|
||||||
|
list.txt # list of images
|
||||||
|
list.streams # list of streams
|
||||||
'path/*.jpg' # glob
|
'path/*.jpg' # glob
|
||||||
'https://youtu.be/Zgi9g1ksQHc' # YouTube
|
'https://youtu.be/Zgi9g1ksQHc' # YouTube
|
||||||
'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream
|
'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream
|
||||||
@@ -85,7 +87,7 @@ def run(
|
|||||||
save_img = not nosave and not source.endswith('.txt') # save inference images
|
save_img = not nosave and not source.endswith('.txt') # save inference images
|
||||||
is_file = Path(source).suffix[1:] in (IMG_FORMATS + VID_FORMATS)
|
is_file = Path(source).suffix[1:] in (IMG_FORMATS + VID_FORMATS)
|
||||||
is_url = source.lower().startswith(('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)
|
webcam = source.isnumeric() or source.endswith('.streams') or (is_url and not is_file)
|
||||||
screenshot = source.lower().startswith('screen')
|
screenshot = source.lower().startswith('screen')
|
||||||
if is_url and is_file:
|
if is_url and is_file:
|
||||||
source = check_file(source) # download
|
source = check_file(source) # download
|
||||||
|
|||||||
@@ -238,6 +238,8 @@ class LoadScreenshots:
|
|||||||
class LoadImages:
|
class LoadImages:
|
||||||
# YOLOv5 image/video dataloader, i.e. `python detect.py --source image.jpg/vid.mp4`
|
# YOLOv5 image/video dataloader, i.e. `python detect.py --source image.jpg/vid.mp4`
|
||||||
def __init__(self, path, img_size=640, stride=32, auto=True, transforms=None, vid_stride=1):
|
def __init__(self, path, img_size=640, stride=32, auto=True, transforms=None, vid_stride=1):
|
||||||
|
if isinstance(path, str) and Path(path).suffix == ".txt": # *.txt file with img/vid/dir on each line
|
||||||
|
path = Path(path).read_text().rsplit()
|
||||||
files = []
|
files = []
|
||||||
for p in sorted(path) if isinstance(path, (list, tuple)) else [path]:
|
for p in sorted(path) if isinstance(path, (list, tuple)) else [path]:
|
||||||
p = str(Path(p).resolve())
|
p = str(Path(p).resolve())
|
||||||
@@ -338,7 +340,7 @@ class LoadImages:
|
|||||||
|
|
||||||
class LoadStreams:
|
class LoadStreams:
|
||||||
# YOLOv5 streamloader, i.e. `python detect.py --source 'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP streams`
|
# YOLOv5 streamloader, i.e. `python detect.py --source 'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP streams`
|
||||||
def __init__(self, sources='streams.txt', img_size=640, stride=32, auto=True, transforms=None, vid_stride=1):
|
def __init__(self, sources='file.streams', img_size=640, stride=32, auto=True, transforms=None, vid_stride=1):
|
||||||
torch.backends.cudnn.benchmark = True # faster for fixed-size inference
|
torch.backends.cudnn.benchmark = True # faster for fixed-size inference
|
||||||
self.mode = 'stream'
|
self.mode = 'stream'
|
||||||
self.img_size = img_size
|
self.img_size = img_size
|
||||||
|
|||||||
Reference in new issue
Block a user