Open
Conversation
|
|
96b9b2a to
3f1c603
Compare
## Motivation
The existing [tools/analysis_tools/get_flops.py](cci:7://file:///home/david/mmdetection/tools/analysis_tools/get_flops.py:0:0-0:0) does not support grounding / vision-language detection models (e.g., GroundingDINO, GroundingCLIP) because these models require text inputs and have multi-modal architectures that cannot be traced end-to-end with `mmengine.analysis.get_model_complexity_info`.
This PR adds a dedicated FLOPs analysis tool that handles the unique architecture of grounding detection models, providing per-component FLOPs and parameter breakdowns.
## Modification
**New file: [tools/analysis_tools/get_flops_grounding.py](cci:7://file:///home/david/mmdetection/tools/analysis_tools/get_flops_grounding.py:0:0-0:0)**
A script that computes per-component FLOPs and parameter counts for grounding detection models:
- **Vision Backbone**: Accurate FLOPs via `fvcore.nn.FlopCountAnalysis`
- **Text Encoder**: Estimated FLOPs based on model type (CLIP, BERT, etc.)
- **Neck (ChannelMapper)**: Estimated from config-driven channel/stride info
- **Transformer Encoder/Decoder**: Estimated from config-driven architecture params
- **Detection Head**: Parameter count
Key design choices:
- Automatically disables `with_cp` (gradient checkpointing) which is incompatible with JIT tracing, without modifying the original config
- Reads architecture parameters (channels, layers, embed_dim, etc.) dynamically from the model config instead of hardcoding
- Uses `MMLogger` consistent with existing mmdet tools
**New file: [tests/test_tools/test_get_flops_grounding.py](cci:7://file:///home/david/mmdetection/tests/test_tools/test_get_flops_grounding.py:0:0-0:0)**
41 unit tests covering all helper functions and config readers.
## BC-breaking
No. This PR only adds new files and does not modify any existing code.
## Use cases
```bash
# Basic usage
python tools/analysis_tools/get_flops_grounding.py \
configs/mm_grounding_dino/grounding_dino_swin-t_finetune_8xb4_20e_cat.py
# Custom input shape
python tools/analysis_tools/get_flops_grounding.py <config> --shape 640 640
# Specify number of classes for text encoder FLOPs estimation
python tools/analysis_tools/get_flops_grounding.py <config> --num-classes 80
9535669 to
3d98616
Compare
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The existing tools/analysis_tools/get_flops.py does not support grounding / vision-language detection models (e.g., GroundingDINO) because these models require text inputs and have multi-modal architectures that cannot be traced end-to-end with
mmengine.analysis.get_model_complexity_info.This PR adds a dedicated FLOPs analysis tool that handles the unique architecture of grounding detection models, providing per-component FLOPs and parameter breakdowns.
Modification
New file: tools/analysis_tools/get_flops_grounding.py
A script that computes per-component FLOPs and parameter counts for grounding detection models:
fvcore.nn.FlopCountAnalysisKey design choices:
with_cp(gradient checkpointing) which is incompatible with JIT tracing, without modifying the original configMMLoggerconsistent with existing mmdet toolsNew file: tests/test_tools/test_get_flops_grounding.py
41 unit tests covering all helper functions and config readers.
BC-breaking
No. This PR only adds new files and does not modify any existing code.
Use cases