Guides

Build a neural network without code and export it to PyTorch

You can design a neural network by connecting layers on a canvas, and still end up with ordinary PyTorch code. This guide builds a small convolutional network for 28×28 images, checks it and exports it, without an account.

What you need

A current browser. Building, checking and exporting work without an account and cost nothing; only saving networks in an account, uploading data and training on the server need a free account. The exported code needs Python and PyTorch on your own machine.

Build the network

Open the editor. On a first visit it shows an example so that there is something to look at; File → New network gives an empty canvas.

  1. Start with an Input

    Drag Input from the palette onto the canvas and set its shape without the batch dimension: 1, 28, 28 for one grayscale channel of 28 × 28 pixels, or 784 for the same image as a flat vector.

  2. Add layers

    Drag Conv2d onto the canvas and connect the right edge of the Input to the left edge of the new layer. With a layer selected, clicking a layer in the palette (or pressing Enter on it) appends the new one after the selected layer and connects them. Continue with Activation (ReLU), MaxPool2d, a second convolution block, Flatten and two Linear layers, the last with 10 outputs.

  3. Set what matters, let Brick DNN fill in the rest

    Select a layer to see its settings. You set what is a design decision, such as out_channels or kernel_size; fields that follow from the incoming tensor, such as in_channels and in_features, are filled in automatically, also after you change an earlier layer.

  4. Read the shapes

    Every layer shows its output shape and parameter count while you build. A mistake is marked in red before anything runs, with a message that says what to change, for example that a kernel is larger than its input. The layers after it have no shape until it is fixed.

A convolutional network in the editor with one Conv2d layer marked red and the message “Kernel size 16 is larger than the (padded) input size 14”; the layers after it show no shape.
A mistake is shown where it happens, with the reason. The layers after it wait for the fix.

Skip connections (Add), merges (Concat) and several inputs work the same way: connect the tensors and the shape inference checks that they fit. Tidy up layout arranges a network that has grown untidy.

Check that it does what you think

The toolbar counts the trainable parameters of the whole network. The inspector of a selected layer explains how its parameters add up and what its receptive field is. How data flows steps one sample through the network, layer by layer, and shows how each layer changes its shape, for example how max pooling turns 32 × 28 × 28 values into 32 × 14 × 14.

The “How data flows” card in the editor follows one sample through a CNN and explains how max pooling halves 32 × 28 × 28 values to 32 × 14 × 14.
How data flows: one sample, one layer at a time.

Export the PyTorch code

Code in the toolbar opens the generated script. It is a self-contained Python file: an nn.Module with one named attribute per layer in __init__ and a forward method in the order of the graph. You can change the class name, and whether the file is a runnable script (a __main__ part that prints the model and runs a random batch through it). For a network with one flat input and one flat output it can also contain a training loop for CSV files. Export .py (Ctrl+E) downloads it.

The code dialog with the generated PyTorch module of a small CNN: the layers in __init__, the forward method, and the options for class name and runnable script.
The code dialog: an nn.Module with named layers, ready to download.

On your machine, python model.py prints the model, the number of trainable parameters and the output shape of a random batch, which should match what the editor showed. The code imports nothing from Brick DNN, so you can change it, put it in a repository or a paper, and train it with your own loop. The example page of this CNN shows the complete script.

Optional: train it on the server

With a free account, Train runs the network on Brick DNN’s server in Switzerland. Choose MNIST, Fashion-MNIST, CIFAR-10, your own CSV file or a ZIP file of images. Brick DNN checks beforehand whether network and data fit, adapts the Input and the last layer if only those differ, and then shows loss and accuracy per epoch. When the run is finished, download the weights (.pt) together with the matching script:

import torch
from model import NeuralNetwork  # the downloaded script

model = NeuralNetwork()
model.load_state_dict(torch.load("model.pt"))
model.eval()
The end of a finished training run with buttons to download the weights, the preprocessing and the script, or to load the network into the editor.
After training: the weights, the preprocessing and the script that fits them.

Keep and share the network

Save as JSON file in the File menu keeps the graph without an account, and Open JSON file brings it back. With an account, networks are saved with their history and can be shared with people or by link and edited together live. The graph format is documented in graph-format.md, and the same networks can be built by an AI assistant over the MCP server.

Examples to start from

  • Small CNN for MNIST

    Two convolution blocks and a classifier head: about 99 % test accuracy on MNIST.

    PyTorch · 421,642 parameters

  • MLP for MNIST

    A multi-layer perceptron: 784 pixel values, two hidden layers, ten class scores.

    PyTorch · 235,146 parameters

  • Residual CNN for CIFAR-10

    A ResNet-style block with a skip connection merged by Add, then global average pooling.

    PyTorch · 76,490 parameters

More guides

Open the editor