Submitting the form below will ensure a prompt response from us.
What are FLOPs in Machine Learning? It’s a question every ML enthusiast should ask when evaluating model efficiency. FLOPs, or Floating Point Operations, help you understand the computational power your model consumes — beyond just accuracy and speed.
In machine learning and deep learning, evaluating model performance isn’t limited to accuracy or loss metrics. When it comes to deploying models in production or on edge devices, computational cost matters. That’s where FLOPs come in. FLOPs, or Floating Point Operations, provide a way to measure the computational complexity of a machine learning model.
FLOPs stands for Floating Point Operations. In machine learning, it refers to the number of mathematical operations (like addition, multiplication, etc.) performed using floating-point numbers to process data and make predictions.
For example, a MobileNet model may have significantly fewer FLOPs than a ResNet, making it more suitable for mobile devices.
Calculating FLOPs manually involves breaking down every operation inside a neural network — convolutions, matrix multiplications, activations — and summing them. This gets tedious, especially with deep neural networks.
Instead, you can use tools or libraries depending on your framework.
Let’s use the popular ptflops library to calculate FLOPs for a simple model in PyTorch.
bash
pip install ptflops
python
import torch
import torchvision.models as models
from ptflops import get_model_complexity_info
model = models.resnet18() # Pre-trained ResNet18
with torch.cuda.device(0):
macs, params = get_model_complexity_info(model, (3, 224, 224), as_strings=True,
print_per_layer_stat=True, verbose=True)
print(f"FLOPs: {macs}")
print(f"Parameters: {params}")
makefile
FLOPs: 1.82 GMac
Parameters: 11.69 M
Note: 1 GMac = 1 Giga Multiply-Accumulate operation = ~2 GFLOPs (approx.)
TensorFlow doesn’t have built-in FLOP counters, but you can use tf.profiler or TensorFlow Lite Converter to get FLOPs.
python
import tensorflow as tf
model = tf.keras.applications.MobileNetV2()
model.save('mobilenet.h5')
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
# Write to file
with open('mobilenet.tflite', 'wb') as f:
f.write(tflite_model)
# Use Netron (netron.app) to inspect FLOPs
For accurate FLOP estimation in TensorFlow, many developers use third-party tools like Netron, TensorBoard, or TensorFlow Profiler.
A model may have fewer parameters but more FLOPs if it does more computation with fewer stored weights (and vice versa).
Model | Parameters | FLOPs (Approx.) |
---|---|---|
ResNet-18 | 11.7M | ~1.8 GFLOPs |
MobileNetV2 | 3.4M | ~0.3 GFLOPs |
BERT Base | 110M | ~22 GFLOPs per seq |
GPT-2 (117M) | 117M | ~38 GFLOPs per token |
Let us help you calculate FLOPs and optimize your deep learning models for faster training and deployment across devices.
FLOPs in machine learning provide a vital metric for understanding how computationally intensive a model is. Whether you’re optimizing for mobile apps, edge devices, or cloud deployments, knowing the FLOPs helps you choose or build efficient architectures.
While not a replacement for benchmarking or profiling, FLOPs offer quick insight into how expensive your model is to run. Combine this knowledge with accuracy and latency metrics to make well-informed deployment decisions.
Submitting the form below will ensure a prompt response from us.