NNT Define Reshape Layer
The bridge between conv-land and dense-land
- LAYER_STACK
- LAYER_STACK
Somewhere between your convolutional layers and your final classification head, every CNN has to make the leap from 4D feature maps to a flat vector. In the Neural Network Toolkit that jump is NNT Define Reshape Layer - a one-input node that reshapes the tensor mid-architecture, without touching any weights.
What it actually does
It appends a Reshape entry to your LAYER_STACK with a target_shape. When NntCompileModel builds the model, it wraps this in a tiny custom module that does x.view(batch_size, *target_shape) - so the shape you type is the shape without the batch dimension, which gets prepended automatically. The classic use: a conv block ends at [B, 8, 7, 7], you type [8, 7, 7]... no wait, you type [392] (or [-1, 392]) to flatten it into a vector that a Linear layer can consume. The name is a slight lie in that sense: its most common job is flattening, but because you can type any shape, it also lets you lay tensors out as sequences - [512, 50] - for transformer-ish stacks.
Inputs that matter
Just one:
target_shape- a Python list as a string, e.g.[392]or[8, 7, 7]. The placeholder shows[-1, 8, 7, 7]:-1is allowed for one dimension and means "whatever's left over," which is the safest way to write a reshape when you don't want to count elements by hand.
There's also the optional LAYER_STACK input to keep the chain going, and the LAYER_STACK output that feeds the next node - the same pattern every NNT define node uses.
The one way to get burned
Reshape only rearranges the tensor - the total number of elements has to match exactly, or PyTorch throws a runtime error the moment the compiled model runs. [8, 7, 7] is 392 elements, so [392] and [7, 8, 7] both work and [400] blows up. That error message is usually the whole diagnosis: count your channels and spatial dims again. It's a hard failure at inference time rather than a silent corruption, which is honestly the good outcome - a wrong reshape that didn't error would mean silently shuffled data.
Note this one is fully wired into the compile path in the current version, unlike some of the more exotic layer types in this pack. NNT is a hobby project and the author's own README calls it a work in progress, but reshape is one of the boring, reliable nodes in it.
Installing NNT
Part of inventorado/ComfyUI_NNT. ComfyUI Manager (search "ComfyUI Neural Network Toolkit") is the easy path; manually:
cd ComfyUI/custom_nodes
git clone https://github.com/inventorado/ComfyUI_NNT.git
cd ComfyUI_NNT
pip install -r requirements.txt
Then restart ComfyUI. The dependency list is a heavy one - torch, scikit-learn, pandas, shap, seaborn and friends - so the first install takes a while. The pack's example workflows need ComfyUI-Jjk-Nodes for their text displays; Manager's "Install Missing Custom Nodes" handles that.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| target_shape | STRING | [8,7,7] | — |
| LAYER_STACKopt | LIST | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LAYER_STACK | LIST | — |