深度学习
深度学习相关
一位不愿暴露自己的小可爱
把时间分给睡眠
分给书籍
分给运动
分给花鸟树木和山川湖海
分给你对这个世界的热爱
当你开始做时间的主人
你会感受到平淡生活中
喷涌而出的平静的力量
要永远年轻,永远热爱
展开
-
scipy.linalg.cho_factor的功能
cho_factor原创 2023-03-07 11:42:47 · 653 阅读 · 0 评论 -
安装apex库
python原创 2023-02-27 11:29:22 · 558 阅读 · 0 评论 -
raise ValueError(“Pool is still running“)报错
python原创 2023-02-25 17:01:32 · 1244 阅读 · 0 评论 -
VS2017社区版Community 许可证过期解决方法
vs2017原创 2023-02-03 11:52:41 · 5377 阅读 · 1 评论 -
手撕nms代码
nms代码原创 2022-12-27 11:34:51 · 265 阅读 · 0 评论 -
浅谈SSIM 损失函数计算
https://blog.csdn.net/qq_35914625/article/details/113789903转载 2022-11-16 17:12:46 · 336 阅读 · 0 评论 -
空间金字塔池化SSP的原理及代码实现
SSP原创 2022-10-28 10:24:56 · 641 阅读 · 0 评论 -
RuntimeError: CUDA error: device-side assert triggered [349] CUDA kernel errors might be asynchronou
RuntimeError: CUDA error: device-side assert triggered原创 2022-10-19 11:26:51 · 1307 阅读 · 1 评论 -
tensorboard查看训练中的loss,acc等
tensorboard原创 2022-08-26 14:24:38 · 1904 阅读 · 0 评论 -
超详细的卷积后大小的计算公式
卷积原创 2022-08-20 14:45:10 · 4404 阅读 · 4 评论 -
ValueError: Buffer dtype mismatch, expected ‘int_t‘ but got ‘long long‘
bug解决原创 2022-08-17 15:53:50 · 1928 阅读 · 0 评论 -
anaconda创建虚拟环境报错:An HTTP error occurred when trying to retrieve this URL.
打开C:\Users\用户名下的.condarc文件,更换镜像源如下channels: - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/ - http://mirrors.ustc.edu.cn/anaconda/pkgs/free/ - http://mirrors.tuna.tsinghua转载 2022-05-21 14:49:50 · 384 阅读 · 0 评论 -
mxnet命令行制作rec数据集
# 1) create train.lst using follow commandpython -m mxnet.tools.im2rec --list --recursive train "Your WebFace42M Root"# 2) create train.rec and train.idx using train.lst using following commandpython -m mxnet.tools.im2rec --num-thread 16 --quality 100原创 2022-05-21 12:03:00 · 584 阅读 · 0 评论 -
关于transforms.ToTensor()
代码中,数据的维度是(48,48,3)过了transforms后,进入模型的输入tensor为(1,3,48,48)感觉到很疑惑,transform怎么会改变输入的维度呢,transform = transforms.Compose([ transforms.ColorJitter(0.3, 0, 0, 0), transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])阅读原创 2022-03-24 19:30:23 · 1118 阅读 · 0 评论 -
transforms.ColorJitter(0.3, 0, 0, 0)
pytorch和onnx输出有一点点不一样,按理说应该是严格对齐的仔细对齐了模型前处理,最后定位到差异是其中一个进行了颜色抖动transform = transforms.Compose([ transforms.ColorJitter(0.3, 0, 0, 0), transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])点进去看源码实现,在transform.py里 i原创 2022-02-21 15:13:18 · 3307 阅读 · 0 评论 -
一篇opencv实现双线性插值写的非常详细的博客
传送门啦,原文非常详细:https://www.cnblogs.com/yssongest/p/5303151.html转载 2022-02-20 22:38:25 · 570 阅读 · 0 评论 -
onnx裁剪中间节点
最近有遇到需要将onnx模型的中间节点裁剪掉的情况,mxnet转成的caff模型,预处理(减去均值除以方差的操作)写在了模型结构里,量化时要把预处理层单独拿出来,这个操作有两种方法可以实现,一种可以加载mxnet训练好的模型,去掉预处理后再保存;另一种时直接将onnx中对应的两个预处理节点裁掉,这里写一下第二种方法具体实现import onnx_graphsurgeon as gsimport numpy as npimport onnx# remove preprocessing node#原创 2022-02-13 20:29:07 · 3028 阅读 · 4 评论 -
深度学习中的四种钩子
为了节省显存(内存),pytorch在计算过程中不保存中间变量,包括中间层的特征图和非叶子张量的梯度等。有时对网络进行分析时需要查看或修改这些中间变量,此时就需要注册一个钩子(hook)来导出需要的中间变量。网上介绍这个的有不少,但我看了一圈,多少都有不准确或不易懂的地方,我这里再总结一下,给出实际用法和注意点。hook方法有四种:torch.Tensor.register_hook()torch.nn.Module.register_forward_hook()torch.nn.Module.re原创 2022-01-05 09:12:13 · 722 阅读 · 2 评论 -
python3读取图片并灰度化图片的四种方法
方法一:在使用OpenCV读取图片的同时将图片转换为灰度图: img = cv2.imread(imgfile, cv2.IMREAD_GRAYSCALE) print("cv2.imread(imgfile, cv2.IMREAD_GRAYSCALE)结果如下:") print('大小:{}'.format(img.shape)) print("类型:%s"%type(img)) print(img)方法二:使用OpenCV,先读取图片,然后在转换为灰度图(注意输入图像需为三通道,否则会报错原创 2022-01-04 20:15:31 · 5835 阅读 · 0 评论 -
图片转灰度报错cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
图片转灰度cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)报错如下: img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)cv2.error: OpenCV(4.5.4) d:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.simd_helpers.hpp:92: error: (-2:Unspecified error) in function '__cdecl原创 2022-01-04 17:15:56 · 33598 阅读 · 3 评论 -
pytorch模型微调—只加载预训练模型的某些层
重新定义一个模型结构,其实微调就是去掉原来模型的fc层,新加一个fc linear层,即只加载预训练模型的某些层,不加载如:分类层的参数 if opt.continue_model != '': print(f'loading pretrained model from {opt.continue_model}') pretrained_dict = torch.load(opt.continue_model) model_dict = model.s原创 2021-12-29 14:03:22 · 1994 阅读 · 2 评论 -
loss为nan模型输出nan
最近,在做剪枝,之前没有接触过,用了gate-decorator-pruning工程,是19年的文章了,号称对resnet剪枝效果很好,如下:可以看到文章中提出的GBN,相比其他剪枝方法,在FLOPs降低最多的情况下,同时保持了最高的精度。这里记录一个自己实验过程中的坑,害的我找这个bug找了一天多,呜呜呜问题:模型运行中train阶段,网络的输出logits第一次是正常的 ,第二次就是nan, 再经过loss, accuracy = pack.criterio原创 2021-12-29 11:31:12 · 2047 阅读 · 0 评论 -
torch.addmm(M, mat1, mat2)是怎么计算的
一、函数解释在torch/_C/_VariableFunctions.py的有该定义,意义就是实现一下公式:换句话说,就是需要传入5个参数,mat里的每个元素乘以beta,mat1和mat2进行矩阵乘法(左行乘右列)后再乘以alpha,最后将这2个结果加在一起。但是这样说可能没啥概念,接下来博主为大家写上一段代码,大家就明白了~>>> M=torch.ones(2,3)>>> Mtensor([[1., 1., 1.], [1., 1., 1.原创 2021-12-29 09:08:50 · 2335 阅读 · 0 评论 -
output.topk()函数解读
>>> a=torch.randn((4,6))>>> print(a)tensor([[ 0.7042, 0.2533, 1.1596, -0.7436, 0.5264, 0.2085], [ 0.2641, 0.9683, 0.4469, -1.9215, -0.7564, 1.1776], [ 1.0520, -1.6003, -0.8634, 1.7596, -0.8464, 0.7166],原创 2021-12-21 22:26:09 · 595 阅读 · 0 评论 -
vs2017环境问题
vs2017报错网上的方法全部试过都不行,修改dns网址并刷新还是不管用,重新安装,报错如下,死活一直连不上网,放弃在线安装,改成离线下载安装。博客:https://blog.csdn.net/chinadragon_1981/article/details/79632996超级慢,...原创 2021-12-17 16:52:23 · 723 阅读 · 0 评论 -
nn.PReLU(planes)
PReLU激活函数,内部源码实现def __init__(self, num_parameters: int = 1, init: float = 0.25) -> None: self.num_parameters = num_parameters super(PReLU, self).__init__() self.weight = Parameter(torch.Tensor(num_parameters).fill_(init))def forward(self,原创 2021-12-15 11:10:22 · 2644 阅读 · 0 评论 -
pytorch中的gather函数_
先来看官方文档的解释:Gathers values along an axis specified by dim.For a 3-D tensor the output is specified by:out[i][j][k] = input[index[i][j][k]][j][k] # if dim == 0out[i][j][k] = input[i][index[i][j][k]][k] # if dim == 1out[i][j][k] = input[i][j][index[i][j]转载 2021-12-08 16:05:24 · 116 阅读 · 0 评论 -
明明有内存报错CUDA out of memory
RuntimeError: CUDA out of memory. Tried to allocate 2.42 GiB (GPU 0; 24.00 GiB total capacity; 113.84 MiB already allocated; 21.85 GiB free; 134.00 MiB reserved in total by PyTorch)百度,有人说是运行完python, 没有释放内存,运行nvidia-smi, 查看占用GPU的进程,命令TASKKILL /PID 18620 -原创 2021-12-07 15:49:09 · 1357 阅读 · 0 评论 -
torch.unique()
torch.unique()的功能类似于数学中的集合,就是挑出tensor中的独立不重复元素。这个方法的参数在官方解释文档中有这么几个:torch.unique(input, sorted=True, return_inverse=False, return_counts=False, dim=None)input: 待处理的tensorsorted:是否对返回的无重复张量按照数值进行排列,默认是生序排列的return_inverse: 是否返回原始tensor中的每个元素在这个无重复张量中的索引转载 2021-12-06 16:37:52 · 1068 阅读 · 0 评论 -
PyTorch 如何设置随机数种子使结果可复现
传送门:https://www.w3cschool.cn/article/48798893.html转载 2021-12-02 17:53:57 · 385 阅读 · 0 评论 -
pytorch transforms.Lambda的使用
当想要对图像设置transforms策略时,如:from torchvision import transforms as Tnormalize = T.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])data_transforms = { 'train': T.Compose([ T.RandomResizedCrop(224), # 从图片中心截取 T.RandomHorizontalFlip原创 2021-11-30 17:22:59 · 1237 阅读 · 0 评论 -
torch.nn.Linear()函数
torch.nn.Linear(in_features, out_features, bias=True) 函数是一个线性变换函数:其中,in_features为输入样本的大小,out_features为输出样本的大小,bias默认为true。如果设置bias = false那么该层将不会学习一个加性偏差。Linear()函数通常用于设置网络中的全连接层。import torchx = torch.randn(8, 3) # 输入样本fc = torch.nn.Linear(3, 5) #原创 2021-11-30 08:57:07 · 11929 阅读 · 1 评论 -
mxnet Record IO详解
最近在看识别的代码,还是有许多东西值得学习,比如说分布式训练,数据的读取,由于识别的训练数据量非常大,数据的制作、读取都是非常影响训练速度的,下面先总结一下数据加载读取的部分。首先,当我们需要使用大数据集来训练模型的时候,这时候加载和读取数据就成为了我们训练的瓶颈。而Mxnet提供了一种数据的存储格式ImageRecord,通过这种数据的存储格式可以使用多进程来加载数据,可以极大的提高训练的效率。Mxnet提供了一个mx.recordio模块,可以对ImageRecord文件进行操作,该模块里面包含了两原创 2021-11-27 15:41:06 · 2873 阅读 · 0 评论 -
cv2.LUT()(使用查找表中的值填充输出数组)
def LUT(src, lut, dst=None): # real signature unknown; restored from __doc__ """ LUT(src, lut[, dst]) -> dst . @brief Performs a look-up table transform of an array. 对数组执行查找表转换。 . . The function LUT fills the output array转载 2021-11-27 12:30:05 · 745 阅读 · 0 评论 -
Pytorch分布式训练错误
subprocess.CalledProcessError: Command ‘[’/home/labpos/anaconda3/envs/idr/bin/python’, ‘-u’, ‘main_distribute.py’, ‘–local_rank=1’]’ returned non-zero exit status 1.pytorch DistributedDataParallel训练时遇到的问题RuntimeError: Expected to have finished reduction原创 2021-11-23 21:03:31 · 587 阅读 · 1 评论 -
一篇ViT写的很清楚的博客
传送门:https://www.jianshu.com/p/06a40338dc7c转载 2021-11-22 09:09:18 · 80 阅读 · 0 评论 -
torch.finfo函数
torch.finfotorch.finfo是一个对象,它表示浮点torch.dtype的数字属性。这类似于numpy.finfo,torch.float32,torch.float64,torch.float16.A torch.finfo provides the following attributes: #号后为返回值 max_neg_value0 = torch.finfo(torch.float16).tiny #6.103515625e-05 max_neg_value原创 2021-11-19 18:05:44 · 1985 阅读 · 0 评论 -
png转.bgr二进制图片
在板端推理时,经常会将png图片转成.bgr为后缀的二进制图片,偶尔也需要将.bgr转为png图片查看,这两者之间的互相转换,代码实现如下:import cv2import numpy as npdef png2bgr(): img_path = r'C:\Code\test_qua_detect_img/res.png'.replace('\\', '/') # 原图地址 save_path = 'C:/imgs'+'/'+'res.bgr' # 转成二进制的存储地址原创 2021-11-15 17:20:36 · 3188 阅读 · 0 评论 -
onnx推理时报错RuntimeError: Input must be a list of dictionaries or a single numpy array for input ‘image
onnx推理时报错:RuntimeError: Input must be a list of dictionaries or a single numpy array for input 'images'找到原因啦,onnx输入的字典对应的值应该是numpy类型, 我的代码中是tensor类型,torch.Size([1, 3, 320, 320]) {'images': tensor([[[[-0.9451, -0.9529, -0.9373, ..., -0.1059, -0.1059, -原创 2021-11-10 16:27:51 · 7927 阅读 · 1 评论 -
安装onnxsim
安装onnxsim并不是pip install onnxsim, 这样会报错正确的安装方式:step1、安装onnxsim包pip install onnx-simplifierstep2、加载onnx文件,simplify处理后重新保存,代码如下:from onnxsim import simplifyonnx_model = onnx.load(output_path) # load onnx modelmodel_simp, check = simplify(onnx_model)原创 2021-11-10 15:03:35 · 14344 阅读 · 4 评论