mmdetection如何计算fps
时间: 2024-06-13 17:07:16 浏览: 24
根据提供的引用内容,***etection的fps需要使用get_fps.py文件。具体步骤如下:
1.首先,进入mmdetection的tools/analysis_tools目录下。
2.找到get_fps.py文件并打开。
3.在get_fps.py文件中,可以看到如下代码:
```python
def main():
parser = argparse.ArgumentParser(description='Get FLOPs of a model')
parser.add_argument('config', help='test config file path')
parser.add_argument('checkpoint', help='checkpoint file')
parser.add_argument('--shape', type=int, nargs='+', default=[800], help='input image size')
parser.add_argument('--device', type=str, default='cuda:0', help='device used for FLOPs computation')
args = parser.parse_args()
model = init_detector(args.config, args.checkpoint, device=args.device)
assert hasattr(model, 'forward_dummy'), \
'Customized models must have forward_dummy function for FLOPs computation'
model.eval()
inputs = torch.randn((1, 3) + (args.shape[0],) * 2).to(args.device)
flop, _ = profile(model, inputs)
print('FLOPs: {}'.format(flop))
# Test speed
model_time = Averager()
with torch.no_grad():
for i in range(10):
inputs = torch.randn((1, 3) + (args.shape[0],) * 2).to(args.device)
model_time.tic()
model(inputs)
model_time.toc()
fps = 1 / model_time.avg
print('{} FPS'.format(fps))
```
4.在终端中输入以下命令:
```python
python get_fps.py ${CONFIG_FILE} ${CHECKPOINT_FILE} --shape ${INPUT_SHAPE} --device ${DEVICE}
```
其中,${CONFIG_FILE}是你的模型配置文件的路径,${CHECKPOINT_FILE}是你的模型权重文件的路径,${INPUT_SHAPE}是输入图像的大小,${DEVICE}是计算设备的名称。
例如,如果你的模型配置文件为configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py,权重文件为checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth,输入图像大小为800x800,计算设备为cuda:0,那么你需要在终端中输入以下命令:
```python
python get_fps.py configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth --shape 800 --device cuda:0
```
5.运行命令后,程序会输出模型的FLOPs和FPS。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)