{"id":21716,"library":"ptflops","title":"ptflops","description":"A Flops counter for neural networks in PyTorch. It computes the number of floating point operations (FLOPs) and parameters of a model. The current version is 0.7.5, with a slow release cadence.","status":"active","version":"0.7.5","language":"python","source_language":"en","source_url":"https://github.com/sovrasov/flops-counter.pytorch","tags":["flops","pytorch","neural-networks","profiling"],"install":[{"cmd":"pip install ptflops","lang":"bash","label":"pip"}],"dependencies":[{"reason":"PyTorch is required to define models and run flops computation.","package":"torch","optional":false}],"imports":[{"note":"Old import path (pre-0.7) is deprecated.","wrong":"from ptflops.flops_counter import get_model_complexity_info","symbol":"get_model_complexity_info","correct":"from ptflops import get_model_complexity_info"}],"quickstart":{"code":"import torch\nfrom ptflops import get_model_complexity_info\nimport torchvision.models as models\n\nnet = models.resnet18()\nmacs, params = get_model_complexity_info(net, (3, 224, 224), as_strings=True, print_per_layer_stat=True)\nprint('{:<30}  {:<8}'.format('Computational complexity: ', macs))\nprint('{:<30}  {:<8}'.format('Number of parameters: ', params))","lang":"python","description":"Compute FLOPs and parameters for ResNet-18 with a 224x224 input."},"warnings":[{"fix":"Change import to 'from ptflops import get_model_complexity_info'.","message":"Importing from ptflops.flops_counter directly is deprecated. Use from ptflops import get_model_complexity_info instead.","severity":"deprecated","affected_versions":">=0.7"},{"fix":"Multiply the returned MACs by 2 to get FLOPs if needed.","message":"The function returns MACs (multiply-accumulate operations), not FLOPs. MACs are roughly half of FLOPs.","severity":"gotcha","affected_versions":"all"},{"fix":"Set model.eval() before calling get_model_complexity_info.","message":"For models with batch normalization, the flops count may be inaccurate if the model is not in eval mode.","severity":"gotcha","affected_versions":"all"},{"fix":"Pass input_shape=(3, 224, 224) instead of input_res=224.","message":"The function signature changed in version 0.7. The parameter 'input_res' was removed and replaced with 'input_shape' (tuple).","severity":"breaking","affected_versions":">=0.7"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use: from ptflops import get_model_complexity_info","cause":"Old import path no longer exists after ptflops 0.7.","error":"from ptflops.flops_counter import get_model_complexity_info\nModuleNotFoundError: No module named 'ptflops.flops_counter'"},{"fix":"Replace 'input_res' with 'input_shape' as a tuple, e.g., input_shape=(3, 224, 224).","cause":"The function signature changed in version 0.7, parameter renamed to 'input_shape'.","error":"TypeError: get_model_complexity_info() got an unexpected keyword argument 'input_res'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}