perfanalytics / pose2sim

Markerless kinematics with any cameras — From 2D Pose estimation to 3D OpenSim motion
https://perfanalytics.github.io/pose2sim/
BSD 3-Clause "New" or "Revised" License
271 stars 50 forks source link

Pose Estimation Shape Mismatch #131

Closed 161siegels closed 1 month ago

161siegels commented 2 months ago

I have been running into an error with multi person pose estimation. On my example, i keep getting shape mismatch errors. It seems that one of the frames is thrown out when calculating track_ids_last_frame but keypoints has every frame. I am using HALPE_26 and Yolox. Here is where the code errors, followed by the error message. Any help is welcome!

keypoints_filled[pose_tracker.track_ids_last_frame] = keypoints

File "/Users/161siegels/miniconda3/envs/Pose2Sim/lib/python3.9/site-packages/Pose2Sim/poseEstimation.py", line 168, in process_video keypoints_filled[pose_tracker.track_ids_last_frame] = keypoints ValueError: shape mismatch: value array of shape (13,26,2) could not be broadcast to indexing result of shape (12,26,2)

If I edit this line to be: keypoints_filled[pose_tracker.track_ids_last_frame] = keypoints[pose_tracker.track_ids_last_frame] then it would work but I am unclear if this is problematic

davidpagnon commented 2 months ago

Hi, thanks for sharing! Could you try to set tracking to false in your config file ? In the meantime, I'll try to pin the issue and fix it.

And if I can't find it and that's possible for you, could you send your data to contact@david-pagnon.com?

161siegels commented 2 months ago

It works if tracking is false but we want tracking (my understanding is this allows for reidentification of people between frames).

Unfortunately I cannot send my data, but I appreciate you looking into this for me! I tried stepping through the code and I couldn't quite put my finger on it but my hunch is that it is some rounding error.

If this helps, when I reduce the frame rate slightly (from the default 60 fps), i get a different mismatch error

(11,26,2) could not be broadcast to indexing result of shape (12,26,2))

davidpagnon commented 2 months ago

It works if tracking is false but we want tracking (my understanding is this allows for reidentification of people between frames).

The reidentification of people between frames is done at the triangulation stage, so it should not matter. At this stage, tracking is only useful for synchronization if you need it, but I'll try to fix it anyway.

Could you send me the whole error message? (both, actually)?

161siegels commented 2 months ago

Ah thanks for the clarification! Really appreciate the quick responses too!! This repo is awesome. When you say synchronization if needed, do you mean that it will need it for synchronization if the videos are not perfectly aligned? Or is this an additional aid for synchronization that you think is often not necessary.

Just trying to gauge how necessary you think this it is for us to allow tracking (I understand this may be difficult without seeing the data).

Here is the full error message:

Traceback (most recent call last): File "/Users/xxx/miniconda3/envs/Pose2Sim/lib/python3.9/runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "/Users/xxx/miniconda3/envs/Pose2Sim/lib/python3.9/runpy.py", line 87, in _run_code exec(code, run_globals) File "/Users/xxx/.vscode/extensions/ms-python.debugpy-2024.10.0-darwin-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/main.py", line 39, in cli.main() File "/Users/xxx/.vscode/extensions/ms-python.debugpy-2024.10.0-darwin-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main run() File "/Users/xxx/.vscode/extensions/ms-python.debugpy-2024.10.0-darwin-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 284, in run_file runpy.run_path(target, run_name="main") File "/Users/xxx/.vscode/extensions/ms-python.debugpy-2024.10.0-darwin-arm64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 321, in run_path return _run_module_code(code, init_globals, run_name, File "/Users/xxx/.vscode/extensions/ms-python.debugpy-2024.10.0-darwin-arm64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 135, in _run_module_code _run_code(code, mod_globals, init_globals, File "/Users/xxx/.vscode/extensions/ms-python.debugpy-2024.10.0-darwin-arm64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code exec(code, run_globals) File "/Users/xxx/Documents/Trial/main.py", line 3, in Pose2Sim.poseEstimation() File "/Users/xxx/miniconda3/envs/Pose2Sim/lib/python3.9/site-packages/Pose2Sim/Pose2Sim.py", line 237, in poseEstimation rtm_estimator(config_dict) File "/Users/xxx/miniconda3/envs/Pose2Sim/lib/python3.9/site-packages/Pose2Sim/poseEstimation.py", line 433, in rtm_estimator process_video(video_path, pose_tracker, tracking, output_format, save_video, save_images, display_detection, frame_range) File "/Users/xxx/miniconda3/envs/Pose2Sim/lib/python3.9/site-packages/Pose2Sim/poseEstimation.py", line 168, in process_video keypoints_filled[pose_tracker.track_ids_last_frame] = keypoints ValueError: shape mismatch: value array of shape (13,26,2) could not be broadcast to indexing result of shape (12,26,2)

davidpagnon commented 2 months ago

Thanks for the appreciation! And thanks for the error message as well, I'll have a look in the next few days.

It depends on what you are trying to do:

161siegels commented 2 months ago

Makes sense! I think we would want tracking for our use case then. Thanks again

davidpagnon commented 2 months ago

I'll write a fix and keep you updated as soon as the new version is released then

davidpagnon commented 2 months ago

The update is uploaded, you can upgrade your pose2sim version with pip install pose2sim -U.

Just to keep you informed, I plan to integrate the OpenSim stage within Pose2Sim by the end of the week :)

