Implement operator-level flops counting using jit. This is a wrapper of fvcore.nn.flop_count, that supports standard detection models in detectron2. Note: The function runs the input through the model to compute flops. The flops of a detection model is often input-d
(
model: nn.Module, inputs: list, **kwargs
)
| 51 | |
| 52 | |
| 53 | def flop_count_operators( |
| 54 | model: nn.Module, inputs: list, **kwargs |
| 55 | ) -> typing.DefaultDict[str, float]: |
| 56 | """ |
| 57 | Implement operator-level flops counting using jit. |
| 58 | This is a wrapper of fvcore.nn.flop_count, that supports standard detection models |
| 59 | in detectron2. |
| 60 | |
| 61 | Note: |
| 62 | The function runs the input through the model to compute flops. |
| 63 | The flops of a detection model is often input-dependent, for example, |
| 64 | the flops of box & mask head depends on the number of proposals & |
| 65 | the number of detected objects. |
| 66 | Therefore, the flops counting using a single input may not accurately |
| 67 | reflect the computation cost of a model. |
| 68 | |
| 69 | Args: |
| 70 | model: a detectron2 model that takes `list[dict]` as input. |
| 71 | inputs (list[dict]): inputs to model, in detectron2's standard format. |
| 72 | """ |
| 73 | return _wrapper_count_operators(model=model, inputs=inputs, mode=FLOPS_MODE, **kwargs) |
| 74 | |
| 75 | |
| 76 | def activation_count_operators( |