ComfyUI Node

LeNet

The 1998 CNN that still teaches everyone deep learning — now a node

By Cynthia-lxx·Created 2 months ago·Updated 2 days ago· 6
LeNet
    • model
    num_classes10
    lr0.100

    CdlLeNet builds a classic LeNet-5 convolutional network as a ComfyDL model object - no code, just two fields and a wire out. LeNet is the network that made convolutional nets famous back in 1998, and it's still the standard first CNN in every deep learning course, including the Dive into Deep Learning (d2l) book this pack is built on. If your goal is to actually understand a CNN instead of just using one, this is the friendliest place to start: small, fast, and readable.

    The output is a cdlModel - the pack's custom type for a PyTorch nn.Module - which means it wires into ComfyDL's model utilities: Model Info to see the parameter count, Model Forward to run it, Model Save to persist it, and so on. The pack's LeNet Inference example workflow wires exactly that chain: build the net, run a forward pass, and render class probabilities as a bar chart.

    The architecture

    What you get is the textbook LeNet-5 structure:

    • LazyConv2d(6, 5x5, pad 2) → Sigmoid → AvgPool2d(2,2)
    • LazyConv2d(16, 5x5) → Sigmoid → AvgPool2d(2,2)
    • Flatten → LazyLinear(120) → Sigmoid → LazyLinear(84) → Sigmoid → LazyLinear(num_classes)

    The Lazy* modules are the modern torch 2.x trick: they infer their input shape on the first forward pass, so you don't have to tell the node the input resolution up front. Your first Model Forward pass is what "initializes" the network.

    Inputs and output

    Two inputs, one of which is mostly a red herring right now:

    • num_classes - integer, default 10 (matching the Fashion-MNIST demo). Set this to however many classes your task has.
    • lr - float, default 0.1. Here's the honest caveat straight from the source: this field is accepted but currently does nothing - the lr value isn't attached to the network that comes out. It's carried over for symmetry with the d2l textbook signature, but the actual learning rate lives in the pack's optimizer nodes downstream (the SGD-style TorchOps). Don't change lr expecting the model to learn faster; nothing will visibly happen. Where people get burned is assuming it's wired up.

    The single output is model, a cdlModel. From there: Model Info to check the ~61k trainable parameters, Model Forward with a properly normalized 28×28-ish tensor, Model Mode set to eval for inference.

    Installing ComfyDL

    It ships with the pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Cynthia-lxx/ComfyDL
    pip install -r ComfyDL/requirements.txt
    

    Restart ComfyUI. Only dependency beyond ComfyUI's bundled torch/torchvision is matplotlib. ComfyUI Manager users: search "ComfyDL"; if it's not in the built-in list (the pack isn't published to the official registry yet), use Install via Git URL with the repo link.

    Common issues

    The two realistic snags: forgetting that a Lazy net needs one forward pass before it has real shapes (so a "params" readout before the first forward can look incomplete), and feeding it input that doesn't match what you trained for - LeNet on grayscale-ish 28×28 is the classic pairing, and the pack's Image Normalize + Image Resize nodes are how you prep images to match. Also, since the net uses Sigmoid (no BatchNorm, no Dropout), train/eval mode barely matters for this particular model - but it matters a lot for the pack's other, deeper nets.

    Categoryd2l/CV Models

    Inputs (2)

    NameTypeDefaultDescription
    num_classesINT101–1000
    lrFLOAT0.1000.0001–1

    Outputs (1)

    NameTypeDescription
    modelcdlModel