pytorch
深度学习
_卷心菜_
一只努力鸭!
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
多分类问题(mnist数据集)
import torch from torchvision import transforms from torchvision import datasets from torch.utils.data import DataLoader import torch.nn.functional as F import torch.optim as optim batch_size = 64 transform = transforms.Compose([ transforms.ToTensor()原创 2021-05-30 21:01:14 · 371 阅读 · 0 评论 -
加载数据集(糖尿病数据)
import numpy as np import torch from torch.utils.data import Dataset from torch.utils.data import DataLoader ## prepare dataset class DiabetesDataset(Dataset): def __init__(self, filepath): xy = np.loadtxt(filepath, delimiter=',', dtype=np.flo原创 2021-05-29 20:47:14 · 504 阅读 · 0 评论 -
处理多维特征的输入(糖尿病数据)
import numpy as np import torch xy = np.loadtxt('E:/BaiduNetdiskDownload/PyTorch深度学习实践/diabetes.csv.gz', delimiter=',', dtype=np.float32) x_data = torch.from_numpy(xy[:, :-1]) y_data = torch.from_numpy(xy[:, [-1]]) class Model(torch.nn.Mod原创 2021-05-29 18:23:08 · 348 阅读 · 0 评论 -
pytorch实现线性回归
import torch import matplotlib.pyplot as plt ## prepare dataset x_data = torch.Tensor([[1.0], [2.0], [3.0]]) y_data = torch.Tensor([[2.0], [4.0], [6.0]]) ## design model using class class LinearModel(torch.nn.Module): def __init__(self): supe原创 2021-05-29 15:17:11 · 229 阅读 · 0 评论 -
RNN实现MNIST数据集分类
# 1. 加载数据集 import torch import torch.nn as nn import torchvision.transforms as transforms import torchvision.datasets as datasets import torchvision import numpy as np import pandas as pd import matplotlib.pyplot as plt # 2. 下载 mnist 数据集 trainsets = dat原创 2021-05-10 21:43:24 · 1331 阅读 · 0 评论 -
Tensor的算术运算
Tensor的算术运算——加法运算 c = a + b c = torch.add(a,b) a.add(b) a.add_(b) 其中,前三种一样,第四种是对 a 进行了修改。 Tensor的算术运算——减法运算 减法同理 c = a - b c = torch.sub(a,b) a.sub(b) a.sub_(b) Tensor的算术运算——乘法运算 哈达玛积(element wise,对应元素相乘) c = a * b c = torch.mul(a,b) a.mul(b) a.mul_(b)原创 2021-03-02 17:18:54 · 3438 阅读 · 0 评论 -
1-3 Tensor的属性——稀疏的张量的编程实践
张量的存放位置 import torch dev = torch.device("cpu") # 将tensor放置在cpu上,用cpu进行计算 a = torch.tensor([2,2],evice=dev) print(a) 输出:tensor([2, 2]) dev = torch.device("cpu") # 将tensor放置在cpu上,用cpu进行计算 dev = torch.device("cuda") # 存放在cuda上 a = torch.tensor([2,2],原创 2021-03-02 16:08:46 · 608 阅读 · 0 评论 -
1-2 Tensor的属性
Tensor的属性 Tensor的属性——稀疏的张量 torch.sparse_coo_tensor coo类型表示了非零元素的坐标形式 indices = torch.tensor([[0,1,1],[2,0,2]]) # 非零元素的坐标(0,2),(1,0),(1,2) values = torch.tensor([3,4,5],dtype=torch.float32) # 对应非零元素的值3,4,5 x = torch.sparse_coo_tensor(i,v,[2,4]) # 一个 2原创 2021-03-02 11:06:52 · 383 阅读 · 0 评论 -
1-1 Tensor创建编程实例
import torch a = torch.Tensor([[1,2],[3,4]]) print(a) print(a.type()) a = torch.Tensor(2,3) print(a) print(a.type()) '''几种特殊的tensor''' a = torch.ones(2,2) # 全 1 的 tensor print(a) print(a.type()) a = torch.eye(2,2) # 对角线是 1 的 tensor print(a) prin原创 2021-03-02 10:42:41 · 347 阅读 · 0 评论
分享