
pytorch
文章平均质量分 51
冰菓(笑)
希望写一些有质量的东西
展开
-
pytorch 保存模型为onnx
# An example input you would normally provide to your model's forward() methodx = torch.rand(1, 3, 512, 720).float().cuda()input_names = ["inputs"]output_names = ["main_out_rest", "sub1_out_rest", "sub2_out_rest", "sub4_out_rest"]# Export the mode...原创 2020-05-28 15:57:24 · 2052 阅读 · 1 评论 -
pytorch 从头开始faster-rcnn(三):vgg16 (带有网络冻结的写法)
由于pytorch自带了一些网络结构可以直接使用,所以直接调用有的模型,详细的可以查看官方文档:https://pytorch.org/docs/stable/torchvision/models.htmldef decom_vgg16(): if opt.caffe_pretrain: model = vgg16(pretrained=False) ...原创 2018-09-26 15:23:00 · 5514 阅读 · 0 评论 -
pytorch 从头开始faster-rcnn(四):rpn
具体参数可以查看:https://www.cnblogs.com/wangyong/p/8513563.htmlRPN流程:1.每一张图片生成固定数量的锚节点,锚节点个数是最后一次特征图大小,比如说最后一层特征大小为(37,50),所以有37*50个锚节点.锚节点之间的步长为16像素点,这是因为vgg16有4次maxpool,所有图像缩小了16倍,所以步长为16像素。每一个锚节点又生成9个...原创 2018-09-26 19:29:54 · 3518 阅读 · 0 评论 -
pytorch 从头开始faster-rcnn 最后:使用自己的数据集
本文代码是参考github上的simple-faster-rcnn-pytorch:https://github.com/zylhub/simple-faster-rcnn-pytorch由于代码原作者能力太强 ,我太弱了,很多看不懂,所有先提前把使用放上来供大家参考。修改2个地方就可以使用自己的数据集,不过数据集需要制作成voc2007里面的格式。1.将voc_dataset.py和...原创 2018-10-02 21:23:35 · 2588 阅读 · 23 评论 -
pytorch 从头开始YOLOV3(一):COCO数据集准备和读取
YOLOV3是工业上可以用的兼顾速度和准确率的一个深度学习目标检测模型,本系列文章将详细解释该模型的构成和实现,本文代码借鉴:https://github.com/eriklindernoren/PyTorch-YOLOv3YOLOv3: An Incremental Improvement:https://pjreddie.com/media/files/papers/YOLOv3.pdf...原创 2019-02-25 14:33:39 · 16391 阅读 · 14 评论 -
pytorch 从头开始YOLOV3(五):检测
github地址:https://github.com/18150167970/pytorch-yolov3-modifiy预测完,只要读取模型,然后进行预测就ok了.1.读模型# Set up modelmodel = Darknet(opt.model_config_path)model.load_weights(opt.weight_path)model.cuda(...原创 2019-03-05 10:36:44 · 1615 阅读 · 2 评论 -
pytorch 从头开始YOLOV3(四):测试
本文实现了mAP函数,其中计算了精确率(Precision),召回率(Recall)首先需要了解mAP的概念和计算方式.具体原理可以查看:https://www.cnblogs.com/lixiunan/articles/9566627.html https://tarangshah.com/blog/2018-01-27/what-is-map-understanding-the-s...原创 2019-03-05 11:24:13 · 1775 阅读 · 0 评论 -
pytorch 从头开始YOLOV3(二):训练模型
1.基本流程pytorch在训练过程有一个很基本的流程,正常情况下就按这个流程就能够训练模型:1.加载模型,2初始化数据,3.预定义优化器,4.训练 # 模型加载 model = Darknet(opt.model_config_path) # pytroch函数 Module.apply 对所有子模型初始化 # https://pytorch.org/...原创 2019-02-26 10:43:35 · 6593 阅读 · 1 评论 -
pytorch 从头开始YOLOV3(三):训练过程中的真值标签
1.获得真值标签用于计算损失从数据集获得的真值标签为整个样本的标签,而在训练过程中预测的标签是每一个特征图上每一个像素的(x,y,w,h,c),因此需要把对每一个特征图上每一个像素制作相应真值标签.首先,初始化真值标签数组. nB = target.size(0) #batch_size nA = num_anchors #锚点数 nC = num_class...原创 2019-02-26 16:16:56 · 2712 阅读 · 4 评论 -
AttributeError: 'module' object has no attribute 'interpolate'
由于我的pytorch一致安装不了1.0.0以上的版本,所以一直用的是0.4.0,很多更新的函数.AttributeError: 'module' object has no attribute 'interpolate'这个问题上只要把interpolate替换成upsample就可以了....原创 2019-03-19 20:47:57 · 3907 阅读 · 0 评论 -
深度学习:图像扩增方法
一个良好的图像预处理能够有效提升模型的准确率。本文总结了常用的图像预处理方法。常见的模型输入一般为固定大小的图像输入,而数据集中的图像常常是不规则大小的图像,因此,对于大小不规则的图像需要放缩至固定大小,而直接使用resize()函数会使得图像变形,因此需要对图像继续填充后继续放缩。图像大小变化import cv2import numpy as npdef preprocess(...原创 2019-05-03 15:14:00 · 3217 阅读 · 0 评论 -
dropblock 实现
DropBlock: A regularization method for convolutional networksDropBlock 由原本的Dropout的随机丢弃点改变为丢弃整个块,如上图所述。该论文认为随机丢弃的像素点(其实是特征图的一个点)可能会由他附近的点的关联信息所表示出来,这样就起不到原本想要的正则效果,因此直接丢弃一个块。 方法如下 输入大...原创 2018-12-19 10:46:55 · 2769 阅读 · 0 评论 -
focal loss
Focal Loss for Dense Object Detection首先,需要了解交叉熵是怎么工作的: https://blog.youkuaiyun.com/tsyccnh/article/details/79163834本文的核心公式如下:借用上面博客中的概率表:* 猫 青蛙 老鼠 Label 0 1 0 Pred 0.3 ...原创 2018-12-22 15:47:27 · 439 阅读 · 0 评论 -
torchvision.utils.make_grid
torchvision.utilstorchvision.utils.make_grid(tensor, nrow=8, padding=2, normalize=False, range=None, scale_each=False, pad_value=0)[source]Make a grid of images.Parameters: tensor (Tensor...原创 2018-07-25 09:59:31 · 12996 阅读 · 0 评论 -
pytorch
TypeError:pic should be PIL Image or ndarray. Got <type 'numpy.ndarray'>pytorch transforms中的方法每次更改图像只能更改一张,所以放入的图片应该是三维图片(H,W,C)....原创 2018-07-26 17:08:39 · 402 阅读 · 1 评论 -
pytorch 自己的图片数据处理成可以训练的图片类型
为了使用自己的图像数据,需要仿照pytorch数据输入创建新的类,其中数据格式为numpy.ndarray。将自己的图片保存到numpy.ndarray中,然后创建类from torch.utils.data import Datasetimport numpy as npclass Dataset(Dataset): def __init__(self, path_im...原创 2018-07-26 17:17:52 · 2923 阅读 · 4 评论 -
pytorch: DiceLoss MulticlassDiceLoss
pytorch的自定义多类dice_loss 和单类dice_lossimport torchimport torch.nn as nnclass DiceLoss(nn.Module): def __init__(self): super(DiceLoss, self).__init__() def forward(self, input, target): N = t...原创 2018-07-26 19:54:40 · 13931 阅读 · 43 评论 -
pytroch 函数学习
1. tensor=torch.from_numpy(ndarray).将ndarray转化为tensor2 . ndarray =tensor.numpy()将tensor转化为ndarray3. x = torch.zeros(*sizes, out=None, dtype=None, layout=torch.strided, device=None, req...原创 2018-09-16 11:23:33 · 699 阅读 · 0 评论 -
pytorch 工程规范
转载自:https://zhuanlan.zhihu.com/p/29024978这不是一篇PyTorch的入门教程!本文较长,你可能需要花费20分钟才能看懂大部分内容建议在电脑,结合代码阅读本文本指南的配套代码地址: chenyuntc/pytorch-best-practice 在学习某个深度学习框架时,掌握其基本知识和接口固然重要,但如何合理组织代码,使得代码具有良好...转载 2018-09-07 15:44:45 · 1801 阅读 · 0 评论 -
关于pytorch 模型复制的一些问题
直接使用model2=model1会出现当更新model2时,model1的权重也会更新,这和自己的初始目的不同。所有要使用模型复制可以使用如下方法。torch.save(model, "net_params.pkl")model5=Cnn(3,10)model5=torch.load('net_params.pkl')这样编写不会影响原始模型的权重...原创 2018-09-13 19:21:11 · 13245 阅读 · 10 评论 -
pytorch 从头开始faster-rcnn(零):使用到的函数
本篇博客是在写faster-rcnn遇到的没见过的函数,所以这篇博客随着代码的编写不定期更新。1.tqdmtqdm在阿拉伯语中的意思是进展。tqdm可以在长循环中添加一个进度提示信息,用户只需要封装任意的迭代器 tqdm(iterator),是一个快速、扩展性强的进度条工具库。from tqdm import tqdmfrom time import sleepfor i in...原创 2018-09-20 15:09:39 · 1198 阅读 · 0 评论 -
torchnet .meter
原文档:https://github.com/torchnet/torchnetimport torchnettnt.Meter Meters provide a standardized way to measure a range of different measures, which makes it easy to measure a wide range of proper...原创 2018-10-02 15:57:50 · 6965 阅读 · 0 评论 -
SPP: Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Recognition
为了适应不同大小的图片, 该篇论文使用池化层将卷积得到的特征图池化成固定大小例如使用三层池化的SPP采用了三个卷积核大小,卷积核大小为图像大小除以1,4,16,这样就可以获得固定特征大小为1,4,16.然后将特征图累加成长度为21一维特征.最后放入fc,就解决了输入大小不一致的问题 class SPPLayer(nn.Module): def __init__(self...原创 2018-12-21 21:09:49 · 241 阅读 · 0 评论 -
pytorch 读取自己的数据
读取自己数据所使用的transforms方法class torchvision.transforms.CenterCrop(size)将给定的PIL.Image进行中心切割,得到给定的size,size可以是tuple,(target_height, target_width)。size也可以是一个Integer,在这种情况下,切出来的图片的形状是正方形。class torchvisi...原创 2018-07-24 20:00:04 · 2218 阅读 · 0 评论