Skip to content

[draft] add optional return_2d flag for including 2D results in predict() return#21

Closed
deruyter92 wants to merge 1 commit intomainfrom
jaap/include_2d_return
Closed

[draft] add optional return_2d flag for including 2D results in predict() return#21
deruyter92 wants to merge 1 commit intomainfrom
jaap/include_2d_return

Conversation

@deruyter92
Copy link
Collaborator

@deruyter92 deruyter92 commented Feb 25, 2026

Motivation:
Currently, if an API-user is interested in the intermediate 2D results, instead of the single predict() call,they have to run a two step prepare_2d() + pose_3d(). This PR adds a minor convenience flag return_2d to include the intermediate 2D estimation in the returned final results for the predict() method.
hen interested in 2D results before lifting,

Changes:

  • added a field pose_2d to the output dataclass Pose3DResult.
  • predict() populates this field with the 2D pose estimation if return_2d=True

- added a field pose_2d to Pose3DResult.
- predict populates the field with the 2D pose estimation if return_2d=True
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an optional return_2d convenience flag to the inference API so callers of FMPose3DInference.predict() can retrieve the intermediate 2D estimation alongside the final 3D result.

Changes:

  • Added pose_2d: Pose2DResult | None to Pose3DResult.
  • Extended FMPose3DInference.predict(..., return_2d=False) to optionally attach the intermediate Pose2DResult.
  • Updated inference API README to document the new flag and result field.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
fmpose3d/inference_api/fmpose3d.py Adds return_2d plumbing and a new optional pose_2d field on Pose3DResult.
fmpose3d/inference_api/README.md Documents the new return_2d parameter and Pose3DResult.pose_2d field.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

progress=progress,
)
if return_2d:
result_3d.pose_2d = result_2d
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pose_3d() explicitly takes only the first person when keypoints_2d is 4D (see pose_3d input handling), but here return_2d attaches the full Pose2DResult (potentially containing multiple persons). This makes Pose3DResult.pose_2d ambiguous/inconsistent with the returned 3D poses. Consider either (a) filtering result_2d down to the same person used for lifting before attaching it, or (b) adding/returning an explicit person_index (and documenting that only that person is lifted).

Suggested change
result_3d.pose_2d = result_2d
# Ensure the attached 2D result matches the person subset used for lifting.
pose2d_for_3d = copy.copy(result_2d)
keypoints_2d = getattr(pose2d_for_3d, "keypoints", None)
if isinstance(keypoints_2d, np.ndarray) and keypoints_2d.ndim == 4:
# pose_3d() uses only the first person when keypoints_2d is 4D;
# mirror that here so pose_2d is consistent with the returned 3D poses.
pose2d_for_3d.keypoints = keypoints_2d[:, :1, ...]
result_3d.pose_2d = pose2d_for_3d

Copilot uses AI. Check for mistakes.
Comment on lines +706 to +708
if return_2d:
result_3d.pose_2d = result_2d
return result_3d
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New behavior (return_2d=True populating Pose3DResult.pose_2d) isn’t covered by the existing inference API tests. Please add a unit test to assert that pose_2d is None by default and is populated (and consistent with the lifted person) when return_2d=True.

Copilot uses AI. Check for mistakes.
@deruyter92 deruyter92 changed the title Inference API: add optional return_2d flag for including 2D results in predict() return [draft] add optional return_2d flag for including 2D results in predict() return Feb 25, 2026
@deruyter92
Copy link
Collaborator Author

Closing this PR. For separated 2D and 3D steps, use:

inference_api = FMPose3DInference(...)
results_2d = inference_api.prepare_2d(...)
results_3d = inference_api.pose_3d(results_2d, ...)

@deruyter92 deruyter92 closed this Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants