文章分类 -  pytorch

张量与GPU、模型与GPU
摘要:import torch from torch import nn print(torch.cuda.is_available()) print(torch.cuda.device_count()) # 获取指定GPU,如果指定编号的GPU存在,则返回gpu(i),否则返回cpu def try_g 阅读全文
posted @ 2022-10-29 12:27 yc-limitless
池化层
摘要:import torch from torch import nn from d2l import torch as d2l # 定义一个池化层的正向传播函数,实现对输入图像的最大池化操作或平均池化操作 def pool2d(X, pool_size, mode='max'): p_h, p_w = 阅读全文
posted @ 2022-10-24 10:52 yc-limitless
卷积层的多输入与多输出通道
摘要:import torch from d2l import torch as d2l # 输入为多个通道,输出为一个通道,将多个通道分别进行卷积再相加 def corr2d_multi_in(X, K): # 先遍历“X”和“K”的第0个维度(通道维度),再把它们加在一起 return sum(d2l 阅读全文
posted @ 2022-10-24 09:55 yc-limitless
卷积层里的填充和步幅
摘要:# import torch # from torch import nn # from d2l import torch as d2l # # 卷积核与图像进行卷积操作 # def corr2d(X, K): # """计算二维互相关运算""" # h, w = K.shape # Y = tor 阅读全文
posted @ 2022-10-23 23:04 yc-limitless
卷积层
摘要:import torch from torch import nn from d2l import torch as d2l # 卷积核与图像进行卷积操作 def corr2d(X, K): """计算二维互相关运算""" h, w = K.shape Y = torch.zeros((X.shap 阅读全文
posted @ 2022-10-23 21:47 yc-limitless
从零实现多层感知机
摘要:import torch from torch import nn from d2l import torch as d2l # 批量大小 batch_size = 256 # 训练集和测试集 train_iter, test_iter = d2l.load_data_fashion_mnist(b 阅读全文
posted @ 2022-10-18 19:30 yc-limitless
从零实现softmax回归
摘要:import torch from IPython import display from d2l import torch as d2l #获取和读取Fashion-MNIST数据集,返回训练集和验证集的数据迭代器 def load_data_fashion_mnist(batch_size, r 阅读全文
posted @ 2022-10-17 19:02 yc-limitless
下载并显示mnist数据集
摘要:import torch import torchvision from torch.utils import data from torchvision import transforms from d2l import torch as d2l from matplotlib import py 阅读全文
posted @ 2022-10-15 16:53 yc-limitless
用pytorch实现线性回归
摘要:import numpy as np import torch from torch.utils import data from d2l import torch as d2l from torch import nn # 定义真实的w系数向量(w1,w2),真是偏移量b = 4.2 true_w 阅读全文
posted @ 2022-10-06 17:04 yc-limitless
从零实现线性回归
摘要:# %matplotlib inline import random import torch from d2l import torch as d2l from matplotlib import pyplot as plt # 构造出一个数据集 # w是真实的权重,b是真实的偏移量,num_ex 阅读全文
posted @ 2022-10-06 16:39 yc-limitless
1.1.1张量的数据类型
摘要:1、什么是张量 在数学中,一个单独的数被称为标量,一列或一行数被称为向量,一个二维数组被称为矩阵,二维以上的数组被称为张量。 在pytorch中,标量、向量、矩阵、更高维的数组被统称为张量。 2、张量的数据类型 在torch中CPU和GPU张量分别有8中数据类型: 3、设置默认数据类型 torch中 阅读全文
posted @ 2022-10-03 21:44 yc-limitless