Ultralytics THOP is a Python library for fast computation of PyTorch model Multiply-Accumulate Operations (MACs) and parameters. It is based on the original `thop` project, maintained by Ultralytics, and provides a robust tool for analyzing the computational cost of deep learning models. The current version is 2.0.18, with a maintenance-focused release cadence.
pip install ultralytics-thopVerified import paths — ran on the pinned version, not inferred.
This example defines a basic convolutional neural network, creates a dummy input tensor, and then uses `thop.profile` to compute its MACs and parameters. `clever_format` is used to make the output human-readable.
Be aware of the distinction when comparing with other profiling tools. The v2.0.16 release explicitly clarified this terminology.
For custom layers or specific non-counted operations, you may need to define and pass `custom_ops` to the `profile` function to ensure comprehensive counting. Consult the `thop` documentation for how to implement custom hooks.
Always profile your model with an input shape representative of its actual use case to get meaningful and accurate performance estimates.