Some cleanups to the load image node (CORE-145)#13677
Conversation
📝 WalkthroughWalkthroughThe 🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✅ Passed checks (2 passed)
✏️ 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.
Built for teams:
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. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
There was a problem hiding this comment.
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 winNormalize 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 whentorch.catsees both(1, H, W)and(1, 64, 64)entries.LoadImageMask.load_imagebelow already handles this by normalizing to RGBA first; this path should do the same (or restore the oldP/Ihandling).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).
No description provided.