
python
文章平均质量分 53
星月夜语
探索深度学习、计算机视觉的世界,务实中上下而求索。
展开
-
python ---- 图像小波变换DWT
数字图像中,离散小波变换在python中的使用。原创 2023-04-06 17:27:10 · 1690 阅读 · 1 评论 -
多GPU训练,加载模型时报错
一、问题描述多个GPU训练,保存时没有加module ,导致加载模型时报错。正确写法应该如下: # save model if num_gpu == 1: torch.save(model.module.state_dict(), os.path.join(opt.outf, 'net.pth')) else: torch.save(model.state_dict(), os.path.join(...原创 2021-04-02 08:31:53 · 2105 阅读 · 2 评论 -
python画图(标记、marker、设置标记大小、marker符号大全)
初衷本人由于平常写论文需要输出一些结果图,但是苦于在网上搜python画图时,详细的教程非常多,但是就是找不到能马上解决自己问题那一行代码,所以打算写一些适合需求简单的朋友应急用的教程,应急就必须方便搜索,所以我把主要的内容写在了标题,方便大家到主页查找对应的功能,教程里有对应的效果图,方便查看,希望可以帮助到有需要的朋友。说明本教程的效果图是在jupyter notebook完成。教程是接着之前的效果图完成的,对应会有关键代码,完整代码会附在最后设置标记有时候我们...转载 2020-12-19 11:01:15 · 21920 阅读 · 4 评论 -
变分自编码器VAE
论文:Auto-Encoding Variational Bayesgit:AntixK/PyTorch-VAE: A Collection of Variational Autoencoders (VAE) in PyTorch.1、原文作者在深度学习上的实战理论指导2、具体原理框图如下:VAE主要由编码和解码两部分构成,enconde和 decode. 为了实现反向传播,作者使用重参数技巧。它本质上就是在我们常规的自编码器的基础上,对encoder的结果(在VA...原创 2020-12-10 09:18:37 · 321 阅读 · 0 评论 -
decoder JPEG not available”-PIL
pip uninstall Pillowpip install Pillow亲测有效 win10参考:https://stackoverflow.com/questions/22558976/oserror-decoder-jpeg-not-available-on-windows?answertab=votes原创 2020-12-07 12:01:25 · 417 阅读 · 0 评论 -
python 实现cosine annealing strategy
import mathimport matplotlib.pyplot as pltimport torch.optim as optimfrom torchvision.models import resnet18lr_rate = 0.0001model = resnet18(num_classes=10)# T_max = 1000epoch_total = 25epoch_iter = 609warm_up = 800lambda1 = lambda epoch: ...原创 2020-08-04 09:52:58 · 849 阅读 · 0 评论 -
最小二乘法
Python 实现:import numpy as npimport matplotlib.pyplot as plt#定义x、y散点坐标x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14]x = np.array(x)print('x is :\n',x)num = [1,1.1,1.2,1.1,1.0,0.9,1.3,1.8, 1.1,0.9,1.2,1.1,1.3,0.8]y = np.array(num)print('y is :\n',y)#用3..原创 2020-07-25 17:08:29 · 217 阅读 · 0 评论 -
Res2net:多尺度骨干网络结构
《Res2Net: A New Multi-scale Backbone Architecture》来自:南开大学程明明组 论文:https://arxiv.org/abs/1904.01169>多尺度的信息首先一张图片里物体可能有不同的大小,例如沙发和杯子就是不同大小的,第二,必要的上下文信息可能所占的面积要大于物体本身。例如,我们需要根据大桌子的信息来更好的确定桌上的是个杯子或是笔筒。第三点,对细精度分类和语义分割,理解局部,观察不同尺度下的信息是有必要的。...转载 2020-07-24 09:37:37 · 3677 阅读 · 0 评论 -
python h5 图片读写
问题描述: 由于存储的是不同大小的图片:直接使用 h5 存储, 报错如下:TypeError: Object dtype dtype(‘O’) has no native HDF5 equivalent问题原因:h5 无法统一处理不同shape 的数据。应对这种情况,有两种方法:1、散装:将相同维度的数据放在同一个dataset中,即把原始数据拆分成多个dataset存储。PS: 我自己有多少图片,新建了多少个dataset:code:数据写入:import h5p..原创 2020-07-20 15:13:28 · 1056 阅读 · 0 评论 -
Matlab 与python 部分函数说明
1、reshape:python 用法:>> mat = [1:12]mat = 1 2 3 4 5 6 7 8 9 10 11 12>> reshape(mat,[3,4])ans = 1 4 7 10 2 5 8 11 3 6 9 12matlab 用法:A原创 2020-07-15 18:21:46 · 254 阅读 · 0 评论 -
几种卷积
1、常规卷积:需要的参数量:Cin×K×K×Cout2、分组卷积:分组卷积需要的计算量 :Cin×K×K×Cout / g3、深度可分离卷积(Depthwise Separable Convolution):要的计算量:Cin×K×K+Cout×1×13.1 深度可分离卷积的过程而应用深度可分离卷积的过程是①用16个3×3大小的卷积核(1通道)分别与输入的16通道的数据做卷积(这里使用了16个1通道的卷积核,输入数据的每个通道用1个3×3的卷积核卷...原创 2020-07-07 09:23:34 · 693 阅读 · 0 评论 -
python读取 excel文件
安装xlrd 库 xlrd库 官方地址:https://pypi.org/project/xlrd/ pip install xlrd 笔者在安装时使用了 pip3 install xlrd 原因:笔者同时安装了python2 和 python3 如果pip的话会默认将库安装到python2中,python3中不能直接调用。 那么到底是使用pip 还是pip3进行安装呢? 如果系统中只安装了Python2,那么就只能使用pip。 如果系统中只安装了Pytho转载 2020-07-05 18:46:24 · 535 阅读 · 0 评论 -
pytorch float object has no attribute backward
一、问题描述 编写自己的loss 函数时, loss.backward() 在反向传播一会后,就报错:'float' object has no attribute 'backward'二、原因: 报错的原因是output,也就是损失函数这里输出了int值。但是在实验过程中,梯度确实是下下降了。只是总是在下降过程中出现了这种报错。三、解决办法:def my loss(input): loss = np.sum(input)/len(input) return ...原创 2020-06-08 21:38:34 · 12619 阅读 · 4 评论 -
tensorflow2.x 报错 Could not load dynamic library cudnn64_7.dll
<p>前往官网下载所需得 cuddn 补丁:<a href="https://developer.nvidia.com/rdp/cudnn-download#a-collapse765-101">戳我</a></p>之后将文件全部复制到相应得中,即可。测试获取 gpu:import tensorflow as tftf.debugging.set_log_device_placement(True)gpu...转载 2020-06-06 17:14:25 · 5727 阅读 · 0 评论 -
Tensorboard 报错 Duplicate plugins for name
一、现象 :tensorflow下启动tensorboard后提示: "Duplicate plugins for name %s" % plugin.plugin_nameValueError: Duplicate plugins for name projector二、解决办法:打开 anaconda安装后对应的终端prompt执行:pip list ,查看是否安装了 tb-lightly ,若有则卸载: pip uninstall tb-light...原创 2020-06-06 10:34:39 · 2095 阅读 · 1 评论 -
SVM之matlab与python对比测试
python 下与matlab下SVM 使用结果对比:1、matlab测试code: scores_train = ones(28,1)*0.8 scores_train(1,1)=6 scores_train(2,1)=4 score_size= size(scores_train) D=ones(28,5)*0.2 scores_train svm_model = svmt.原创 2020-05-28 08:42:33 · 935 阅读 · 0 评论 -
PIL 图片操作
一、图片显示from PIL import Imageimport matplotlib.pyplot as pltimg = Image.open('./ww.jpg')plt.figure("ww")plt.imshow(img)plt.show()二、图片保存:img.save('d:/ww.jpg')原创 2020-05-18 09:23:35 · 283 阅读 · 0 评论 -
pytorch--transforms.RandomChoice 使用code
import numpy as npfrom sklearn.model_selection import StratifiedShuffleSplitimport PILfrom torchvision import transformsfrom transforms import *from PIL import Imageimport matplotlib.pyplot...原创 2020-05-01 16:48:19 · 3251 阅读 · 0 评论 -
win10 下GeForce 940MX + CUDA10.0 +pytorch环境配置
前言: 笔记本显卡是硬伤,为了验证GPU上跑的代码的正确性。就想着利用下笔记本上的显卡:具体步骤:1、确定自己的显卡是否支持CUDA 打开英伟达官网找到CUDA-Enabled GeForce Products寻找有没有自己对应的显卡型号,如果有才能下载。2、安装CUDA进入CUDA下载链接,根据电脑的属性点击。下载完成后点击安装即可。我下载的是10...原创 2020-04-17 18:38:45 · 9736 阅读 · 4 评论 -
CS231n-模型参数初始化--Weight Initialization
一、模型初始化from torch.nn import init#define the initial function to init the layer's parameters for the networkdef weigth_init(m): if isinstance(m, nn.Conv2d): init.xavier_uniform_(m.weig...原创 2020-04-11 18:57:42 · 400 阅读 · 0 评论 -
Python编程:方差、标准差、均方差、均方根值、均方误差、均方根误差
python实现代码# -*- coding: utf-8 -*-import mathdef get_average(records): """ 平均值 """ return sum(records) / len(records)def get_variance(records): """ 方差 反映一个数据集的离散程度...转载 2020-04-08 21:02:00 · 4050 阅读 · 0 评论 -
pytorch中的L2和L1正则化,自定义优化器设置等操作
在pytorch中进行L2正则化,最直接的方式可以直接用优化器自带的weight_decay选项指定权值衰减率,相当于L2正则化中的λ \lambdaλ,也就是:中的λ \lambdaλ。但是有一个问题就是,这个指定的权值衰减是会对网络中的所有参数,包括权值w ww和偏置b bb同时进行的,很多时候如果对b bb进行L2正则化将会导致严重的欠拟合1,因此这个时候一般只需要对权值进行正则即可,...原创 2020-04-01 17:26:06 · 4676 阅读 · 2 评论 -
RuntimeError: Expected object of scalar type Double but got scalar type Float for argument #3 'mat1'
pytorch 在model 送入数据时,总是报错,提示是数据类型的问题,正确做法是noise_img_rgb.float() Tensor 后面添加 float()即可++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++补充:Pytorch的数据类型为各式各样...原创 2020-03-31 20:10:14 · 6617 阅读 · 0 评论 -
python中PIL.Image和OpenCV图像格式相互转换
PIL.Image转换成OpenCV格式import cv2from PIL import Imageimport numpy image = Image.open("plane.jpg")image.show()img = cv2.cvtColor(numpy.asarray(image),cv2.COLOR_RGB2BGR)cv2.imshow("OpenCV",img)...转载 2020-03-17 16:45:24 · 355 阅读 · 0 评论 -
标准化后的图像保存
import torch as timport cv2from torchvision import transforms as Timport torchvision as tvfrom PIL import Imageimport numpy as npimg_reals_path='./test_croped/temp_img/48.3.png'o...原创 2020-03-17 16:31:06 · 643 阅读 · 0 评论 -
batch_size 的设置
batchsize过小:每次计算的梯度不稳定,引起训练的震荡比较大,很难收敛。batchsize过大:(1)提高了内存利用率,大矩阵乘法并行计算效率提高。(2)计算的梯度方向比较准,引起的训练的震荡比较小。(3)跑完一次epoch所需要的迭代次数变小,相同数据量的数据处理速度加快。缺点:容易内容溢出,想要达到相同精度,epoch会越来越大,容易陷入局部最优,泛化性能差。...转载 2020-03-08 11:34:23 · 2805 阅读 · 0 评论 -
python RuntimeError:cannot join current thread
一、问题提出在运行程序的时候老是会报错RuntimeError:cannot join current thread二、问题解决定位到你安装的tqdm包,一般都是安装在site-packages/tqdm中,然后找到_monitor.py文件,打开在以下内容中做出修改from threading import Event,Thread,current_thread #第一行...原创 2020-02-25 13:04:23 · 4372 阅读 · 1 评论 -
python之文件基本操作
一、本文核心 介绍python中文件的基本操作。二、正文 1、文件夹的新建和删除 if not isExists: # 如果不存在则创建目录 # 创建目录操作函数 os.makedirs(self.temp_dir) #os.remove(self.temp_dir) ...原创 2020-02-22 10:48:38 · 239 阅读 · 0 评论 -
pytorch学习笔记:fine-tune 预训练的模型
一、主旨torchvision 中包含了很多预训练好的模型,这样就使得 fine-tune 非常容易。本文主要介绍如何 fine-tune torchvision 中预训练好的模型。二、安装pip install torchvision三、如何 fine-tune以 resnet18 为例:from torchvision import modelsfrom t...转载 2020-02-22 09:44:15 · 1608 阅读 · 0 评论 -
python:urllib.error.URLError: urlopen error [SSL: CERTIFICATE_VERIFY_FAILED]
一、问题描述fine_tune 时提示如下:urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) 产生这个问题的原因在于python本身,pyhon升级到2.7.9以后,引入了一个新特性,当使用urll...原创 2020-02-22 09:30:40 · 4848 阅读 · 0 评论 -
visdom:Downloading scripts, this may take a little while
一、问题描述晚上尝试执行了多次:python -m visdom.server总是卡在如下提示中: ioloop.install() # Needs to happen before any tornado imports!Checking for scripts.Downloading scripts, this may take a little while晚...原创 2020-02-22 06:57:10 · 4362 阅读 · 2 评论 -
Conv2d卷积层到Linear全连接层之间的变换——解决方法2(核心)
一、本文问题阐述 记录 Conv2 卷积层 到全链接层之间参数设置报错问题的解决办法: 开始阶段全链接层1参数设置为: self.fc1 = nn.Linear(16*5*5, 120) 运行时报错:RuntimeError: shape '[-1, 1024]' is invalid for input of size 512 ...原创 2020-02-11 17:58:13 · 5125 阅读 · 0 评论 -
pytorch之'tensorboardx' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
一、问题描述注:使用pycharm 编译环境当查看 最终loss曲线时,提示'tensorboard ' 不是内部或外部命令,也不是可运行的程序 或批处理文件。如下:二、问题解决1、安装对应包定位问题在 tensorflow 没有安装,打开AnacondaPrompt 命令窗口 输入:(1、conda create --name tensorflo...原创 2020-02-09 16:23:04 · 8748 阅读 · 8 评论 -
Module Not Found Error: No module named 'torch'
1、pycharm 测试代码:import torchprint(torch.__version__)print(torch.cuda.is_available())x = torch.randn(1)if torch.cuda.is_available(): device = torch.device("cuda") y = torch.ones_like(x,...原创 2020-02-08 16:09:19 · 2054 阅读 · 0 评论