ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
49.5k stars 16.08k forks source link

quick start, new rpi5: Failed to open tcp://127.0.0.1:8888 #12583

Closed stuartcrobinson closed 6 months ago

stuartcrobinson commented 8 months ago

Search before asking

YOLOv5 Component

Detection

Bug

re https://docs.ultralytics.com/guides/raspberry-pi/#quick-start-with-yolov5

brand new raspberry pi 5. followed the steps in that guide and got this:

(.venv) stuart@mypi:~ $ cd ~/yolov5
python3 detect.py --source=tcp://127.0.0.1:8888
detect: weights=yolov5s.pt, source=tcp://127.0.0.1:8888, data=data/coco128.yaml, imgsz=[640, 640], conf_thres=0.25, iou_thres=0.45, max_det=1000, device=, view_img=False, save_txt=False, save_csv=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs/detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False, vid_stride=1
YOLOv5 🚀 v7.0-267-gc42aba5 Python-3.11.2 torch-2.1.2 CPU

Downloading https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt to yolov5s.pt...
100%|██████████████████████████████████████| 14.1M/14.1M [00:00<00:00, 16.9MB/s]

Fusing layers... 
YOLOv5s summary: 213 layers, 7225885 parameters, 0 gradients, 16.4 GFLOPs
Traceback (most recent call last):
  File "/home/stuart/yolov5/detect.py", line 295, in <module>
    main(opt)
  File "/home/stuart/yolov5/detect.py", line 290, in main
    run(**vars(opt))
  File "/home/stuart/.venv/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/stuart/yolov5/detect.py", line 109, in run
    dataset = LoadStreams(source, img_size=imgsz, stride=stride, auto=pt, vid_stride=vid_stride)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stuart/yolov5/utils/dataloaders.py", line 397, in __init__
    assert cap.isOpened(), f'{st}Failed to open {s}'
AssertionError: 1/1: tcp://127.0.0.1:8888... Failed to open tcp://127.0.0.1:8888
(.venv) stuart@mypi:~/yolov5 $ 

libcamera-vid terminal window:

(.venv) stuart@mypi:~ $ libcamera-vid -n -t 0 --width 1280 --height 960 --framerate 1 --inline --listen -o tcp://127.0.0.1:8888
[0:26:05.314994219] [15946]  INFO Camera camera_manager.cpp:284 libcamera v0.1.0+118-563cd78e
[0:26:05.331492702] [15949]  INFO RPI pisp.cpp:653 libpisp version v1.0.2 fa44a258644a 22-11-2023 (21:59:22)
[0:26:05.352347996] [15949]  INFO RPI pisp.cpp:1112 Registered camera /base/axi/pcie@120000/rp1/i2c@88000/imx708@1a to CFE device /dev/media1 and ISP device /dev/media0 using PiSP variant BCM2712_C0
[0:26:31.866467254] [15946]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format Y16 
[0:26:31.866513495] [15946]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format RGB6
[0:26:31.866527273] [15946]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format BGR6
[0:26:31.866542310] [15946]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format PC1M
Mode selection for 1280:960:12:P(1)
    SRGGB10_CSI2P,1536x864/120.135 - Score: 1422.67
    SRGGB10_CSI2P,2304x1296/56.0255 - Score: 1506.67
    SRGGB10_CSI2P,4608x2592/14.3536 - Score: 2406.67
Stream configuration adjusted
[0:26:31.866852053] [15946]  INFO Camera camera.cpp:1183 configuring streams: (0) 1280x960-YUV420 (1) 1536x864-BGGR16_PISP_COMP1
[0:26:31.866927646] [15949]  INFO RPI pisp.cpp:1396 Sensor: /base/axi/pcie@120000/rp1/i2c@88000/imx708@1a - Selected sensor format: 1536x864-SBGGR10_1X10 - Selected CFE format: 1536x864-PC1B
[NULL @ 0x555661638720] Unable to find a suitable output format for 'tcp://127.0.0.1:8888'
ERROR: *** libav: cannot allocate output context ***
(.venv) stuart@mypi:~ $ 

i installed the OS today using Raspberry Pi Imager v1.8.4 and selected bookworm 64-bit released 2023-12-5

libcamera-hello seems to work. displays video feed for a few seconds.

system info:

(.venv) stuart@mypi:~/yolov5 $ uname -a
Linux mypi 6.1.0-rpi7-rpi-2712 #1 SMP PREEMPT Debian 1:6.1.63-1+rpt1 (2023-11-24) aarch64 GNU/Linux
(.venv) stuart@mypi:~/yolov5 $ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Environment

Minimal Reproducible Example

follow these steps to run yolov5 on a fresh rpi5 https://docs.ultralytics.com/guides/raspberry-pi/#quick-start-with-yolov5

Additional

No response

Are you willing to submit a PR?

github-actions[bot] commented 8 months ago

👋 Hello @stuartcrobinson, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Requirements

Python>=3.8.0 with all requirements.txt installed including PyTorch>=1.8. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

YOLOv5 CI

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

Introducing YOLOv8 🚀

