自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(46)
  • 收藏
  • 关注

原创 np.where可对tensor直接操作

if __name__ == '__main__': # pdist = torch.nn.PairwiseDistance() a = torch.tensor([1,2,3,5,6]) b = torch.tensor([1,2,3,4,5]) idx = np.where(a!=b)[0] print(a,b,idx)原因是因为会默认将tensor转换成numpy。当然也可以直接用torch.where实现。...

2022-07-04 11:01:12 373 1

原创 t-SNE可视化将训练样本单独显示

颜色和字体的设计可自行调整

2022-07-04 10:38:34 502

原创 python string转float原来如此简单,集合set的操作,对于动态变化的训练集操作

只需一个float就可以,这样从文件里读取string类型的数据的时候,直接float即可转换。if __name__ == '__main__': a = "0.2" print(float(a) / 10)输出:0.02集合set的操作,对于动态变化的训练集操作有时候训练集一直在变化,比如标签纠正,有些训练样本要增加或者删除,这时候用set集合操作去快速获取非训练样本。import torchif __name__ == '__main__': .

2022-05-28 11:25:50 460

原创 tensor.max,tensor.argmax 使用

max返回的值有两个,values和indexes。argmax返回的只是indexes。import torchimport numpy as npif __name__ == '__main__': a = torch.tensor([[1,2,3], [4,5,6]]) b = a.max(dim=1)[0] c = a.max(dim=1)[1] d = a.argmax(dim=1) b = b.re

2022-05-04 17:20:41 2136

原创 argsort 在numpy和torch中

默认是升序排列,调用ndarray.argsort 或者 tensor.argsort 返回的是index,加负号,将index逆序即可得到降序。import torchimport numpy as npif __name__ == '__main__': b = np.array([[2,3,4,5], [5,6,7,8], [2,2,2,2]]) # increasing order by defau

2022-05-03 09:24:37 1190

原创 np.newaxis,tensor.squeeze(),np.hstack,torch.hstack,torch.cat,tensor.reshape的使用

np.newaxis,tensor.squeeze()的作用比较相似,增加维度。np.hstack,torch.hstack,torch.cat([tensor,tensor],dim=1) 比较相似,连接tensor。import torchimport numpy as npif __name__ == '__main__': print(torch.__version__) # labels = torch.tensor([0, 1, 2, 0, 1, 2, 0, 1,

2022-05-02 17:16:09 703

原创 numpy.testing.assert_array_almost_equal

assert_array_almost_equal(x,y,decimal=6,err_msg=' ',verbose=True)如果x,y不满足一定精度的误差的话,会报错,decimal默认为6。精度的设置是:abs(desired-actual) < 1.5 * 10**(-decimal),而且是逐个元素的比较。如下:import numpy as npfrom numpy.testing import assert_array_almost_equalif __name

2022-04-16 15:55:50 1109

原创 torch.nn.CrossEntropyLoss()

参考:torch.nn.functional 和 torch.nn 去使用softmax,logsoftmax,crossentropy等的区别_LUQC638的博客-CSDN博客参考:softmax + log = logsoftmax, logsoftmax+ nllloss= crossentropy_LUQC638的博客-CSDN博客import torchimport torch.nn as nnimport torch.nn.functional as F# Example of target

2022-04-14 16:45:05 4664 1

原创 Pytorch-geomretic学习笔记 params_count,sparseTensor

params_count(model),model是nn.Module类型的,计算参数的数量。SparseTensor:rom torch_sparse import SparseTensoradj = SparseTensor(row=edge_index[0], col=edge_index[1], value=..., sparse_sizes=(num_nodes, num_nodes))# value is optional and can b

2022-04-12 10:10:19 1598

原创 tqdm.write ,不打断进度条的输出

tqdm和range循环相搭配,如果循环里面有输出,那么每次输出同时输出进度条的推进。如果进度条只想显示一个,和正常的输出分开的话,可以在循环里面用到tqdm.write进行操作。from tqdm import tqdmfrom time import sleepif __name__ == '__main__': for i, j in enumerate(tqdm(range(0,5))): # print(i,j) tqdm.write("{}

2022-04-11 23:32:39 2604

原创 parser.add_argument metavar

metavar 感觉像元变量。使用场景主要是parser.print_help()的时候,positional argument只显示metavar的名字,optional arguments 中,变量名和metavar都会显示。如下。一个optional arguments: --epochs-taken, metavar 是 ‘N’,命名规则:__epochs不合法,前两个必须是中间横线,不能是下划线。而中间的连接线可以是下划线或者中间横线。无论是--epochs-taken 还是--epoch

2022-04-11 21:50:58 2569 1

原创 bool tensor的使用

