faulthandler模块
当我们遇到python解释器崩溃或由于其他未知原因导致无法提供有用的回溯信号时,例如:
模型在训练的时候停止并仅打印:segmentation fault(core dumped)
例如,如果你的程序由于段错误(segfault)或者堆栈溢出而崩溃,那么faulthandler就能提供有用的信息来帮助你找出问题所在。
参考方案:ps -aux | grep python 查看是否有太多进程
排查方法
way1:
python -X faulthandler your_script.py
way2:
利用python3的faulthandler,可定位到出错的代码行
在python代码开头:
import faulthandler
faulthandler.enable()
# 后边正常写你的代码
res = 1 / 0
numpy数据在C++中的读写(cv::mat):
我们将python中的np或tensor数组保存到本地,并传递给C++, 可以采用xml文件的形式存储;
具体方式举例:
#notice how its almost exactly the same, imagine cv2 is the namespace for cv
#in C++, only difference is FILE_STORGE_WRITE is exposed directly in cv2
cv_file = cv2.FileStorage("test.xml", cv2.FILE_STORAGE_WRITE)
# 定义数据
matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
cv_file.write("my_mat", matrix) # “my_mat” 是写入到xml中矩阵的名字
cv_file.release()