davidpagnon commented 2 months ago

Sorry, I'm just realizing that I introduced another bug, I'm currently trying to fix it! 😅

161siegels commented 2 months ago

No worries! May I ask what the bug is? I am having extrinsic calibration issues with one of my cameras. Doubt this would affect it but just curious

davidpagnon commented 2 months ago

It was a big on synchronization but I just solved it (although I did not push the release yet). We chose to synchronize on the person with the highest confidence to cope with bad detections, but the person in the background of the Single person demo is detected with a high confidence so that did not work great. Instead, I decided to synchronize on the person with the largest bounding box.

I don't think this has anything to do with your extrinsic calibration problem but tell me if you can't solve it!

161siegels commented 2 months ago

Sounds good! I think I solved the extrinsic calibration when using 2 of our 3 cameras (the reprojection error is low and the picture looks great). However, I am still having issues with the resulting 3d output having nonsensical coordinates. I will provide a bit about my setup + issues... any help would be greatly appreciated!

Setup

Issues

Thanks again for all your help! I understand this is a bit difficult without our data but I appreciate your patience and hard work

davidpagnon commented 2 months ago

From what you are telling me, the main difficult points seem to be:

Issues:

Not sure I correctly answered your comments so feel free to ask again!

161siegels commented 2 months ago

Thank you so much for the detailed response! I think you answered most of my questions but I have a few follow ups.

  1. Using the third (different) camera - hmm, i will keep playing around with it. I can't seem to get ext to work for some reason
  2. Heights and masses - makes sense, thanks for this
  3. 20 people - yes, that is exactly what I want to do. Get coordinates for all and then remove people myself. However, it only seems to give me 3d files for 2 people. I just get P1 files and P2 files. How can I specify otherwise?
  4. Synchronization - yes, I realized this morning that this was an issue. I am going to try to synchronize the videos with ffmpeg
  5. Extrinsic Calculation - Yes, but if I specify calculate_extrinsics=false, will it use my last calculation? That was not clear to me as it is with overwrite_extrinsics. I want to keep the extrinsic calculation from a previous calibration
davidpagnon commented 2 months ago
  1. What is your problem? Do you have high distortions on this third camera?
  2. 20 people with 2 cameras is extremely challenging. You'll have to see if a good synchronization helps, otherwise you may need more cameras!
  3. It should not overwrite your last extrinsics. If you are afraid of it, just copy your last calibration file and give it the name calibration.toml.old. But How could intrinsic parameters change and not the extrinsic ones?
161siegels commented 2 months ago
  1. The problem is the reprojection points are very far from the points I click when i calibrate via 'scene'
  2. Sounds good, I will try with better synchronization and go from there
  3. Ok so it does save the extrinsic. I wasn't 100% sure. My intrinsic and extrinsic are not changing. I set overwrite_intrinsic to false but did not realize that setting calculate_extrinsic to false would also grab the old ext calibration. My misunderstanding. Thanks!
davidpagnon commented 2 months ago

Is it possible to send me just the folder with your calibration images/videos (intrinsic and extrinsic) so that I can check?

davidpagnon commented 1 month ago

This issue has been handled by email, and is consequently closed.