It is used to Obtain the memory usage of the CPU and GPU during the running of the program. And this function Current program is time-consuming.
()
| 321 | |
| 322 | |
| 323 | def get_current_memory_mb(): |
| 324 | """ |
| 325 | It is used to Obtain the memory usage of the CPU and GPU during the running of the program. |
| 326 | And this function Current program is time-consuming. |
| 327 | """ |
| 328 | import pynvml |
| 329 | import psutil |
| 330 | import GPUtil |
| 331 | gpu_id = int(os.environ.get('CUDA_VISIBLE_DEVICES', 0)) |
| 332 | |
| 333 | pid = os.getpid() |
| 334 | p = psutil.Process(pid) |
| 335 | info = p.memory_full_info() |
| 336 | cpu_mem = info.uss / 1024. / 1024. |
| 337 | gpu_mem = 0 |
| 338 | gpu_percent = 0 |
| 339 | gpus = GPUtil.getGPUs() |
| 340 | if gpu_id is not None and len(gpus) > 0: |
| 341 | gpu_percent = gpus[gpu_id].load |
| 342 | pynvml.nvmlInit() |
| 343 | handle = pynvml.nvmlDeviceGetHandleByIndex(0) |
| 344 | meminfo = pynvml.nvmlDeviceGetMemoryInfo(handle) |
| 345 | gpu_mem = meminfo.used / 1024. / 1024. |
| 346 | return round(cpu_mem, 4), round(gpu_mem, 4), round(gpu_percent, 4) |
| 347 | |
| 348 | |
| 349 | def multiclass_nms(bboxs, num_classes, match_threshold=0.6, match_metric='iou'): |
no test coverage detected