![](https://img-blog.csdnimg.cn/20210207141828858.jpg?x-oss-process=image/resize,m_fixed,h_224,w_224)
pytorch基础
文章平均质量分 56
pytorch实战--基础学习
墨理学AI
计算机视觉领域,新晋砖家 ☞
未来可期,欢迎和墨理一起学 AI 》 博主创建了很多CV领域的技术Club,欢迎主页左侧下方,Contact my WeChat;
展开
-
初识 torch.Autograd | 理解pytorch网络训练过程 | 笔记
文章目录Disabling Gradient Tracking 禁止 梯度 跟踪默认情况下,所有具有 requires_grad=True 的张量都在跟踪它们的计算历史并支持梯度计算。但是,在某些情况下我们不需要这样做,例如,当我们训练了模型并且只想将其应用于某些输入数据时,即我们只想通过网络进行前向计算。我们可以通过用 torch.no_grad() 块包围我们的计算代码来停止跟踪计算:There are reasons you might want to disable gradient trackin原创 2021-08-12 15:16:59 · 320 阅读 · 0 评论 -
pytorch中 PIL与tensor、numpy与tensor、base64之间相互转化
整理的 cv、PIL 读取图片,然后 PIL2tensor、Tensor2PILImage、tensor2numpy相互转化的代码,建议直接复制运行,观察输出 :原创 2020-08-11 20:57:08 · 2736 阅读 · 0 评论 -
Tensor与Numpy的转化【numpy与list的转换】
张量和Numpy array数组在CPU上可以共用一块内存区域, 改变其中一个另一个也会随之改变。原创 2021-02-07 18:11:14 · 910 阅读 · 0 评论 -
pytorch 张量的乘积和矩阵乘法
pytorch 张量的乘积和矩阵乘法张量的乘积( tensor 维度需要一致,对应 位置 元素相乘 )tensor = torch.ones(4,4)tensor[:,1] = 2print('tensor:')print(tensor)# 逐个元素相乘结果print(f"tensor.mul(tensor): \n {tensor.mul(tensor)} \n")# 等价写法:print(f"tensor * tensor: \n {tensor * tensor}").原创 2021-02-07 17:53:21 · 3891 阅读 · 0 评论 -
Pytorch 中 tensor 拼接 | torch.cat() 函数
修改 第 1 列 数值为 2# 初始化一个 tensortensor = torch.ones(4,4)tensor[:,1] = 2print(tensor)输出:tensor([[1., 2., 1., 1.], [1., 2., 1., 1.], [1., 2., 1., 1.], [1., 2., 1., 1.]])横向拼接t1 = torch.cat([tensor, tensor, tensor],dim = 1)pri.原创 2021-02-07 16:50:05 · 1322 阅读 · 0 评论 -
Python 中 numpy 和 pytorch 的size、shape 分析
numpy array 类型# -*- coding: utf-8 -*-import torchimport numpy as npa = np.array([[1, 2, 3, 4], [1, 2, 3, 4]])print(len(a))print(a.size)print(a.shape)输出为:28(2, 4)对于 numpy array 来说,shape、size 都是 array 的属性;pytorch tensor 类型tensor = torc.原创 2021-02-07 16:34:58 · 4369 阅读 · 0 评论 -
torch.randn 方法
torch.randn 方法返回一个张量,其中包含来自均值为0、方差为1的正态分布的随机数(也称为标准正态分布)官方文档https://pytorch.org/docs/stable/generated/torch.randn.htmlExample:>>> torch.randn(4)tensor([-2.1436, 0.9966, 2.3426, -0.6366])>>> torch.randn(2, 3)tensor([[ 1.5954,.原创 2021-02-07 14:21:04 · 4421 阅读 · 0 评论 -
torch 知识点收藏 | 只收藏,不重复搬砖 | 持续补充 : torch.max、torch.cat()、tensor.view()
torch 知识点收藏 | 只收藏,不重复搬砖 | 持续补充原创 2020-11-14 09:59:49 · 1112 阅读 · 9 评论