lf-lang / playground-lingua-franca

:rocket: Try Lingua Franca now!
Other
16 stars 13 forks source link

Resurrection of the YOLO example #108

Closed edwardalee closed 6 months ago

edwardalee commented 6 months ago

This PR resurrects the YOLO example in examples/python, which now work for me on Mac. It would be great if someone else could try them out, particularly on a machine with a CUDA-compatible GPU (although it works fine without it).

lhstrh commented 6 months ago

I tried it, but it didn't work for me. I'm using Python 3.10 or ArchLinux.

---- System clock resolution: 1 nsec
Using cache found in /home/marten/.cache/torch/hub/ultralytics_yolov5_master
Downloading https://ultralytics.com/assets/Arial.ttf to /home/marten/.config/Ultralytics/Arial.ttf...
YOLOv5 🚀 2021-10-4 torch 2.2.2+cu121 CPU

Downloading https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt to /home/marten/.cache/torch/hub/ultralytics_yolov5_master/yolov5s.pt...
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 14.1M/14.1M [00:02<00:00, 5.71MB/s]

Fusing layers... 
/home/marten/.local/lib/python3.10/site-packages/torch/functional.py:507: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:3549.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
Model Summary: 213 layers, 7225885 parameters, 0 gradients
Adding AutoShape... 

******* Press 'q' in the video window to exit *******

ERROR: FATAL: Calling reaction _dnn.reaction_function_1 failed.
Traceback (most recent call last):
  File "/home/marten/lf-lang/playground-lingua-franca/examples/Python/src-gen/YOLOv5/YOLOv5_Webcam/YOLOv5_Webcam.py", line 267, in reaction_function_1
    results = self._model(fr)
  File "/home/marten/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/marten/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/marten/.local/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/home/marten/.cache/torch/hub/ultralytics_yolov5_master/models/common.py", line 337, in forward
    y = self.model(x, augment, profile)[0]  # forward
  File "/home/marten/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/marten/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/marten/.cache/torch/hub/ultralytics_yolov5_master/models/yolo.py", line 124, in forward
    return self._forward_once(x, profile, visualize)  # single-scale inference, train
  File "/home/marten/.cache/torch/hub/ultralytics_yolov5_master/models/yolo.py", line 147, in _forward_once
    x = m(x)  # run
  File "/home/marten/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/marten/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/marten/.cache/torch/hub/ultralytics_yolov5_master/models/yolo.py", line 67, in forward
    y[..., 2:4] = (y[..., 2:4] * 2) ** 2 * self.anchor_grid[i]  # wh
RuntimeError: The size of tensor a (80) must match the size of tensor b (56) at non-singleton dimension 3
../../bin/YOLOv5_Webcam: line 2: 2649161 Segmentation fault      (core dumped) /usr/bin/python3.10 /home/marten/lf-lang/playground-lingua-franca/examples/Python/src-gen/YOLOv5/YOLOv5_Webcam/YOLOv5_Webcam.py "$@"
edwardalee commented 6 months ago

Do the video examples work for you? I wonder this tensor size mismatch is because of some assumptions about the camera...

lhstrh commented 6 months ago

The video examples do work.

edwardalee commented 6 months ago

Does it work in the main branch?

lhstrh commented 6 months ago

Does it work in the main branch?

Assuming that you mean main of this repository, no, I get the same error.