We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 🚀!

Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects.

Check out our YOLOv8 Docs for details and get started with:

pip install ultralytics
stuartcrobinson commented 8 months ago

fwiw i get the same thing for yolov8, following the guide:

stuart@mypi:~ $ source .venv/bin/activate
(.venv) stuart@mypi:~ $ python
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ultralytics import YOLO

>>> 
>>> model = YOLO('yolov8n.pt')
Downloading https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt to 'yolov8n.pt'...
100%|██████████████████████████████████████| 6.23M/6.23M [00:00<00:00, 12.4MB/s]
>>> 
>>> 
>>> results = model('tcp://127.0.0.1:8888', stream=True)
>>> 
>>> 
>>> while True:
...     for result in results:
...         boxes = result.boxes
...         probs = result.probs
... 

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/stuart/.venv/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 35, in generator_context
    response = gen.send(None)
               ^^^^^^^^^^^^^^
  File "/home/stuart/.venv/lib/python3.11/site-packages/ultralytics/engine/predictor.py", line 241, in stream_inference
    self.setup_source(source if source is not None else self.args.source)
  File "/home/stuart/.venv/lib/python3.11/site-packages/ultralytics/engine/predictor.py", line 216, in setup_source
    self.dataset = load_inference_source(source=source,
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stuart/.venv/lib/python3.11/site-packages/ultralytics/data/build.py", line 166, in load_inference_source
    dataset = LoadStreams(source, imgsz=imgsz, vid_stride=vid_stride, buffer=buffer)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stuart/.venv/lib/python3.11/site-packages/ultralytics/data/loaders.py", line 92, in __init__
    raise ConnectionError(f'{st}Failed to open {s}')
ConnectionError: 1/1: tcp://127.0.0.1:8888... Failed to open tcp://127.0.0.1:8888
>>> 
stuart@mypi:~ $ source .venv/bin/activate
(.venv) stuart@mypi:~ $ libcamera-vid -n -t 0 --width 1280 --height 960 --framerate 1 --inline --listen -o tcp://127.0.0.1:8888
[0:00:53.163341819] [1947]  INFO Camera camera_manager.cpp:284 libcamera v0.1.0+118-563cd78e
[0:00:53.177607551] [1950]  INFO RPI pisp.cpp:653 libpisp version v1.0.2 fa44a258644a 22-11-2023 (21:59:22)
[0:00:53.196786487] [1950]  INFO RPI pisp.cpp:1112 Registered camera /base/axi/pcie@120000/rp1/i2c@88000/imx708@1a to CFE device /dev/media0 and ISP device /dev/media2 using PiSP variant BCM2712_C0
[0:02:04.510510919] [1947]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format Y16 
[0:02:04.510557562] [1947]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format RGB6
[0:02:04.510569875] [1947]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format BGR6
[0:02:04.510584114] [1947]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format PC1M
Mode selection for 1280:960:12:P(1)
    SRGGB10_CSI2P,1536x864/120.135 - Score: 1422.67
    SRGGB10_CSI2P,2304x1296/56.0255 - Score: 1506.67
    SRGGB10_CSI2P,4608x2592/14.3536 - Score: 2406.67
Stream configuration adjusted
[0:02:04.510956221] [1947]  INFO Camera camera.cpp:1183 configuring streams: (0) 1280x960-YUV420 (1) 1536x864-BGGR16_PISP_COMP1
[0:02:04.511068005] [1950]  INFO RPI pisp.cpp:1396 Sensor: /base/axi/pcie@120000/rp1/i2c@88000/imx708@1a - Selected sensor format: 1536x864-SBGGR10_1X10 - Selected CFE format: 1536x864-PC1B
[NULL @ 0x5556266e4720] Unable to find a suitable output format for 'tcp://127.0.0.1:8888'
ERROR: *** libav: cannot allocate output context ***
(.venv) stuart@mypi:~ $ 

also the guide worked fine for me on a rpi4 using the same camera

default-student commented 8 months ago

isnt that because tcp just isnt supported?

glenn-jocher commented 8 months ago

@default-student hello! It looks like you're encountering an issue with the TCP stream setup on your Raspberry Pi 5. The error message from libcamera-vid suggests that the output format for the TCP stream is not being recognized or supported.

The message Unable to find a suitable output format for 'tcp://127.0.0.1:8888' indicates that the streaming command might not be correctly setting up the video stream for YOLOv5 or YOLOv8 to consume.

Please ensure that you have followed all the steps correctly and that the libcamera-vid command is executed with the right parameters. Also, make sure that no other process is using the TCP port 8888 and that your firewall settings allow TCP connections on this port.

If the problem persists, you might want to try using a different method to provide the video stream to the model, such as using a file or a camera directly connected to the Raspberry Pi.

For further assistance, please refer to the Ultralytics Docs and consider opening an issue on the GitHub repository with the details of the error you're facing. The community and maintainers can help troubleshoot the problem more effectively there. Thank you for your contribution and for using YOLOv5! 🚀

github-actions[bot] commented 7 months ago

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