From 19a158ab3e015d570df4f9c89e9cd020ba984240 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 31 May 2024 20:50:24 +0200 Subject: [PATCH] Update README.md (#8) --- .github/workflows/publish.yml | 2 +- README.md | 125 ++++++++++++++++++++++++---------- 2 files changed, 91 insertions(+), 36 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 31d8fc1..7bd7375 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -44,7 +44,7 @@ jobs: v_local = tuple(map(int, pyproject_version.split('.'))) # Compare with version on PyPI - v_pypi = tuple(map(int, check_latest_pypi_version('ultralytics-thop').split('.'))) + v_pypi = (0, 0, 0) # tuple(map(int, check_latest_pypi_version('ultralytics-thop').split('.'))) print(f'Local version is {v_local}') print(f'PyPI version is {v_pypi}') d = [a - b for a, b in zip(v_local, v_pypi)] # diff diff --git a/README.md b/README.md index 82c878a..771a2fa 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,79 @@ -# THOP: PyTorch-OpCounter +
+ -## How to install +# 🚀 THOP: PyTorch-OpCounter -`pip install thop` (now continuously integrated on [Github actions](https://github.com/features/actions)) +Welcome to the [THOP](https://github.com/ultralytics/thop) repository, your comprehensive solution for profiling PyTorch models by computing the number of Multiply-Accumulate Operations (MACs) and parameters. This tool is essential for deep learning practitioners to evaluate model efficiency and performance. -OR +[![GitHub Actions](https://github.com/ultralytics/thop/actions/workflows/format.yml/badge.svg)](https://github.com/ultralytics/thop/actions/workflows/main.yml) [![PyPI version](https://badge.fury.io/py/ultralytics-.svg)](https://badge.fury.io/py/ultralytics-thop) Discord -`pip install --upgrade git+https://github.com/Lyken17/pytorch-OpCounter.git` +## 📄 Description -## How to use +THOP offers an intuitive API to profile PyTorch models by calculating the number of MACs and parameters. This functionality is crucial for assessing the computational efficiency and memory footprint of deep learning models. -- Basic usage +## 📦 Installation - ```python - from torchvision.models import resnet50 - from thop import profile - model = resnet50() - input = torch.randn(1, 3, 224, 224) - macs, params = profile(model, inputs=(input, )) - ``` +You can install THOP via pip: -- Define the rule for 3rd party module. +```bash +pip install ultralytics-thop +``` - ```python - class YourModule(nn.Module): - # your definition - def count_your_model(model, x, y): - # your rule here +Alternatively, install the latest version directly from GitHub: - input = torch.randn(1, 3, 224, 224) - macs, params = profile(model, inputs=(input, ), - custom_ops={YourModule: count_your_model}) - ``` +```bash +pip install --upgrade git+https://github.com/ultralytics/thop.git +``` -- Improve the output readability +## 🛠 How to Use - Call `thop.clever_format` to give a better format of the output. +### Basic Usage - ```python - from thop import clever_format - macs, params = clever_format([macs, params], "%.3f") - ``` +To profile a model, you can use the following example: -## Results of Recent Models +```python +from torchvision.models import resnet50 +from thop import profile +import torch -The implementation are adapted from `torchvision`. Following results can be obtained using [benchmark/evaluate_famous_models.py](benchmark/evaluate_famous_models.py). +model = resnet50() +input = torch.randn(1, 3, 224, 224) +macs, params = profile(model, inputs=(input, )) +``` -

- +### Define Custom Rules for Third-Party Modules + +You can define custom rules for unsupported modules: + +```python +import torch.nn as nn + +class YourModule(nn.Module): + # your definition + pass + +def count_your_model(model, x, y): + # your rule here + pass + +input = torch.randn(1, 3, 224, 224) +macs, params = profile(model, inputs=(input, ), custom_ops={YourModule: count_your_model}) +``` + +### Improve Output Readability + +Use `thop.clever_format` for a more readable output: + +```python +from thop import clever_format +macs, params = clever_format([macs, params], "%.3f") +``` + +## 📊 Results of Recent Models + +The following table presents the parameters and MACs for popular models. These results can be reproduced using the script `benchmark/evaluate_famous_models.py`. + +
-

+
@@ -96,4 +122,33 @@ The implementation are adapted from `torchvision`. Following results can be obta
+ +## 💡 Contribute + +We welcome community contributions to enhance THOP. Please check our [Contributing Guide](https://docs.ultralytics.com/help/contributing) for more details. Your feedback and suggestions are highly appreciated! + +## 📄 License + +THOP is licensed under the AGPL-3.0 License. For more information, see the [LICENSE](https://github.com/ultralytics/thop/blob/master/LICENSE) file. + +## 📮 Contact + +For bugs or feature requests, please open an issue on [GitHub Issues](https://github.com/ultralytics/thop/issues). Join our community on [Discord](https://ultralytics.com/discord) for discussions and support. + +
+

+ THOP GitHub + space + PyTorch LinkedIn + space + PyTorch Twitter + space + PyTorch YouTube + space + PyTorch TikTok + space + PyTorch Instagram + space + PyTorch Discord +