Skip to content

Some cleanups to the load image node (CORE-145)#13677

Merged
comfyanonymous merged 1 commit into
masterfrom
temp_pr
May 3, 2026
Merged

Some cleanups to the load image node (CORE-145)#13677
comfyanonymous merged 1 commit into
masterfrom
temp_pr

Conversation

@comfyanonymous

Copy link
Copy Markdown
Member

No description provided.

@coderabbitai

coderabbitai Bot commented May 3, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The LoadImage.load_image method now precomputes an intermediate dtype and device at the start, ensuring consistent tensor placement across code paths. In the video fast-path, decoded images and masks are explicitly converted to the precomputed device and dtype before returning. The animated-image fallback similarly applies device/dtype conversion, generating zero masks for frames lacking alpha bands and concatenating all outputs before moving them to the target device/dtype.

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided by the author. Add a description explaining the changes, such as: 'Refactor LoadImage to determine device/dtype upfront and apply consistently to both fast and fallback paths.'
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is vague and generic, using the non-descriptive term 'cleanups' without conveying specific information about what was improved. Replace 'Some cleanups' with a specific description, e.g., 'Unify device/dtype handling in LoadImage across video and fallback paths' for clarity.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get your free trial and get 200 agent minutes per Slack user (a $50 value).


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
nodes.py (1)

1718-1738: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Normalize animated frames to RGBA before deriving the mask.

Checking 'A' in i.getbands() on the raw frame misses palette/transparency cases, so transparent animated GIF/WebP frames now fall into the zero-mask branch and lose their mask. Because that branch also hard-codes (64, 64), mixed alpha/non-alpha animations will now crash at Line 1738 when torch.cat sees both (1, H, W) and (1, 64, 64) entries. LoadImageMask.load_image below already handles this by normalizing to RGBA first; this path should do the same (or restore the old P/I handling).

Suggested fix
         for i in ImageSequence.Iterator(img):
             i = node_helpers.pillow(ImageOps.exif_transpose, i)
-
-            image = i.convert("RGB")
+            frame = i
+            if frame.mode == "I":
+                frame = frame.point(lambda v: v * (1 / 255))
+            rgba = frame if frame.getbands() == ("R", "G", "B", "A") else frame.convert("RGBA")
+            image = rgba.convert("RGB")
@@
-            if 'A' in i.getbands():
-                mask = np.array(i.getchannel('A')).astype(np.float32) / 255.0
-                mask = 1. - torch.from_numpy(mask)
-            else:
-                mask = torch.zeros((64, 64), dtype=torch.float32, device="cpu")
+            mask = 1.0 - torch.from_numpy(
+                np.array(rgba.getchannel("A")).astype(np.float32) / 255.0
+            )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@nodes.py` around lines 1718 - 1738, Normalize each frame to RGBA before
deriving the mask: replace the current use of i.convert("RGB") / checking 'A' in
i.getbands() with i = i.convert("RGBA") (or call convert("RGBA") first), extract
the RGB pixels for the image tensor but derive the mask from i.getchannel('A')
so the mask size matches the image (use image.size or numpy shape for H,W)
instead of the hard-coded (64,64), and ensure the mask tensor is created with
the same device/dtype before appending to output_masks (ref: variables/functions
output_images, output_masks, i and the mask creation branch in this loop; align
with LoadImageMask.load_image behavior).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@nodes.py`:
- Around line 1718-1738: Normalize each frame to RGBA before deriving the mask:
replace the current use of i.convert("RGB") / checking 'A' in i.getbands() with
i = i.convert("RGBA") (or call convert("RGBA") first), extract the RGB pixels
for the image tensor but derive the mask from i.getchannel('A') so the mask size
matches the image (use image.size or numpy shape for H,W) instead of the
hard-coded (64,64), and ensure the mask tensor is created with the same
device/dtype before appending to output_masks (ref: variables/functions
output_images, output_masks, i and the mask creation branch in this loop; align
with LoadImageMask.load_image behavior).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3ffaefda-220f-4f4d-9c52-d2f30e227199

📥 Commits

Reviewing files that changed from the base of the PR and between 783782d and 9997c95.

📒 Files selected for processing (1)
  • nodes.py
@comfyanonymous comfyanonymous merged commit ef6722f into master May 3, 2026
16 checks passed
@comfyanonymous comfyanonymous deleted the temp_pr branch May 3, 2026 00:35
@alexisrolland alexisrolland changed the title Some cleanups to the load image node. May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant