ComfyUI Node

RGB to BGR

When your embeddings look like static, try flipping the channels

By p1atdev·Created about a year ago·Updated about a year ago· 1
RGB to BGR
  • image
  • IMAGE

RGB to BGR is the smallest node in this pack and the easiest to dismiss: it takes an image, flips the channel order, gives it back. One input, one output, no options. But it exists for a real reason, and if you're chasing bad embeddings it's a ten-second experiment worth running.

Most vision backbones in timm were trained on RGB input, and ComfyUI hands you IMAGE tensors in RGB order, so the two line up and you never think about this. A smaller but very real slice of models - especially ones whose training pipeline loaded images through OpenCV, which defaults to BGR - were trained on flipped channels. Feed them RGB and the model sees a color-inverted world: the red channel is read as blue and vice versa. The features come out subtly scrambled, which reads as "my embeddings are nonsense" and sends you down a completely wrong debugging path.

The node is dead simple under the hood: it checks the image has exactly 3 channels (otherwise it raises ValueError("Input image must have 3 channels (RGB).")) and reverses the last dimension with torch.flip. That's it.

When to reach for it

  • Your timm encode output looks wrong or unrepeatable after you've already confirmed normalization is correct.
  • The model card or the training code for your chosen backbone mentions BGR or OpenCV loading.
  • You're porting a Python snippet that used cv2.imread and want parity with the original results.

Where people get burned: flipping channels after the model has already seen RGB isn't the same as feeding BGR - do the flip before the encode node, in this order: resize → Image NormalizeRGB to BGRTimm Backbone Image Encode. And don't leave it in the graph if the model doesn't need it; a gratuitous flip just turns correct embeddings into wrong ones. If you're not sure the model wants it, the honest answer is to try both and compare - two runs is cheaper than a forum post.

Install is the same as the rest of the pack: ComfyUI Manager search timm backbone, or clone https://github.com/p1atdev/comfyui-timm-backbone into custom_nodes and pip install -r requirements.txt. It's one of five nodes in a small pack that's really aimed at people building their own TENSOR-consuming custom nodes - this one just quietly sits upstream of the interesting part.

Categoryimage

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (1)

NameTypeDescription
IMAGEIMAGE