重新安装了PyTorch CUDA后运行yolov5的train.py遇到如下报错

【深度学习】OMP Error #15 Initializing libiomp5md.dll, but found libiomp5md.dll already initialized 报错提示完美解决方案

// 本次 opencv、torch、torchvision 都是通过whl文件安装的 可能会导致此问题问题

// 之前使用conda命令在线安装没有遇到这个问题

完整报错提示如下

OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.

进程已结束,退出代码为 3

✨解决方案

解决方案一

import os
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"

把如上代码加在代码最前面

//但是并不能从根本上解决问题

解决方案二

Everything 搜索 libiomp5md.dll

发现有Anaconda目录下存在两个libiomp5md.dll

【深度学习】OMP Error #15 Initializing libiomp5md.dll, but found libiomp5md.dll already initialized 报错提示完美解决方案

【深度学习】OMP Error #15 Initializing libiomp5md.dll, but found libiomp5md.dll already initialized 报错提示完美解决方案

C:\ProgramData\Anaconda3\envs\yolov5-3.1\Library\bin

C:\ProgramData\Anaconda3\envs\yolov5-3.1\Lib\site-packages\torch\lib

第一个路径是conda虚拟环境下的

第二个路径是torch下的

建议先备份路径

然后把第一个路径中的 libiomp5md.dll 剪切到其他地方问题完美解决

✨参考及引用

https://blog.csdn.net/Victor_X/article/details/110082033

⭐转载请注明出处

本文作者:双份浓缩馥芮白

原文链接:https://www.cnblogs.com/Flat-White/p/14678858.html

版权所有,如需转载请注明出处。