NNT Tensor Slice
NNT Tensor Slice — grab a few rows out of a tensor (or image) without leaving the graph
- tensor
- image
- TENSOR
- IMAGE
Sometimes you don't want the whole batch. NNT Tensor Slice is the toolkit's way of cutting a chunk out of a tensor (or an image) so you can inspect it, plot it, or feed a single sample somewhere. It's a debug-and-explore node, and for a teaching pack that's a core job.
The inputs
- start_element (default 0) - where to start cutting, along the first (batch) dimension.
- num_elements (default 1) - how many rows to keep. Slice of 1 = one sample.
- flatten (False) - squash the tensor to 1D first, then slice. Useful when you want a flat vector of values.
- reshape (False) + shape (default
[1,1,1]) - reshape the sliced chunk.shapeis a Python-list string like[1, 28, 28]that gets evaluated. Only applies after the slice. - convert_mask (False) - permute the result to
[N, 3, H, W]layout. Handy if you're slicing image-ish tensors that arrived in channels-last form and need them back in image format.
The node takes tensor or image as an optional input - wire whichever you're cutting. Outputs: TENSOR and IMAGE (both get the same sliced data, so pick the type that matches your downstream node).
How it works
Simple and honest: it picks whichever input you gave it, converts to float32 if needed, optionally flattens, then does tensor[start : start + num_elements]. If your range runs past the end, it silently clamps the count instead of erroring - nice behavior. Then the optional reshape (via eval(shape)) and the mask-permute apply. If anything throws, it returns the input unchanged rather than crashing the workflow, so a bad shape string won't kill your run - it'll just quietly do nothing.
When you'd actually use it
- Spot-check your data - after a dataset-to-tensor conversion, slice off one sample and inspect it.
- Single-sample inference - pull one row out of a test set and feed it to the pack's inference node.
- Debugging shapes - confirm your slice has the shape you expect before it enters a model.
It's a tiny node, and its one impression with a 100% CTR suggests the couple of people who landed on it knew what they wanted. For the toolkit's "see what's inside your tensors" philosophy it's the right companion to the plot and text-display nodes.
Common issues
- Nothing happens - you probably fed a malformed
shapestring (evalfails silently), or didn't connect either input. - Start index out of range - the node raises a clear error for that one case and returns the input as-is.
- Slicing images - remember IMAGE tensors in ComfyUI are
[N, H, W, C](channels-last).flattenwill destroy that layout; useconvert_maskif you need channels-first back.
Install
Part of the pack:
cd ComfyUI/custom_nodes
git clone https://github.com/inventorado/ComfyUI_NNT.git
cd ComfyUI_NNT
pip install -r requirements.txt
or ComfyUI Manager → "ComfyUI Neural Network Toolkit NNT", restart, and it's under NNT Neural Network Toolkit/Tensors.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| start_element | INT | 00–2147483647 | — |
| num_elements | INT | 11–2147483647 | — |
| flatten | COMBO | False | 2 options: True, False |
| reshape | COMBO | False | 2 options: True, False |
| shape | STRING | [1,1,1] | — |
| convert_mask | COMBO | False | 2 options: True, False |
| tensoropt | TENSOR | — | |
| imageopt | IMAGE | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| TENSOR | TENSOR | — |
| IMAGE | IMAGE | — |