Nodes/ComfyUI Neural Network Toolkit NNT /NNT Tensor Element To Image
ComfyUI Node

NNT Tensor Element To Image

The bridge that lets you actually see your tensors

By inventorado·Created 2 years ago·Updated 2 years ago· 69
NNT Tensor Element To Image
  • tensor
  • IMAGE
index0
convert_modeRGB
clamp_rangeTrue
reshapeFalse
channels3
height64
width64

Most of the Neural Network Toolkit lives in raw torch tensors that ComfyUI can't display. NNT Tensor Element To Image is the translator: it grabs one element out of a tensor - say, a single MNIST image from your batch of 32 - and converts it into an actual ComfyUI IMAGE that a Preview Image or Save Image node will happily render. If you've been staring at dataset_info strings and wondering what your data actually looks like, this is the node that answers.

It's also the fix for a specific trap in this pack: several visualization nodes (like the SHAP summary node) output their plots as TENSOR, not IMAGE. Run that tensor through this node and suddenly you can see the plot. Same trick works for inspecting what your model's input really is before you spend a training run on it.

How it works

Feed it a TENSOR and an index, and it pulls tensor[index] - the first dimension is treated as the batch. Then it normalizes, reshapes if asked, and converts to PIL and back into ComfyUI's [B,C,H,W] float format.

The inputs you'll actually touch:

  • index - which element of the batch to render (default 0).
  • convert_mode - RGB (default) or L (grayscale). Pick L for single-channel data like MNIST.
  • clamp_range - clamps values to [0, 1] before scaling to 0–255. Leave it on; off, and out-of-range values wrap around into garbage colors.
  • reshape - for flat vectors. If your tensor element is 1-D (like a flattened 784-pixel MNIST row), turn this on and set channels, height, width so the node can rebuild the 2-D image. The element count has to match channels × height × width exactly or it errors.

The output is a single IMAGE. That's it - one output, but it's the one that makes the rest of the pack legible.

Where people get burned

Two things get beginners. First, a 1-D tensor with reshape off raises "Tensor is flattened. Enable reshape option to convert to image." That's the node being honest - it can't guess your image dimensions. Second, values outside [0, 1] with clamping off produce visual garbage (which is why clamp defaults to on). And if your tensor is 2-D (single channel, H×W), no reshape needed - it auto-adds the channel dimension.

The channel handling is also worth knowing: in RGB mode a 1-channel image gets its single channel repeated into three, which is fine for viewing. In L mode an RGB tensor gets converted with the standard luminance weights, which is a reasonable grayscale conversion if you're stuck with 3-channel data.

Install

Part of the pack, one-time install:

cd ComfyUI/custom_nodes
git clone https://github.com/inventorado/ComfyUI_NNT.git
cd ComfyUI_NNT
pip install -r requirements.txt

Restart ComfyUI (or use Manager → search "ComfyUI Neural Network Toolkit NNT"). Heavy requirements - torch, numpy, pandas, matplotlib, sklearn, transformers, statsmodels, shap 0.41.0 - so give the first pip install a few minutes.

This is one of the thin-but-essential utility nodes: on its own it does one boring thing, but it's the node that connects the pack's invisible tensor world to ComfyUI's visible image world. You'll use it more than you expect.

CategoryNNT Neural Network Toolkit/Tensors

Inputs (8)

NameTypeDefaultDescription
tensorTENSOR
indexINT00–99999
convert_modeCOMBORGB2 options: L, RGB
clamp_rangeCOMBOTrue2 options: True, False
reshapeCOMBOFalse2 options: True, False
channelsINT31–4
heightINT641–8192
widthINT641–8192

Outputs (1)

NameTypeDescription
IMAGEIMAGE