EmptyPoseBody: zero-allocation reads + fix v0.1 frame count via BytesIOReader#234
Merged
Conversation
…OReader unpack_empty_tensor now returns a zero-stride broadcast view instead of np.empty, keeping shape and dtype without allocating shape-sized memory. Adding a shape test exposed a pre-existing bug: BytesIOReader.bytes_left() only counted already-buffered bytes, so v0.1 files (which infer frame count from bytes_left) read 0 frames through any BytesIOReader path (EmptyPoseBody, start_frame/start_time on file objects). bytes_left() now reports the stream's remaining bytes, matching BufferReader semantics, while expect_to_read uses the new buffered_bytes_left() for chunk fetching. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
1.
unpack_empty_tensorno longer allocatesReturns
np.broadcast_to(np.array(0, dtype=...), shape)— a zero-stride, read-only view backed by 4 bytes — instead ofnp.empty(shape).EmptyPoseBodykeeps the full shape and dtype without shape-sized memory, and values are now deterministically0instead of uninitialized garbage.2. Fix: v0.1 files read 0 frames through
BytesIOReaderAdding a shape test for
EmptyPoseBodyexposed a pre-existing bug:read_v0_1infers the frame count fromreader.bytes_left(), butBytesIOReader.bytes_left()only counted already-buffered bytes — nearly zero right after the header. This broke every v0.1 read through theBytesIOReaderpath, not justEmptyPoseBody:bytes_left()now reports the stream's remaining bytes (matchingBufferReadersemantics), whileexpect_to_readuses a newbuffered_bytes_left()to decide when to fetch more from the file — the two callers need different quantities.3. Tests
test_unpack_empty_tensor: shape, dtype, and buffer advancement.test_read_empty_pose_body_shape_matches_numpy_pose_body: reads every sample.posefile with bothNumPyPoseBodyandEmptyPoseBodyand asserts identical data shape, dtype, confidence shape, and fps. Skips the legacy v0.0openpose.pose(EmptyPoseBodyhas never supported v0.0, which stores variable people per frame).Verification
EmptyPoseBodyonmediapipe.pose: shape(170, 1, 178, 3), strides(0, 0, 0, 0), 4-byte backing buffer (previously read as 0 frames).Pose.read(f, start_frame=5)on a v0.1 file now matches a bytes-based read exactly (shape and values).🤖 Generated with Claude Code