![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
lowl
这个作者很懒,什么都没留下…
展开
-
pytorch保存模型记录
RuntimeError: Error(s) in loading state_dict情况一:原因:网络结构明显不一致Missing key(s) in state_dict: "weight", "bias". Unexpected key(s) in state_dict: "conv1.weight", "bn1.weight", "bn1.bias", "bn1.running_mean", "bn1.running_var", "bn1.num_batches_track原创 2021-11-11 15:55:28 · 1126 阅读 · 0 评论 -
cuda大坑
问题RuntimeError: No CUDA GPUs are available问题是GPU明明都是可用的!!!!查资料可知:cuda在使用之前要检查是否可用,不检测默认不可用torch.cuda.is_available()原创 2021-09-05 12:15:43 · 1073 阅读 · 0 评论 -
ROS使用Python3
cd catkin_workspacegit clone https://github.com/ros-perception/vision_opencv.git src/vision_opencvcatkin build或者 catkin build cv_bridgeCMake Error at /usr/share/cmake-3.10/Modules/FindBoost.cmake:1947 (message): Unable to find the requested Boost原创 2021-08-12 15:00:43 · 379 阅读 · 0 评论 -
pip3 install question
Traceback (most recent call last): File "/opt/anaconda3/bin/pip3", line 11, in <module> sys.exit(main()) File "/opt/anaconda3/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 73, in main return command.main(cmd_args) File "/原创 2021-08-11 11:09:43 · 305 阅读 · 0 评论 -
Anaconda
安装下载地址bash Anaconda3-2021.05-Linux-x86_64.sh直接执行conda命令出现conda:未找到命令在环境变量文件中加入以下语句,注意修改为自己的安装路径:export PATH=/opt/anaconda3/bin:$PATH设置anaconda为默认Python3删除系统原有python3软链接rm /usr/bin/python3创建新链接到anacondacd /usr/binln -s /opt/anaconda3/bin/py原创 2021-08-06 15:46:42 · 106 阅读 · 0 评论 -
self-attention pytorch实现
Attentionclass Attention(nn.Module): def __init__(self, dim, num_heads=2, qkv_bias=False, qk_scale=None, attn_drop=0., proj_drop=0.): super().__init__() self.num_heads = num_heads head_dim = dim // num_heads self.scale原创 2021-03-18 17:51:21 · 1771 阅读 · 0 评论 -
图像 patch Embedding
import torchimport torch.nn as nnclass PatchEmbed(nn.Module): """ Image to Patch Embedding """ def __init__(self, img_size=224, patch_size=16, in_chans=3, embed_dim=768): super().__init__() img_size = (img_size, img_size)原创 2021-03-18 17:45:44 · 2305 阅读 · 0 评论 -
基于OpenCV-python的图像融合
图像融合一种常见的融合方法是将两张图像进行加权求和,并添加一个gmma值,作为偏移量具体公式为:merge = (image1)*(alpha) + (image2)*(beta) + gamma其中,image1,image2分别为要融合的两张图,alpha,beta分别是两种图像融合时的权重,增大权重可以突出对应图像在融合结果中的明显程度python-opencv方法原型:def addWeighted(src1, alpha, src2, beta, gamma, dst=None, d原创 2020-12-17 15:53:40 · 1327 阅读 · 1 评论 -
python实现图像阴影去除
导入依赖import cv2import numpy as np最大滤波def max_filter(image,filter_size): # padding操作,在最大滤波中需要在原图像周围填充(filter_size//2)个小的数字,一般取-1 # 先生成一个全为-1的矩阵,大小和padding后的图像相同 empty_image = np.full((image.shape[0] + (filter_size // 2) * 2, image.shape[1] +原创 2020-12-17 10:43:39 · 6619 阅读 · 11 评论 -
python装饰器
python中,所谓的装饰器其实是一个函数,这个函数的返回值也是一个函数对象。在装饰器内部,原有函数加装新功能成为新函数后返回给原有的引用装饰器的作用主要是让其他现有函数在不用修改代码的情况下,新增一些功能。这样就可以将一些函数中的通用代码抽取出来进行复用。##无参数装饰器# 这是装饰器函数,参数 func 是被装饰的函数def decorator(function): def wrapper(*args, **kw): # 加装新功能 print('新功能先原创 2020-12-16 14:24:05 · 62 阅读 · 0 评论 -
数据归一化
导入MinMaxScalerfrom sklearn.preprocessing import MinMaxScaler最大最小归一化minMaxScaler = MinMaxScaler()train_data = minMaxScaler.fit_transform(df)原创 2020-09-02 14:32:17 · 234 阅读 · 0 评论 -
python实现训练集和测试集分割
shuffle矩阵合并import numpy as npdef train_test_split(X, y, ratio, seed): assert X.shape[0] == y.shape[0] assert 0.0 <= ratio <= 1.0 if seed: np.random.seed(seed) data=np.hstack((X,y.reshape(X.shape[0],-1))) np.random.shu原创 2020-11-13 15:34:48 · 863 阅读 · 0 评论 -
python实现简单KNN算法
import numpy as npdef KNN_classify(k,X_train,y_train,x): assert k>0 and k<=X_train.shape[0] assert X_train.shape[0]==y_train.shape[0] assert X_train.shape[1]==x.shape[0] def E_distance(v1,v2): return np.sqrt(np.sum((v1-v2)*原创 2020-11-13 11:28:12 · 274 阅读 · 0 评论 -
numpy基础
numpy创建初始数组全0数组import numpy as npndarray = np.zeros(shape=(2,3),dtype=float)print(ndarray)[[0. 0. 0.] [0. 0. 0.]]全1数组import numpy as npndarray = np.ones(shape=(2,3),dtype=float)print(ndarray)[[1. 1. 1.] [1. 1. 1.]]全为自定义数组import numpy as n原创 2020-11-12 17:47:31 · 83 阅读 · 0 评论 -
python3 object of type ‘zip‘ has no len()报错
python3中以下代码报错:training_data = zip(training_inputs, training_results)print(len(training_data ))object of type 'zip' has no len()解决方法在zip的基础上转为list类型training_data = list(zip(training_inputs, training_results))print(len(training_data ))...原创 2020-09-28 17:26:30 · 508 阅读 · 0 评论 -
python3 pickle.load报错
python3中,pickle.load方法时报错:data = pickle.load(f)UnicodeDecodeError: 'ascii' codec can't decode byte 0x90 in position 614: ordinal not in range(128)解决方法改为:data = pickle.load(f,encoding="bytes")原创 2020-09-28 17:06:48 · 1052 阅读 · 0 评论 -
numpy向量堆叠
hstack()hstack函数是对两个向量做水平方向上的堆叠行向量import numpy as npx1=np.random.rand(1,3)print("x1:",x1)x2=np.random.rand(1,3)print("x2:",x2)X=np.hstack((x1,x2))print("X:",X)x1 [[0.94329401 0.11576768 0.0776751 ]]x2 [[0.40474337 0.00161241 0.63968894]]X [原创 2020-09-28 11:48:16 · 1326 阅读 · 0 评论 -
python命令行debug
在有图形界面的操作系统中,借助集成开发工具可以很方便调试python代码,而在命令行下也可以调试python程序不设置断点执行命令python -m pdb test.py常用命令next:单步跳过step:单步进c: 继续执⾏w: 显⽰当前正在执⾏的代码⾏的上下⽂信息a: 打印当前函数的参数列表s: 执⾏当前代码⾏,并停在第⼀个能停的地⽅(相当于单步进⼊)n: 继续执⾏到当前函数的下⼀⾏,或者当前⾏直接返回(单步跳过)设置断点也可以在代码内部设置断点,这样就可以在某些特定行查原创 2020-09-27 10:21:25 · 7724 阅读 · 0 评论 -
python函数不定参
写函数时,预先可能不确定会传入多少个参数,以及传入的方式,这时候可以通过不定参的形式传递例如def test(*args,**kwargs): print("args:",args) print("kwargs:",kwargs)if __name__ == "__main__": test(1,2,3,4,a=5,b=6,c=7)args: (1, 2, 3, 4)kwargs: {'a': 5, 'b': 6, 'c': 7}*args用来接收不命名参数,以元组原创 2020-09-27 10:19:42 · 334 阅读 · 0 评论