Skip to content

Fix identity comparison (is not) to value comparison (!=)#557

Open
Mr-Neutr0n wants to merge 1 commit intoKlingAIResearch:mainfrom
Mr-Neutr0n:fix/identity-vs-equality-comparison
Open

Fix identity comparison (is not) to value comparison (!=)#557
Mr-Neutr0n wants to merge 1 commit intoKlingAIResearch:mainfrom
Mr-Neutr0n:fix/identity-vs-equality-comparison

Conversation

@Mr-Neutr0n
Copy link

Summary

In src/live_portrait_pipeline.py, the execute() method uses is not for integer comparisons on two lines (lines 156 and 199). This performs an identity check rather than a value check. In CPython, integers outside the internally cached range of [-5, 256] are not guaranteed to be the same object, so is not can incorrectly return True even when the values are equal.

This causes incorrect frame count adjustment for videos with more than 256 frames, leading to silent output truncation.

Before:

if len(ret_d["frame_crop_lst"]) is not n_frames and flag_is_driving_video:
if len(ret_s["frame_crop_lst"]) is not n_frames:

After:

if len(ret_d["frame_crop_lst"]) != n_frames and flag_is_driving_video:
if len(ret_s["frame_crop_lst"]) != n_frames:

Test plan

  • Process a driving video with more than 256 frames and verify that the output frame count matches the input when all frames are successfully cropped.
  • Process a source video with more than 256 frames and verify correct frame count handling.
  • Verify that videos with fewer than 256 frames continue to work correctly (no regression).

In `execute()`, two comparisons used `is not` instead of `!=` to
compare integer values. In CPython, integers outside the cached
range [-5, 256] are not guaranteed to be the same object, so `is not`
can return True even when the values are equal. This causes incorrect
frame count adjustment for videos with more than 256 frames,
leading to silent output truncation.

Replace `is not` with `!=` for correct value-based comparison.
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.

1 participant