Add camera-controlled Panda demo with YOLOv8 person detection#2
Add camera-controlled Panda demo with YOLOv8 person detection#2ChadliaJerad wants to merge 10 commits into
Conversation
|
@ChadliaJerad @edwardalee I was explaining this demo to my student today and noticed that this was not merged yet. Could we merge this PR into main soon? |
|
Sure! How about Edward doing the review, me working on the comments he will give, and you proceeding with the merge? |
Sounds good to me, thanks! |
There was a problem hiding this comment.
I am unable to get this working. See comments. I'm not crazy about the duplication of the YOLO code with the playground repo. It would be better to find a package manager solution so that both playground and this could import the video library. Or maybe this should go into the playground, which should import this mujoco-py library.
| **If you have an NVIDIA GPU**, select the correct CUDA version on the installation page and follow the generated command, for example: | ||
|
|
||
| ```bash | ||
| pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121 | ||
| ``` | ||
|
|
||
| **If you have no GPU (CPU only)**, install the CPU builds explicitly. Using the generic PyPI packages will cause a version mismatch and a segfault at runtime: | ||
|
|
||
| ```bash | ||
| pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu | ||
| ``` |
There was a problem hiding this comment.
Why not auto-detect whether there is a NVDIA GPU, Apple GPU, or CPU? Here is a possible template:
pip install torch torchvision
Then the following code will detect the device and use it in a test:
import torch
def get_compute_device() -> torch.device:
"""
Detects and returns the best available computing device.
Prioritizes CUDA, then Apple MPS, and falls back to CPU.
"""
if torch.cuda.is_available():
device_name = "cuda"
elif torch.backends.mps.is_available():
device_name = "mps"
else:
device_name = "cpu"
print(f"🚀 Device selected: {device_name.upper()}")
return torch.device(device_name)
if __name__ == "__main__":
# 1. Initialize the device
device = get_compute_device()
# 2. Test tensor creation directly on the active device
try:
x = torch.randn(3, 3, device=device)
y = torch.randn(3, 3, device=device)
z = torch.matmul(x, y)
print("\n✅ Verification Test Passed!")
print(f"Matrix multiplication result shape: {z.shape}")
print(f"Tensor is successfully hosted on: {z.device}")
except Exception as e:
print(f"\n❌ Error during tensor operations: {e}")| pip install -r requirements.txt | ||
| ``` | ||
|
|
||
| > **Note:** `requirements.txt` intentionally omits `torch` and `torchvision` so that the correct build variant (CPU or CUDA) can be chosen in the step above. |
There was a problem hiding this comment.
If we auto-detect, then requirements.txt should include these.
|
|
||
| ```bash | ||
| lfc src/PandaDemoCamCtrl.lf | ||
| bin/PandaDemoCamCtrl |
There was a problem hiding this comment.
On a mac, I had to do this:
mjpython src-gen/PandaDemoCamCtrl/PandaDemoCamCtrl.py
Then, the MuJoCo window opens, but then I get this error:
ERROR: FATAL: Calling reaction _display.reaction_function_1 failed.
Traceback (most recent call last):
File "/Users/edwardlee/git/Chadlia/mujoco-py/src-gen/PandaDemoCamCtrl/PandaDemoCamCtrl.py", line 575, in reaction_function_1
cv2.imshow("frame", frame.value)
cv2.error: Unknown C++ exception from OpenCV code
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'API misuse: modification of a menu's items on a non-main thread when the menu is part of the main menu. Main menu contents may only be modified from the main thread.'
This error should be avoided by the single-threaded: true target directive, but perhaps there is some incompatibility with mjpython?
| # NOTE: torch and torchvision are NOT listed here. | ||
| # Install them separately BEFORE running pip install -r requirements.txt. | ||
| # See README.md for the correct command depending on whether you have a GPU. | ||
| # | ||
| # CPU (no GPU): | ||
| # pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu | ||
| # | ||
| # NVIDIA GPU (example for CUDA 12.1): | ||
| # pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121 |
There was a problem hiding this comment.
Again, why not auto-detect?
| ipywidgets | ||
| ipython | ||
| ipykernel | ||
| matplotlib>=3.2.2 |
There was a problem hiding this comment.
Are you actually using matplotlib? This seems like a lot of requirements.
| @@ -0,0 +1,96 @@ | |||
| /** | |||
| * Copied from: https://github.com/lf-lang/playground-lingua-franca/blob/main/examples/Python/src/YOLOv5/Video.lf | |||
There was a problem hiding this comment.
Why not update the existing example rather than copy it here?
| @@ -0,0 +1,84 @@ | |||
| /** | |||
| * Copied from: https://github.com/lf-lang/playground-lingua-franca/blob/main/examples/Python/src/YOLOv5/VideoAsync.lf | |||
There was a problem hiding this comment.
Again, I don't think we should copy this here.
| // If you are using `mjpython`, then uncomment the following lines | ||
| // cmake-args: { | ||
| // Python_EXECUTABLE: "mjpython" | ||
| // } |
There was a problem hiding this comment.
Ah, this may be connected with the error I'm seeing. However, if I uncomment it, it still fails.
This PR:
PandaDemoCamCtrl.lf: Panda robot that pauses automatically when ≥2 people are detected by a YOLOv8 webcam feed, and resumes when the area is clearPandaDemoParameters.csvwith joint limits tuned to keep the arm above the floorREADMEand addssrc/lib/video/*files with setup and run instructions