From a026133849b724b64fc4794224ee2a2b1c3b8600 Mon Sep 17 00:00:00 2001 From: Feng Wang Date: Thu, 22 Jul 2021 13:54:38 +0800 Subject: [PATCH] fix(utils): change logic of setup_env to provide better feeling (#63) --- yolox/utils/setup_env.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/yolox/utils/setup_env.py b/yolox/utils/setup_env.py index 40847d5a9..d13282ff0 100644 --- a/yolox/utils/setup_env.py +++ b/yolox/utils/setup_env.py @@ -3,7 +3,6 @@ # Copyright (c) 2014-2021 Megvii Inc. All rights reserved. import os -import resource import subprocess import cv2 @@ -28,13 +27,24 @@ def configure_module(ulimit_value=8192): Configure pytorch module environment. setting of ulimit and cv2 will be set. Args: - ulimit_value(int): default open file number on linux. Default value: 4096. + ulimit_value(int): default open file number on linux. Default value: 8192. """ # system setting - rlimit = resource.getrlimit(resource.RLIMIT_NOFILE) - resource.setrlimit(resource.RLIMIT_NOFILE, (ulimit_value, rlimit[1])) + try: + import resource + rlimit = resource.getrlimit(resource.RLIMIT_NOFILE) + resource.setrlimit(resource.RLIMIT_NOFILE, (ulimit_value, rlimit[1])) + except Exception: + # Exception might be raised in Windows OS or rlimit reaches max limit number. + # However, set rlimit value might not be necessary. + pass + # cv2 # multiprocess might be harmful on performance of torch dataloader os.environ["OPENCV_OPENCL_RUNTIME"] = "disabled" - cv2.setNumThreads(0) - cv2.ocl.setUseOpenCL(False) + try: + cv2.setNumThreads(0) + cv2.ocl.setUseOpenCL(False) + except Exception: + # cv2 version mismatch might rasie exceptions. + pass