Skip to content

Fix ltx2 i2av some input image failed#1111

Merged
helloyongyang merged 1 commit into
mainfrom
fix_ltx2
Jun 2, 2026
Merged

Fix ltx2 i2av some input image failed#1111
helloyongyang merged 1 commit into
mainfrom
fix_ltx2

Conversation

@huochaitiantang
Copy link
Copy Markdown
Collaborator

No description provided.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors image decoding in decode_image to convert images to RGB format and simplifies the array conversion. It also adds input validation and conversion logic in encode_single_frame to handle 2D grayscale images and enforce an RGB shape requirement. The review feedback suggests using a context manager with Image.open to prevent potential resource leaks and extending the grayscale handling to support 3D single-channel arrays of shape (H, W, 1).

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +118 to +119
image = Image.open(image_path).convert("RGB")
return np.array(image)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using Image.open without a context manager can leave the file handle open until the image object is garbage collected, which may lead to resource leaks (e.g., 'Too many open files' error) when processing many images. It is recommended to use a with statement to ensure the file is closed immediately after loading.

Suggested change
image = Image.open(image_path).convert("RGB")
return np.array(image)
with Image.open(image_path) as image:
return np.array(image.convert('RGB'))

Comment on lines +348 to +351
if image_array.ndim == 2:
image_array = np.stack([image_array, image_array, image_array], axis=-1)
elif image_array.ndim != 3 or image_array.shape[-1] != 3:
raise ValueError(f"Expected HxWx3 RGB image; got shape {image_array.shape}.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Grayscale images can sometimes be represented with a single channel dimension (e.g., shape (H, W, 1)). To make this function more robust, we can handle both 2D grayscale arrays and 3D single-channel arrays by squeezing the channel dimension before stacking.

Suggested change
if image_array.ndim == 2:
image_array = np.stack([image_array, image_array, image_array], axis=-1)
elif image_array.ndim != 3 or image_array.shape[-1] != 3:
raise ValueError(f"Expected HxWx3 RGB image; got shape {image_array.shape}.")
if image_array.ndim == 3 and image_array.shape[-1] == 1:
image_array = np.squeeze(image_array, axis=-1)
if image_array.ndim == 2:
image_array = np.stack([image_array, image_array, image_array], axis=-1)
elif image_array.ndim != 3 or image_array.shape[-1] != 3:
raise ValueError(f'Expected HxWx3 RGB image; got shape {image_array.shape}.')

@helloyongyang helloyongyang merged commit 7de67a3 into main Jun 2, 2026
2 checks passed
@helloyongyang helloyongyang deleted the fix_ltx2 branch June 2, 2026 05:32
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