Configure pytorch module environment. setting of ulimit and cv2 will be set. Args: ulimit_value(int): default open file number on linux. Default value: 8192.
(ulimit_value=8192)
| 23 | |
| 24 | |
| 25 | def configure_module(ulimit_value=8192): |
| 26 | """ |
| 27 | Configure pytorch module environment. setting of ulimit and cv2 will be set. |
| 28 | |
| 29 | Args: |
| 30 | ulimit_value(int): default open file number on linux. Default value: 8192. |
| 31 | """ |
| 32 | # system setting |
| 33 | try: |
| 34 | import resource |
| 35 | |
| 36 | rlimit = resource.getrlimit(resource.RLIMIT_NOFILE) |
| 37 | resource.setrlimit(resource.RLIMIT_NOFILE, (ulimit_value, rlimit[1])) |
| 38 | except Exception: |
| 39 | # Exception might be raised in Windows OS or rlimit reaches max limit number. |
| 40 | # However, set rlimit value might not be necessary. |
| 41 | pass |
| 42 | |
| 43 | # cv2 |
| 44 | # multiprocess might be harmful on performance of torch dataloader |
| 45 | os.environ["OPENCV_OPENCL_RUNTIME"] = "disabled" |
| 46 | try: |
| 47 | cv2.setNumThreads(0) |
| 48 | cv2.ocl.setUseOpenCL(False) |
| 49 | except Exception: |
| 50 | # cv2 version mismatch might rasie exceptions. |
| 51 | pass |