Windows下使用mmrotate1.x中tools/analysis_tools/benchmark.py测试fps报错如下:
Traceback (most recent call last):
File "tools/analysis_tools/benchmark.py", line 133, in <module>
main()
File "tools/analysis_tools/benchmark.py", line 128, in main
benchmark = eval(f'{args.task}_benchmark')(args, cfg, distributed, logger)
File "tools/analysis_tools/benchmark.py", line 72, in inference_benchmark
benchmark = InferenceBenchmark(
File "H:\Anaconda\envs\mmrotate1.x\lib\site-packages\mmdet\utils\benchmark.py", line 161, in __init__
print_process_memory(self._process, self.logger)
File "H:\Anaconda\envs\mmrotate1.x\lib\site-packages\mmdet\utils\benchmark.py", line 53, in print_process_memory
pss_mem = gb_round(memory_full_info.pss)
AttributeError: 'pfullmem' object has no attribute 'pss'
进入"H:\Anaconda\envs\mmrotate1.x\lib\site-packages\mmdet\utils\benchmark.py"文件,将报错处代码的pss改为rss,具体如下
def print_process_memory(p: psutil.Process,
logger: Optional[MMLogger] = None) -> None:
"""print process memory info."""
mem_used = gb_round(psutil.virtual_memory().used)
memory_full_info = p.memory_full_info()
uss_mem = gb_round(memory_full_info.uss)
# pss_mem = gb_round(memory_full_info.pss)
pss_mem = gb_round(memory_full_info.rss) #############
for children in p.children():
child_mem_info = children.memory_full_info()
uss_mem += gb_round(child_mem_info.uss)
# pss_mem += gb_round(child_mem_info.pss)
pss_mem += gb_round(child_mem_info.rss) #############共修改两处
process_count = 1 + len(p.children())
print_log(
f'(GB) mem_used: {mem_used:.2f} | uss: {uss_mem:.2f} | '
f'pss: {pss_mem:.2f} | total_proc: {process_count}', logger)
改完后又会报错:
Traceback (most recent call last):
File "tools/analysis_tools/benchmark.py", line 134, in <module>
main()
File "tools/analysis_tools/benchmark.py", line 129, in main
benchmark = eval(f'{args.task}_benchmark')(args, cfg, distributed, logger)
File "tools/analysis_tools/benchmark.py", line 72, in inference_benchmark
benchmark = InferenceBenchmark(
File "H:\Anaconda\envs\mmrotate1.x\lib\site-packages\mmdet\utils\benchmark.py", line 164, in __init__
self.model = self._init_model(checkpoint, is_fuse_conv_bn)
File "H:\Anaconda\envs\mmrotate1.x\lib\site-packages\mmdet\utils\benchmark.py", line 180, in _init_model
model = MODELS.build(self.cfg.model)
File "H:\Anaconda\envs\mmrotate1.x\lib\site-packages\mmengine\registry\registry.py", line 570, in build
return self.build_func(cfg, *args, **kwargs, registry=self)
File "H:\Anaconda\envs\mmrotate1.x\lib\site-packages\mmengine\registry\build_functions.py", line 232, in build_model_from_cfg
return build_from_cfg(cfg, registry, default_args)
File "H:\Anaconda\envs\mmrotate1.x\lib\site-packages\mmengine\registry\build_functions.py", line 121, in build_from_cfg
obj = obj_cls(**args) # type: ignore
TypeError: __init__() got an unexpected keyword argument 'pretrained'
还是在上面那个文件里,将InferenceBenchmark(BaseBenchmark)类中的这段代码删掉或注释掉。
self.cfg.model.pretrained = None
接着报错:
Traceback (most recent call last):
File "tools/analysis_tools/benchmark.py", line 133, in <module>
main()
File "tools/analysis_tools/benchmark.py", line 129, in main
benchmark.run(args.repeat_num)
File "H:\Anaconda\envs\mmrotate1.x\lib\site-packages\mmdet\utils\benchmark.py", line 100, in run
results.append(self.run_once())
File "H:\Anaconda\envs\mmrotate1.x\lib\site-packages\mmdet\utils\benchmark.py", line 216, in run_once
self.model(data, return_loss=False)
File "H:\Anaconda\envs\mmrotate1.x\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
TypeError: forward() got an unexpected keyword argument 'return_loss'
还是在这个类中,改动def run_once(self)函数中的这段代码
with torch.no_grad():
# self.model(data, return_loss=False) #######把这句改成下句
self.model.test_step(data)
最后运行指令
python tools/analysis_tools/benchmark.py work_dirs/test/config.py --checkpoint work_dirs/test/epoch_120.pth
(mmrotate1.x) PS H:\mmrotate1.x> python tools/analysis_tools/benchmark.py work_dirs/test/config.py --checkpoint work_dirs/test/epoch_120.pth
08/31 16:13:08 - mmengine - INFO - before build:
08/31 16:13:08 - mmengine - INFO - (GB) mem_used: 10.56 | uss: 0.15 | pss: 0.23 | total_proc: 1
Loads checkpoint by local backend from path: work_dirs/test/epoch_120.pth
08/31 16:13:09 - mmengine - INFO - after build:
08/31 16:13:09 - mmengine - INFO - (GB) mem_used: 11.98 | uss: 1.44 | pss: 1.63 | total_proc: 1
08/31 16:13:13 - mmengine - INFO - ==================================
08/31 16:13:13 - mmengine - INFO - Done image [50 /2000], fps: 69.7 img/s, times per image: 14.3 ms/img, cuda memory: 51 MB
08/31 16:13:13 - mmengine - INFO - (GB) mem_used: 13.51 | uss: 2.78 | pss: 3.27 | total_proc: 1
08/31 16:13:15 - mmengine - INFO - ==================================
08/31 16:13:15 - mmengine - INFO - Done image [100/2000], fps: 69.5 img/s, times per image: 14.4 ms/img, cuda memory: 51 MB
08/31 16:13:15 - mmengine - INFO - (GB) mem_used: 13.53 | uss: 2.78 | pss: 3.27 | total_proc: 1
08/31 16:13:16 - mmengine - INFO - ==================================
08/31 16:13:16 - mmengine - INFO - Done image [150/2000], fps: 67.7 img/s, times per image: 14.8 ms/img, cuda memory: 51 MB
08/31 16:13:16 - mmengine - INFO - (GB) mem_used: 13.53 | uss: 2.78 | pss: 3.27 | total_proc: 1
08/31 16:13:17 - mmengine - INFO - ==================================
08/31 16:13:17 - mmengine - INFO - Done image [200/2000], fps: 65.2 img/s, times per image: 15.3 ms/img, cuda memory: 51 MB
08/31 16:13:17 - mmengine - INFO - (GB) mem_used: 13.51 | uss: 2.78 | pss: 3.27 | total_proc: 1
08/31 16:13:18 - mmengine - INFO - ============== Done ==================
08/31 16:13:18 - mmengine - INFO - Overall fps: 65.2 img/s, times per image: 15.3 ms/img
08/31 16:13:18 - mmengine - INFO - cuda memory: 51 MB
08/31 16:13:18 - mmengine - INFO - (GB) mem_used: 13.52 | uss: 2.78 | pss: 3.26 | total_proc: 1
成功计算出fps