随笔分类 - Python AND Pytorch 琐碎知识
摘要:解释: 以下面代码为例: index = torch.tensor([[2, 1, 0]]) tensor_1 = tensor_0.gather(dim=1, index) print(tensor_1) (1) output.shape = index.shape # 确定最后输出的output
阅读全文
摘要:DropPath 类似于Dropout,不同的是 Drop将深度学习模型中的多分支结构随机 “失效” 而Dropout 是对神经元随机 “失效” DropPath在网络中的应用 假设在前向传播中有如下的代码: x = x + self.drop_path( self.conv(x) ) 那么在dro
阅读全文
摘要:参考链接: https://www.liaoxuefeng.com/wiki/1016959663602400/1017451662295584 https://blog.csdn.net/zhh763984017/article/details/120072425
阅读全文
摘要:import argparse # (1) 声明一个parser parser = argparse.ArgumentParser() # (2) 添加参数 parser.add_argument("parg") # 位置参数,这里表示第一个出现的参数赋值给parg parser.add_argum
阅读全文
摘要:torchvision.transforms.ToTensor() 将numpy的ndarray或PIL.Image读的图片(H,W,C)转换成形状为(C,H, W)的Tensor格式,当然,需要特别注意的是,当使用ToTensor() 将numpy转为Tensor格式时,numpy中的元素必须是u
阅读全文
摘要:Image.open(img_path).convert("RGB") 读出来的图像是RGBA四通道的,A通道为透明通道,该通道值对深度学习模型训练来说暂时用不到,因此使用convert(‘RGB’)进行通道转换
阅读全文
摘要:定义 torch.sort(input,dim,descending) torch.argsort(input,dim,descending) 用法 torch.sort:对输入数据排序,返回两个值,即排序后的数据values和其在原矩阵中的坐标indices torch.argsort:同torc
阅读全文
摘要:形式: torch.max(input) → Tensor 返回输入tensor中所有元素的最大值: a = torch.randn(1, 3) >>0.4729 -0.2266 -0.2085 torch.max(a) #也可以写成a.max() >>0.4729 形式: torch.max(in
阅读全文
摘要:https://pytorch.org/docs/stable/generated/torch.nonzero.html
阅读全文
摘要:None的作用主要是在使用None的位置新增一个维度。 a = np.arange(25).reshape(5,5) print(a) ''' [[ 0 1 2 3 4] [ 5 6 7 8 9] [10 11 12 13 14] [15 16 17 18 19] [20 21 22 23 24]]
阅读全文
摘要:torch.stack():http://www.45fan.com/article.php?aid=1D8JGDik5G49DE1X torch.stack()个人理解:属于先变形再cat的操作,所以在哪个维度上stack,要先把原数据变成相应维度上的值。 例如:x = [1, 2], y = [
阅读全文
摘要:教程链接:https://blog.51cto.com/u_15521344/5056937 注意: 一个SummaryWriter只会在文件夹中生成一个events文件(.add_scalars实际上是多个SummaryWriter) 一个SummaryWriter可以给不同的tag画图,但是画出
阅读全文
摘要:1:https://blog.csdn.net/weixin_39504171/article/details/106356977 2: https://pytorch.org/docs/stable/generated/torch.meshgrid.html
阅读全文
摘要:https://zhuanlan.zhihu.com/p/474153365 torch.repeat 使张量沿着某个维度进行复制, 并且不仅可以复制张量,也可以拓展张量的维度: import torch x = torch.randn(2, 4) # 1. 沿着某个维度复制 x.repeat(1,
阅读全文
摘要:链接:https://blog.csdn.net/yzlh2009/article/details/114118470 情况一,索引数组为整数值 情况二,索引数组为bool值
阅读全文
摘要:原文链接:https://blog.csdn.net/jackandsnow/article/details/103885422
阅读全文