NNT Image To Tensor
Your bridge from pixels to training data
- image
- TENSOR
ComfyUI thinks in IMAGE tensors - [batch, height, width, channels], values 0–1. The Neural Network Toolkit thinks in TENSORs it can train on. NNT Image To Tensor is the adapter between those two worlds: it takes a ComfyUI image and converts it into the tensor shape and layout your NNT model expects. If you're building a model that classifies images you already have in your ComfyUI workflow, this node is your front door.
What it actually does
It takes the input IMAGE (shape [B, H, W, C], range 0–1), and for each image in the batch: converts to a PIL image, applies color mode, resizes, optionally crops, and repacks it as a tensor. The output TENSOR is channels-first ([C, H, W] per image, batched up) - the convention your conv layers expect. Resizing uses LANCZOS by default for quality downsampling.
Inputs that matter
image- any ComfyUI image output: aLoadImageresult, a generated image, whatever.width/height- the target size, both defaulting to 512. Resize happens first; if you also want a crop, read on.crop-False(default) just stretches the image towidth×height.Truedoes a center crop: it first resizes to fit, then crops awidth×heightwindow from the middle. UseTruewhen you don't want distortion but need an exact size.color_mode-RGBorGrayscale. Grayscale is the classic choice for MNIST-style tasks and for shrinking your model's input; set it and your tensor drops to a single channel.flatten-Truesquashes each image into a flat vector, which is what you want if you're skipping conv layers and going straight to a dense classifier (the pack's linear regression example takes a similar route).
The one gotcha
Channel order. ComfyUI images are [H, W, C]; NNT tensors need [C, H, W]. The node handles that swap for you, so you don't think about it - but if you ever hand a tensor to a node that expects ComfyUI's layout back, remember the order is different. Also mind the 0-1 scale: the conversion keeps values in 0–1 (it doesn't blindly multiply to 0–255), so don't add your own normalization unless your model needs it. For a model built with NntInputLayer as [3, 224, 224], set width/height to 224 and feed the output straight in.
Installing NNT
Part of inventorado/ComfyUI_NNT. ComfyUI Manager (search "ComfyUI Neural Network Toolkit") or:
cd ComfyUI/custom_nodes
git clone https://github.com/inventorado/ComfyUI_NNT.git
cd ComfyUI_NNT
pip install -r requirements.txt
Restart ComfyUI after. The requirements are a heavy scientific stack (torch, numpy, scikit-learn, Pillow, pandas, transformers), so the first install is chunky. The pack's example workflows also want ComfyUI-Jjk-Nodes for text output; Manager's "Install Missing Custom Nodes" covers it.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| width | INT | 5121–4096 | — |
| height | INT | 5121–4096 | — |
| crop | COMBO | False | 2 options: False, True |
| color_mode | COMBO | RGB | 2 options: RGB, Grayscale |
| flatten | COMBO | False | 2 options: False, True |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TENSOR | TENSOR | — |