问题描述
我正在尝试在ubuntu 16.04上构建交叉编译系统,以缩短编译时间。
我已经安装了这些工具并从树莓派pi复制了库,并且肯定有一个简单的“ Hello world”示例效果很好。
当我尝试使用cmake和opencv生成程序时发生了问题。显然,它在主机系统中找不到OpenCVConfig.cmake,因为它仅存在于以下文件夹中的rpi上:
/ usr / local / lib / cmake / opencv4 $
我可以只将/ usr / local / lib / cmake文件夹复制到主机并手动修改库的安装路径吗?
错误消息:
找不到“ OpenCV”提供的软件包配置文件以及任何 以下名称中的一个:
full error list:
Traceback (most recent call last):
File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\frameworks\torch\tensors\interpreters\native.py",line 333,in handle_func_command
cmd,args_,kwargs_,return_args_type=True
File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\generic\frameworks\hook\hook_args.py",line 157,in unwrap_args_from_function
new_args = hook_args(args_)
File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\generic\frameworks\hook\hook_args.py",line 356,in
return lambda x: f(lambdas,x)
File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\generic\frameworks\hook\hook_args.py",line 535,in three_fold
lambdas[1](args_[1],**kwargs),File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\generic\frameworks\hook\hook_args.py",line 331,in
else lambda i: forward_functype(i)
File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\frameworks\torch\hook\hook_args.py",line 30,in
else (_ for _ in ()).throw(PureFrameworkTensorFoundError),File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\frameworks\torch\hook\hook_args.py",syft.exceptions.PureFrameworkTensorFoundError
During handling of the above exception,another exception occurred:
Traceback (most recent call last):
File "",line 1,in
File "B:\tools and software\PyCharm 2020.1\plugins\python\helpers\pydev_pydev_bundle\pydev_umd.py",line 197,in runfile
pydev_imports.execfile(filename,global_vars,local_vars) # execute the script
File "B:\tools and software\PyCharm 2020.1\plugins\python\helpers\pydev_pydev_imps_pydev_execfile.py",line 18,in execfile
exec(compile(contents+"\n",file,'exec'),glob,loc)
File "B:/projects/GRA/FederatedLearningAnalysis/anomaly-detection/PyTroch_singleworker_combined_train_test.py",line 266,in
app.run(main)
File "B:\tools and software\Anaconda\envs\pysyft-pytorch\lib\site-packages\absl\app.py",line 299,in run
run_main(main,args)
File "B:\tools and software\Anaconda\envs\pysyft-pytorch\lib\site-packages\absl\app.py",line 250,in run_main
sys.exit(main(argv))
File "B:/projects/GRA/FederatedLearningAnalysis/anomaly-detection/PyTroch_singleworker_combined_train_test.py",line 261,in main
tr=tr,df_malicIoUs=load_mal_data(),features=features)
File "B:/projects/GRA/FederatedLearningAnalysis/anomaly-detection/PyTroch_singleworker_combined_train_test.py",line 131,in test_with_data
Y_pred = model.predict(torch.from_numpy(X_test_scaled).float())
File "B:/projects/GRA/FederatedLearningAnalysis/anomaly-detection/PyTroch_singleworker_combined_train_test.py",line 204,in predict
x_pred = self.model(x)
File "B:\tools and software\Anaconda\envs\pysyft-pytorch\lib\site-packages\torch\nn\modules\module.py",line 532,in call
result = self.forward(*input,**kwargs)
File "B:/projects/GRA/FederatedLearningAnalysis/anomaly-detection/PyTroch_singleworker_combined_train_test.py",line 183,in forward
x = torch.tanh(self.fc1(x))
File "B:\tools and software\Anaconda\envs\pysyft-pytorch\lib\site-packages\torch\nn\modules\module.py",**kwargs)
File "B:\tools and software\Anaconda\envs\pysyft-pytorch\lib\site-packages\torch\nn\modules\linear.py",line 87,in forward
return F.linear(input,self.weight,self.bias)
File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\generic\frameworks\hook\hook.py",line 336,in overloaded_func
response = handle_func_command(command)
File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\frameworks\torch\tensors\interpreters\native.py",line 343,in handle_func_command
response = new_type.handle_func_command(new_command)
File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\generic\pointers\object_pointer.py",line 213,in handle_func_command
response = owner.send_command(location,cmd_name=cmd,args=args,kwargs_=kwargs_)
File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\workers\base.py",line 626,in send_command
ret_val = self.send_msg(message,location=recipient)
File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\workers\base.py",line 274,in send_msg
bin_response = self.send_msg(bin_message,location)
File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\workers\virtual.py",line 16,in send_msg
return location.recv_msg(message)
File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\workers\virtual.py",line 20,in recv_msg
return self.recv_msg(message)
File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\workers\base.py",line 310,in recv_msg
response = self.message_routertype(msg)
File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\workers\base.py",line 451,in execute_tensor_command
return self.execute_computation_action(cmd.action)
File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\workers\base.py",line 514,in execute_computation_action
response = command(*args,**kwargs)
File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\generic\frameworks\hook\hook.py",line 367,in handle_func_command
response = cls.get_response(cmd,args,kwargs)
File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\frameworks\torch\tensors\interpreters\native.py",line 401,in get_response
response = command_method(*args,**kwargs)
File "B:\tools and software\Anaconda\envs\pysyft-pytorch\lib\site-packages\torch\nn\functional.py",line 1370,in linear
ret = torch.addmm(bias,input,weight.t())
File "C:\Users\OMEGA-Money\AppData\Roaming\Python\python36\site-packages\syft\generic\frameworks\hook\hook.py",**kwargs_)
IndexError: Dimension out of range (expected to be in range of [-1,0],but got 1)
CODE bits:
def predict(self,x):
x = x.send('testing')
self.model.send(x.location)
x_pred = self.model(x)
mse = np.mean(np.power(x.get().data.numpy() - x_pred.get().data.numpy(),2),axis=1)
y_pred = mse > self.threshold
return y_pred.astype(int)
CODE 2:
X_test = df.drop(columns=["malicIoUs"]).values
X_test_scaled = scaler.transform(X_test)
Y_test = df["malicIoUs"]
Y_pred = model.predict(torch.from_numpy(X_test_scaled).float())
将“ OpenCV”的安装前缀添加到CMAKE_PREFIX_PATH或进行设置 “ OpenCV_DIR”到包含上述文件之一的目录。如果是“ OpenCV” 提供单独的开发包或SDK,请确保已 已安装。
我的CMakeLists.txt:
OpenCVConfig.cmake
opencv-config.cmake
解决方法
在您的方案中,您已将软件包安装在自定义位置。
您可以尝试以下操作(来自the cmake manual):
,默认搜索顺序被设计为最特定于 最不特定于常见用例。项目可能会覆盖顺序 通过简单地多次调用命令并使用NO_ * 选项:
find_package (<package> PATHS paths... NO_DEFAULT_PATH)
我建议您通常使用一些cmake选项进行Linux交叉编译:
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_SYSROOT /home/devel/rasp-pi-rootfs)
set(CMAKE_STAGING_PREFIX /home/devel/stage)
set(tools /home/devel/gcc-4.7-linaro-rpi-gnueabihf)
set(CMAKE_C_COMPILER ${tools}/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/arm-linux-gnueabihf-g++)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
请参见link,其中说明了选项
对我来说,一个简单的解决方案是添加以下文件(或编写您自己的文件): https://github.com/opencv/opencv/blob/2f4e38c8313ff313de7c41141d56d945d91f47cf/cmake/OpenCVConfig.cmake
到CmakeLists.txt所在的文件夹“ cmake-modules”,例如:
cmake-modules/FindOpenCV.cmake
然后请添加
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)
在调用find_package(OpenCV)之前
另一种想法,用于快速修复的方法是使用系统变量来表达,在哪里可以找到不同cmake目标的opencv库 在调用cmake之前从commadline调用follwing命令:
export CMAKE_PREFIX_PATH=opencv_installation_folder/build
或
export OpenCV_DIR=opencv_installation_folder/build
或在您的cmake文件中写入
set (OpenCV_DIR /home/cmake/opencv/compiled) #change the path to match your complied directory of opencv
,
我认为您在交叉编译配置中缺少ScrollView
。
将所有交叉编译选项都放入一个所谓的工具链文件中,然后使用set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
另一个选择是从源代码构建OpenCV,因此您不必担心它是否已打包在工具链中。将cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchainfile/raspberrypi.cmake ..
替换为:
find_package