
Python相关学习
晓理紫
天行健,君子以自强不息
地势坤,君子以厚德载物
展开
-
cyclonedds编译与使用(python版本的subscriber与C++版本的publisher)
【代码】cyclonedds编译与使用(python版本的subscriber与C++版本的publisher)原创 2024-07-16 15:52:42 · 1212 阅读 · 1 评论 -
解决在分布式训练时报出But your machine only has: [0]错误
程序可见的显卡数目只有一个,其中可能就是只有一张卡;或者有多张卡但是程序只能看到一个。只检测到一张GPU卡,程序却要使用两张。针对第二个原因只需要设置一下。程序就可以看到多张卡了。原创 2024-03-26 12:14:16 · 1045 阅读 · 0 评论 -
解决openai调用出现的valueerror: unknown scheme for proxy url url(‘socks://127.0.0.1:7890/‘)
我使用openai的接口进行调用时,在代码文件中设置了代理如下。如果有all_proxy的设置,使用下面命令设置为空就行。看看有没有出现下面的all_proxy的设置。使用下面命令查看系统的代理设置。原创 2024-03-14 22:13:22 · 6498 阅读 · 4 评论 -
Python调用C++接口传入并返回图像和其他参数(有框架代码)
使用C++部署一个深度学习网络,并通过fastAPI对外提供服务。深度学习网络需要输入要推理的图像,最终返回推理结果和处理后的图像原创 2024-01-09 08:15:36 · 611 阅读 · 0 评论 -
解决pip 安装 pyhash错误
解决pip 安装 pyhash错误原创 2023-11-08 17:10:33 · 1547 阅读 · 1 评论 -
解决ModuleNotFoundError: No module named ‘pip._vendor.retrying‘问题
解决ModuleNotFoundError: No module named 'pip._vendor.retrying'问题原创 2023-10-25 09:35:28 · 2821 阅读 · 0 评论 -
ERROR:Could not build wheels for pycocotools,which is required to install pyproject.toml-based proje
解决安装pycocotools错误原创 2023-08-09 17:29:09 · 2191 阅读 · 0 评论 -
利用pybind11进行C++与Python混合编程
编译时会根据python版本生成baxter.cpython-37m-x86_64-linux-gnu.so文件。这里以ROS为列,获取Baxter机器人上方的图片,为了简洁方便看,这里只放头文件和cmake文件。可以把pybind11的lib库拷入到编译目录的lib库中(不是必须,能找到对应.........原创 2022-07-28 10:10:33 · 3974 阅读 · 1 评论 -
error: (-215:Assertion failed) ( (npoints >= 4) ... in function ‘solvePnPGeneric‘
在使用solvePnP函数时可能会报以下错误OpenCV(4.4.0) /tmp/pip-req-build-xgme2194/opencv/modules/calib3d/src/solvepnp.cpp:753: error: (-215:Assertion failed) ( (npoints >= 4) || (npoints == 3 && flags == SOLVEPNP_ITERATIVE && useExtrinsicGuess) ) &&原创 2021-08-22 12:08:27 · 2431 阅读 · 0 评论 -
使用zmq在Python2与Python3之间进行图片传输
zmq安装python3使用命令 python3 -m pip install pyzmqpython2在python2中,由于zmq最新版本不再支持python2,所以要指定版本 python2 -m pip install pyzmq==17.1.3或者先下载 下载地址 在安装图像发布相关信息可以去zmq官网查看,这里之间上代码import zmqimport ioimport cv2context = zmq.Context.instance()socker原创 2021-08-05 10:13:32 · 1066 阅读 · 1 评论 -
error: (-210:Unsupported format or combination of formats) *** ‘ONNXImporter‘
使用opencv加载网络模型时可能遇到一下错误:cv2.error: OpenCV(3.4.8) /io/opencv/modules/dnn/src/onnx/onnx_importer.cpp:57: error: (-210:Unsupported format or combination of formats) Failed to parse onnx model in function 'ONNXImporter'一般是模型的路径出错,可以先检查一下网络模型的路径是否正确...原创 2021-08-02 13:48:56 · 2230 阅读 · 0 评论 -
yolov4在WIDERFACE中训练进行人脸检测、修改WIDERFACE标注格式
1、简介WIDERFACE是香港中文大学资讯工程学系 多媒体实验室 发布的人脸数据集下载连接2、标注格式其有两种标注格式.mat与.txt。由于我只能打开.txt文件。其内容如下0--Parade/0_Parade_marchingband_1_849.jpg1449 330 122 149 0 0 0 0 0 0 0--Parade/0_Parade_Parade_0_904.jpg1361 98 263 339 0 0 0 0 0 0 0--Parade/0_Parade_原创 2021-07-09 23:12:35 · 530 阅读 · 0 评论 -
VOC的xml数据格式与COCO的json的数据格式互转脚本
1、数据格式样本1.1 COCO的json数据格式{"info": {"description": "COCO 2017 Dataset","url": "http://cocodataset.org","version": "1.0","year": 2017,"contributor": "COCO Consortium","date_created": "2017/09/01"},"licenses": [{"url": "http://creativecommons.org/licenses/b原创 2021-03-26 15:00:01 · 386 阅读 · 6 评论 -
把COCO数据集的josn标注转变成VOC数据集xml格式的标注;json数据标注转xml数据标注;把coco数据集json格式转变单张图片对应的xml格式
主要是以目标检测为列进行的COCO数据集json格式样本{"info": {"description": "COCO 2017 Dataset","url": "http://cocodataset.org","version": "1.0","year": 2017,"contributor": "COCO Consortium","date_created": "2017/09/01"},"licenses": [{"url": "http://creativecommons.org/license原创 2020-08-07 17:06:04 · 1186 阅读 · 0 评论 -
_mask.so: undefined symbol: _Py_ZeroStruct 或者cython_bbox.so: undefined symbol: _Py_ZeroStruct
原因在使用Faster RCNN有时会遇到如下错误_mask.so: undefined symbol: _Py_ZeroStruct或者cython_bbox.so: undefined symbol: _Py_ZeroStruct这个主要原因可能是原生成so的python环境与你的python环境不一致。(生成cython_bbox.so的环境是python2而你的环境是python3这样的化就会报错)。解决方法在自己的环境中重新生成对应的so文件生成步骤以我生成so的步骤说下,可原创 2020-07-21 17:04:20 · 999 阅读 · 2 评论 -
ImportError: libSM.so.6: cannot open shared object file: No such file or directory
在centos中使用opencv-python。在进行导入的时候报出如下错误>>> import cv2Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/python3/lib/python3.6/site-packages/cv2/__init__.py", line 3, in <module> from原创 2020-07-19 15:32:56 · 1176 阅读 · 0 评论 -
The necessary bits to build these optional modules were not found: _uuid _bz2 _curse _curses_panel
在安装Python3.7可能遇到如题的错误,只需安装uuid库就可以ubuntu下安装uuid链接库sudo apt-get install uuid-devCentOS yum install libuuid-devel对于以下的问题The necessary bits to build these optional modules were not found:_bz2 _curses _curses_panel_dbm原创 2020-07-10 09:35:56 · 14665 阅读 · 2 评论 -
使用 pyinstaller打包多个python文件的 应用程序 并在执行时报出Failed to execute script pyi_rth_pkgres错误
当时使用pyinstaller对python应用程序进行打包的,执行成功打包的exe应用程序时弹出一个错误提示框。信息如下:Failed to execute script pyi_rth_pkgres或者是其他的模块无法加载。此时可以使用打包时导入模块的方式--hidden-import=pkg_resources.py2_warn下面有个打包多个文件的示例pyinstaller.exe -F -w .\photo_editor.py(主文件) -p .\color_filter.py -p原创 2020-06-09 10:17:38 · 1066 阅读 · 0 评论 -
Etensorflow/stream_executor/cuda/cuda_dnn.cc:329] Could not create cudnn handle: CUDNN_STATUS_INTER
在ubuntu16 GTX2060 cuda10.1中使用tensorflow报出一下错误E tensorflow/stream_executor/cuda/cuda_dnn.cc:329] Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR在网上尝试了很多中方法1、删除缓存(我用没有成功)sudo rm -rf ~/.vn/2、修改cuda版本之类的,太麻烦没有试3、换tensorflow版本之类的。太麻烦没有试4、使原创 2020-05-26 20:53:21 · 3330 阅读 · 5 评论 -
terminate called after throwing an instance of dmlc::Error
在python中使用MxNet时在代码 self.module.bind(data_shapes=[data_name_shape], for_training=False)报出一下错误terminate called after throwing an instance of 'dmlc::Error' what(): [07:08:37] src/storage/storage.cc:119: Compile with USE_CUDA=1原创 2020-05-26 16:04:33 · 3112 阅读 · 0 评论 -
error: PyThreadState {aka struct _ts} has no member named exc_type
在使用Cython时候 可能会报出一下错误_nms_gpu_post.c:5968:19: error: ‘PyThreadState {aka struct _ts}’ has no member named ‘exc_type’ *type = tstate->exc_type;这是因为你使用的Cython的版本与生成.c文件的版本不一致,此时应该使用Cython重新的生成.c文件。但是你会发现你重新生成的时候依然回报错。主要因为当目录中以及有一个相关的.c文件的时候Cython原创 2020-05-24 16:14:17 · 3508 阅读 · 8 评论 -
ImportError: cannot import name imresize from scipy.misc
在Pytorch中使用imresize函数报出如下错误ImportError: cannot import name 'imresize' from 'scipy.misc'imresize函数已被最新的SciPy给弃用。有两个解决方案1、安装Pillow试试pip install Pillow如果安装以后还是报错,则需要使用其他的函数替换imresize2、使用numpy+Pillow库试试from PIL import Imageimport numpy as npnorm_m原创 2020-05-23 16:42:06 · 11682 阅读 · 5 评论 -
运行python 使用tab键报出AttributeError: module readline has no attribute redisplay
在win系统终端运行python,在使用tab键进行伸缩的时候会报出以下错误AttributeError: module 'readline' has no attribute 'redisplay'解决方法:卸载掉pyreadline即可pip uninstall pyreadline原创 2020-05-20 10:22:07 · 2332 阅读 · 0 评论 -
MemoryError: Unable to allocate 6.73 GiB for an array with shape (3000, 3, 448, 448) and data type f
在ubuntu系统上得docker中运行pytorch代码,报出如下错误MemoryError: Unable to allocate 6.73 GiB for an array with shape (3000, 3, 448, 448) and data type float32主要是因为一次开辟得内存过大,此时1、内存过载处理模式cat /proc/sys/vm/overcommit_memory 应该显示是02、切换到root身份并更改处理模式echo 1 > /proc/s原创 2020-05-16 08:28:13 · 8813 阅读 · 0 评论 -
使用百度识图从图片获取内容,再使用百度语音合成与科大讯飞的语音合成把图片内容合成语音进行播放,并使用pyqt5画界面
主要逻辑:使用pyqt5画出界面点击上传图片按钮上传图片(最多16张),点击图片获取图片内容,点击播放按钮获取合成音频并播放。啥都不说,上代码import sysfrom PyQt5.QtWidgets import(QWidget, QGridLayout, QApplication,QLabel,QHBoxLayout,QVBoxLayout,QComboBox,QTextEdit,QPushButton,QSlider,QFileDialog)from PyQt5.QtGui impor原创 2020-05-10 11:27:00 · 559 阅读 · 0 评论 -
Where-are-they-looking-PyTorch 代码Error: Bool value of Tensor with more than one value is ambiguous
在Where-are-they-looking-PyTorch中的utils.py中有一个判断 if temp < best: best = temp报出Error: Bool value of Tensor with more than one value is ambiguous解决方法把getdata.py中的predi...原创 2020-05-07 16:36:48 · 1033 阅读 · 3 评论 -
TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy...
在使用Pytorch时我遇到如下错误TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.出错代码如下 out = out.detach().numpy()如下修改就可以 out = out.detach().cpu().numpy...原创 2020-04-29 15:47:25 · 861 阅读 · 0 评论 -
RuntimeError: CUDA out of memory. Tried to allocate 98.00 MiB (GPU 0; 5.79 GiB total capacity; 4.75
使用pytorch进行训练是报出以下错误RuntimeError: CUDA out of memory. Tried to allocate 98.00 MiB (GPU 0; 5.79 GiB total capacity; 4.75 GiB already allocated; 25.38 MiB free; 4.86 GiB reserved in total by PyTorch)...原创 2020-04-20 16:40:03 · 7625 阅读 · 0 评论 -
visdom 可视化使用
1、安装与更新pip install visdompip install --upgrade visdom2、起服务python -m visdom.server3、使用 viz = visdom.Visdom() for epoch in range(1000): for batchidx, (x, _) in enumerate(mnist_tr...原创 2020-03-09 16:55:15 · 3565 阅读 · 0 评论 -
tf2在import时报出ImportError: DLL load failed: 找不到指定的模块
1、环境win 10python 3.7tf 2.1.0在导入tf时报出一下错误During handling of the above exception, another exception occurred:Traceback (most recent call last): File "G:/动手学习深度学习练习/tf_2/安装.py", line 1, in <...原创 2020-02-24 17:06:37 · 2420 阅读 · 0 评论 -
linux下使用matplotlib绘图报出no display name and no $DISPLAY environment variable错误
在linux终端下没有GUI,使用matplotlib绘图报出如下错误信息_tkinter.TclError: no display name and no $DISPLAY environment variable使用粗暴简单的方法1、在导入pyplot前加入下面两句import matplotlib as mplmpl.use('Agg')再导入import matplot...原创 2020-02-16 17:51:39 · 2052 阅读 · 0 评论 -
Python3中遇到UnicodeEncodeError: 'ascii' codec can't encode characters in ordinal not in range(128)
在python3中遇到如下错误UnicodeEncodeError: 'ascii' codec can't encode characters in ordinal not in range(128)这是编码的问题,在代码中加入如下代码即可import sysimport iodef setup_io(): sys.stdout = sys.__stdout__ = io.T...原创 2020-02-12 17:13:18 · 554 阅读 · 0 评论 -
pytorch实现简单的softmax回归代码
import torchfrom torch import nnfrom torch.nn import initimport numpy as npimport sysfrom collections import OrderedDictimport d2lzh_pytoch as d2limport torchvisionimport torchvision.trans...原创 2020-01-07 15:40:38 · 1343 阅读 · 0 评论 -
使用Pytorch实现简单的线性回归
import torchimport numpy as np#生成数据num_inputs=2num_examples = 1000true_w = [2,-3.4]true_b = 4.2features = torch.tensor(np.random.normal(0,1,(num_examples,num_inputs)),dtype=torch.float)#la...原创 2020-01-03 16:01:31 · 1010 阅读 · 0 评论 -
RuntimeError: Expected object of scalar type Double but got scalar type Float for argument #2 'mat2'
在#线性回归矢量计算def linreg(X,w,b): return torch.mm(X,w)+b报出RuntimeError: Expected object of scalar type Double but got scalar type Float for argument #2 'mat2'错误。其主要原因是第二个参数本应该是double类型,但传过来的是flo...原创 2020-01-02 17:08:51 · 1239 阅读 · 0 评论 -
pybind11 python3导入模块的时候报出undefined symbol: _ZN9cv_bridge8toCvCopyERKN5boost10shared_ptrIKN11sensor_m
使用pybind11把c++代码变成python模块时,成功编译出so文件进行python import导入模块时报出如下错误Traceback (most recent call last): File "<stdin>", line 1, in <module>ImportError: ........./baxter_sheixang/built/baxter...原创 2019-12-23 22:03:35 · 2897 阅读 · 0 评论 -
pip升级后解决Import Error:cannot import name main问题
只需修改一下pip文件sudo gedit /usr/bin/pip将原来的:from pip import mainif __name__ == '__main__': sys.exit(main())改为:from pip import __main__if __name__ == '__main__': sys.exit(__main__._main())...原创 2019-10-26 07:35:24 · 500 阅读 · 0 评论 -
修改pip/conda为国内数据源(如清华源)
网上有很多可用的源 清华:https://pypi.tuna.tsinghua.edu.cn/simple最近使用得比较多并且比较顺手的是清华大学的pip源,它是官网pypi的镜像,每隔5分钟同步一次,地址为 https://pypi.tuna.tsinghua.edu.cn/simple临时使用:可以在使用pip的时候加参数-i https://pypi.tuna.tsinghua.edu...原创 2019-10-25 21:21:37 · 6179 阅读 · 0 评论 -
ubuntu18中pycham无法import 已经安装好的包
把 Inherit global site-packages打上句即可原创 2019-10-18 10:29:48 · 229 阅读 · 0 评论 -
k-近邻分类算法详解以两个使用案例
k-近邻分类算法1.基本思想 存在一个样本数据集(训练数据集),数据集中每一个数据都带有一个标签,即我们知道数据集中每一个数据与所属分类得对应关系。输入没有标签得数据后,将数据得每一个特征与样本数据集中数据对应得特征进行比较,然后算法提取样本集中特征最相近数据(最邻近)得分类标签作为测试数据得分类标签。主要是根据测试数据特征与样本集数据特征得距离来判断,选择距离最近得数据分类标签。2.使用...原创 2019-10-13 19:36:52 · 3766 阅读 · 0 评论