构建或者生成的bool tensor作为index,可以方便的访问满足特定条件的相关的tensor值。import torchimport numpy as npif __name__ == '__main__': a = torch.range(0,5) print(a) b = range(0,6) print(b) for i in b: print(i) c = torch.tensor([False,True,False,

2022-04-10 22:09:35 2599

原创 torch.backends.cudnn.deterministic = True torch.backends.cudnn.benchmark = False manual_seed控制程序的随机性

cuda 是NVIDIA 针对自家的CPU设计的并行计算的框架,cuDNN是is a GPU-accelerated library of primitives for deep neural networks。是专门针对深度神经网络打造的加速库。cuDNN Archive | NVIDIA Developerhttps://developer.nvidia.com/rdp/cudnn-archivetorch.backends.cudnn.benchmark = FalseReproducib

2022-04-10 10:53:11 3153

原创 Theoretical Analysis of Self-Training with Deep Networks on Unlabeled Data 解读

novelties:统一的理论分析,结合了半监督学习,无监督领域的改编,无监督的学习。作者的分析基于一定的假设:expansion:一个小的数据集会扩展成一个彼此之间大概率相关的集群,同一类的样本之间有比较好的连续性。Separation: 不同的类别的样本邻居之间的重叠最小。作者证明在这两个假设之下,自训练和输入一致性正则会达到比较高的预测准确度,也即作者提出了一个目标函数,会进行输入一致性的正则,会删除那些可能是错误的伪标签。Under a simple and r.

2022-04-06 14:56:18 1538

原创 supervised contrastive learning 解读

SupCon 定义:Clusters of points belonging to the same class are pulled together in embedding space, while simultaneously pushing apart clusters of samples from different classes.novelties:属于同一类的归一化后的特征表示靠得越近越好,不同类的靠的越远越好。并且,一个anchor 样本,具有多个正样本,sel-sup 通

2022-04-03 15:31:17 5250 1

原创 co-learning:learning from noisy labels with self-supervision 解读

co-learning:learning from noisy labels with self-supervision摘要novelties传统方法的limitationsrelated work方法实验摘要受到co-training的启发,作者将supervised learning和self-supervised learning 结合起来。

2022-03-26 12:57:08 2073

原创 Dual Graph: a graph-based method for reasoning about label noise 解读

现有的limitation: 被选择的样本不能利用所有的数据的信息,尤其是标签 被破坏的情况。作者的novelties:DualGraph 捕获了标签之间的structural relations,包括两个level:instance-level,distribution-level。实例层面利用实例的相似性表征样本的类别,分布层面描述每个sample和其他sample的实例相似度分布。通过instance similarity的分布来优化instance-level的关系。训练了两个网络,在r

2022-03-25 20:24:58 2137 1

原创 SELF-TRAINING OF GRAPH NEURAL NETWORKS USING SIMILARITY REFERENCE

作者认为传统的方法只使用了被采样出来的认为是clean的data进行训练,那些没有被sample的数据就没有被利用起来。作者提出了一个基于图的学习框架使得网络能够传播被sample的数据的标签信息到临近的数据(无论是被采样还是没有被采样出来的)。作者提出的self-training的策略利用没有标签也没有被sample的数据,通过使用采样的数据的信息来正则化网络的更新。Introductiondecoupling method认为被两个网络预测为不同的结果的数据反而更有价值。mentornet使用了

2022-03-25 10:17:04 1288

原创 SCI 论文常用词汇 持续更新中。。。

形容词、副词:大量地:ubiquitously,a wide spectrum of, increasingly,可观的:considerable,重度地:heavily,极度:extremely,重要:crucial,易受影响的:be susceptible to,正交的:orthogonal to,动词:减轻:mitigate,alleviate,relieve,利用:leverage,utilize,exploit, resort to介词短语:没有华丽

2022-03-24 18:04:26 1083 2

原创 learning to reweight examples for robust deep learning

deep neural networks can easily overfit to training biases and label noises. In addition to various regularizers, example reweighting algorithms are popular solutions.They propose a novel meta-learning algorithm that learns to assign weights to training

2022-03-21 22:47:33 715

原创 CoDiM: Learning with Noisy Labels via Contrastive Semi-Supervised Learning 解读

Noisy label learning, semi-supervised learning, and contrastive learning are three different strategies for designing learning processes requiring less annotation cost.

2022-03-14 21:58:58 1371

原创 torch_geometric 入门,加载benchmark数据集

来自官网的例子:from torch.nn import Linear, ReLU# from torch_geometric.nn import Sequential, GCNConvimport torchfrom torch_geometric.datasets import Planetoid, TUDatasetfrom torch_scatter import scatter_meanfrom torch_geometric.loader import DataLoader

2022-03-11 22:40:29 719

原创 torch-geometric 大坑(2) conda 和pip安装

自己的Python是conda环境下面的,pip安装后,表明没问题,一运行就报错,还是得用conda的命令,来自pyg官网:https://pytorch-geometric.readthedocs.io/en/latest/notes/installation.htmlhttps://pytorch-geometric.readthedocs.io/en/latest/notes/installation.html结果自己一直用的是pip命令:问题的来源承接上一次安装好torch geo.

2022-03-09 23:24:27 1604

原创 torch.cat

将两个torch tensor拼接,并且维度的数量保持不变,比如原来是二维的两个tensor拼接完了之后仍然是二维的,不会变成三维的。import torchif __name__ == '__main__': a = torch.tensor([[2,3,4], [5,6,7]]) b = torch.tensor(list(range(3))*2).reshape(2,3) c = torch.cat((a,b),dim=1

2022-01-18 21:29:12 963

原创 训练数据集,验证数据集,测试数据集 编号的生成

idx_train, idx_val, idx_test 的生成。import torch,randomimport numpy as npif __name__ == '__main__': idx_train, idx_val,idx_test = [],[],[] idx_train = np.hstack([idx_train, random.sample(list(range(30)), 10)]) others = np.delete(range(30), i

2022-01-18 15:37:59 1027

原创 torch.where,torch.cat

import torchif __name__ == '__main__': x = torch.randn(2,3,dtype=torch.double) print(x) x = torch.where(x>0,x,0.) print(x) y = torch.randn(1,3) print(y) print(torch.cat((x,y),dim=0))torch.where (condition,x,y)三个参数 ,x,y是形.

2022-01-13 17:38:48 240

原创 torch 广播加法

import torchif __name__ == '__main__': a = torch.tensor([[2], [4], [6]]) b = torch.tensor([[1,2,3]]) c = a + b d = a.T + b print(c,d)tensor([[3, 4, 5], [5, 6, 7], [7, 8...

2022-01-13 16:40:15 696

原创 BatchNorm和LayerNorm 简单解释

对于一维的数据,使用BatchNorm1d和LayerNorm,简单的理解,BatchNorm是对所有样本的每一个维度取均值,均方差进行计算。LayerNorm是对每一个样本的所有维度取均值,均方差进行计算。

2022-01-12 12:12:24 1384

原创 pytorch 单机多卡训练模型

单机多卡pytorch训练模型

2022-01-11 21:36:38 476

原创 F.dropout,nn.Dropout的验证使用,参数training,inplace

F.dropout,nn.Dropout的验证使用,参数training,inplace

2022-01-11 11:44:15 6723 1

原创 model.load_state_dict(state_dict)构造模型和预训练模型的结构不一样的情况

预训练的模型可以很好的学到特征,我们想利用预训练的模型再加上分类器,实现分类任务,需要在自己的模型上添加新的层,直接使用 model.load_state_dict(state_dict) 会报错:RuntimeError: Error(s) in loading state_dict for Model: Missing key(s) in state_dict可以逐个的查找自己的模型如果和预训练的模型有相同的参数名称,那么就复制过来,这样就可以避免直接全部加载出现的错误。如果预训练模...

2022-01-10 22:27:34 3457

原创 torch中冻结神经网络参数,加载和删除网络中的结构

预训练好的模型,有些结构需要冻结参数,训练的时候不发生改变 for name, param in model.named_parameters(): # print(name,param.size()) if not (name.startswith('mlp') or name.startswith('predictor')): param.requires_grad = False if name == 'gat.blocks.0.norm1.bi

2022-01-09 21:31:25 1657

原创 torchvision.models 图片任务加载多个模型,比如resnet,vgg,googlenet

torchvision.models 图片任务加载多个模型,比如resnet,vgg,googlenet

2022-01-08 18:09:10 1757

原创 pytorch 中一个变量被detach()后,这个变量生成的其他变量还存在梯度的验证

pytorch 中一个变量被detach()后,这个变量生成的其他变量还存在梯度的验证

2022-01-07 00:23:38 1533

原创 pytorch中cuda的使用,GPU的使用信息查看

cuda的使用,GPU的使用信息查看

2022-01-06 15:33:59 1617

原创 Open Graph Benchmark 数据集加载

图网络数据OGB

2022-01-06 12:40:43 782

原创 计算两个向量之间的距离,分别用nn.InstanceNorm1d 和手动实现

对于通道数只有1,长度为L 的向量,大小是 1*L ,计算这样的两个向量之间的距离,拓展到一个batch 共有n个样本向量,也即向量的大小是 n*1*L , 计算两个batch之间的距离(大小是[-1,1])import torchimport torch.nn as nnfrom torch_geometric.data import DataLoaderdef D1(p,z): norm = nn.InstanceNorm1d(1) p = norm(p) prin

2022-01-06 12:22:57 1398

原创 torch_geometric 的坑

其他必备的包可以和torch_geometric 一起安装:pip install torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f https://data.pyg.org/whl/torch-1.9.0+cu102.html将pytorch和cuda版本替换成自己的版本就好。如果之前没有安装过这些包,应该很顺利就装好了。但如果像我一样,在pycharm里面单独安装的这些包,即使和正

2022-01-04 13:00:38 1926

原创 tensor自身的softmax,log,log_softmax函数

tensor自身的softmax,log,log_softmax函数

2022-01-02 16:20:41 2891

原创 torch.spmm矩阵乘法

Torch.spmm只支持 sparse 在前,dense 在后的矩阵乘法,两个sparse相乘或者dense在前的乘法不支持,当然两个dense矩阵相乘是支持的。import torchif __name__ == '__main__': indices = torch.tensor([[0,1], [0,1]]) values = torch.tensor([2,3]) shape = torch.Size((2,

2022-01-01 19:26:32 8607 6

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除