在vs2010 MFC c++代码中需要调用pytorch写的深度学习的代码以获得预测结果;
具体实现方法为:
vs中输出待预测数据,pytorch执行预测结果后写出数据,然后vs重新读取预测数据。
在c++中加入代码段:batpath 为编写好的.bat的路径
HINSTANCE hd; hd = ShellExecute(NULL,"open",batpath, NULL, NULL, SW_SHOW);.bat 内代码为:
cd到pytorch的文件夹下并调用虚拟环境pytorch_gpu下的python.exe 然后执行test.py
cd D:\Pointnet_Pointnet2_pytorch-master\Pointnet_Pointnet2_pytorch-master && C:\Users\Anaconda3\envs\pytorch_gpu\python.exe test_partseg.py echo. & pause此时报错:
D:\PartSeg_PatternImage_testPredicate\PartSeg_PatternImage_SinglePart\PatternImage-Edu\PatternImage>cd D:\Pointnet_Pointnet2_pytorch-master\Pointnet_Pointnet2_pytorch-master && C:\Users\YinghanJin\Anaconda3\envs\pytorch_gpu\python.exe test_partseg.py C:\Users\YinghanJin\Anaconda3\envs\pytorch_gpu\lib\site-packages\numpy\__init__.py:138: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service from . import _distributor_init Traceback (most recent call last): File "C:\Users\YinghanJin\Anaconda3\envs\pytorch_gpu\lib\site-packages\numpy\core\__init__.py", line 22, in <module> from . import multiarray File "C:\Users\YinghanJin\Anaconda3\envs\pytorch_gpu\lib\site-packages\numpy\core\multiarray.py", line 12, in <module> from . import overrides File "C:\Users\YinghanJin\Anaconda3\envs\pytorch_gpu\lib\site-packages\numpy\core\overrides.py", line 7, in <module> from numpy.core._multiarray_umath import ( ImportError: DLL load failed: 找不到指定的模块。 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "test_partseg.py", line 7, in <module> from data_utils.ShapeNetDataLoader import PartNormalDataset File "D:\Pointnet_Pointnet2_pytorch-master\Pointnet_Pointnet2_pytorch-master\data_utils\ShapeNetDataLoader.py", line 5, in <module> import numpy as np File "C:\Users\YinghanJin\Anaconda3\envs\pytorch_gpu\lib\site-packages\numpy\__init__.py", line 140, in <module> from . import core File "C:\Users\YinghanJin\Anaconda3\envs\pytorch_gpu\lib\site-packages\numpy\core\__init__.py", line 48, in <module> raise ImportError(msg) ImportError: IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE! Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed. We have compiled some common reasons and troubleshooting tips at: https://numpy.org/devdocs/user/troubleshooting-importerror.html Please note and check the following: * The Python version is: Python3.6 from "C:\Users\YinghanJin\Anaconda3\envs\pytorch_gpu\python.exe" * The NumPy version is: "1.19.1" and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help. Original error was: DLL load failed: 找不到指定的模块。 D:\Pointnet_Pointnet2_pytorch-master\Pointnet_Pointnet2_pytorch-master>echo. & pause应该是numpy的版本不对造成的。
尝试修改numpy版本
原虚拟环境下的numpy版本为:
修改后为:(安装该版本numpy 参考文章https://www.cnblogs.com/hackpig/p/8110986.html)
再重新运行,成功调用.bat文件,并执行了预测。
