Calculate the floating point operations required for a model's forward pass.
FLOPs (floating point operations) measure the raw compute cost of a layer's forward pass. Each multiply-accumulate is typically counted as 2 FLOPs (one multiply, one add). For a dense layer, FLOPs = 2 × input_dim × output_dim. For a Conv2D layer, the same multiply-add is repeated at every output spatial location, giving FLOPs = 2 × kernel_h × kernel_w × in_channels × out_channels × output_h × output_w. Summing FLOPs across all layers estimates the total compute needed for one forward pass, which is useful for comparing model efficiency and estimating inference latency.
Dense layer FLOPs
FLOPs = 2 * input_dim * output_dim
Conv2D layer FLOPs
FLOPs = 2 * kernel_h * kernel_w * in_channels * out_channels * output_h * output_w
Each multiply-accumulate operation (multiply the inputs, then add to a running sum) is conventionally counted as 2 FLOPs — one for the multiplication and one for the addition.
Parameter count measures the number of learnable weights/biases (memory footprint), while FLOPs measure the number of arithmetic operations to compute one forward pass (compute cost). A layer can have few parameters but many FLOPs if it's applied repeatedly, as with convolutions.
No, this calculates forward-pass FLOPs only. Training FLOPs are commonly approximated as about 3x forward FLOPs (1x forward + 2x backward) — see the Training Time Calculator, which uses a factor of 6x total including both passes.
Sum the FLOPs of every layer in the network's forward pass, using each layer's actual input/output dimensions in sequence.