文章分类 -  跟李沐动手学pytorch

上一页 1 2 3 下一页
5.2 模型参数
摘要:5.2.0 头文件 import torch from torch import nn 5.2.1创建一个网络模型 # 通过实例化nn.Sequential来创建一个网络模型,模型包括一个具有8个隐藏单元带有relu激活函数的全连接隐藏层,具有1个输出单元不带激活函数的全连接输出层 net = nn 阅读全文
posted @ 2022-11-08 14:55 yc-limitless
5.1 块
摘要:5.1.0 头文件 import torch from torch import nn from torch.nn import functional as F 5.1.1 通过实例化nn.Sequential来构建网络模型 # 通过实例化nn.Sequential来构建网络模型,该网络模型包含一个 阅读全文
posted @ 2022-11-08 10:28 yc-limitless
4.10 预测房价实战
摘要:4.10.0 头文件 import hashlib import os import tarfile import zipfile import requests import numpy as np import pandas as pd import torch from torch impor 阅读全文
posted @ 2022-11-07 20:43 yc-limitless
4.6 暂退法(dropout)框架实现
摘要:4.6.0 头文件 import torch from torch import nn from d2l import torch as d2l from matplotlib import pyplot as plt 4.6.1 定义损失函数 # 定义交叉熵损失函数 loss = nn.Cross 阅读全文
posted @ 2022-11-06 10:26 yc-limitless
4.6 暂退法(dropout)从零实现
摘要:4.6.0 头文件 import torch from torch import nn from d2l import torch as d2l from matplotlib import pyplot as plt 4.6.1 定义dropout层 def dropout_layer(X, dr 阅读全文
posted @ 2022-11-05 22:09 yc-limitless
4.5 L2正则化框架实现
摘要:4.5.0 头文件 import torch from torch import nn from d2l import torch as d2l from matplotlib import pyplot as plt 4.5.1 制作数据集 # 训练集样本数、测试集样本数、样本维度、批量大小 n_ 阅读全文
posted @ 2022-11-05 19:32 yc-limitless
4.5 L2正则化从零实现
摘要:4.5.0 头文件 import torch from torch import nn from d2l import torch as d2l from matplotlib import pyplot as plt 4.5.1 初始化模型权重和偏移量 # 训练集样本数、测试集样本数、样本维度、批 阅读全文
posted @ 2022-11-05 17:45 yc-limitless
5.6 GPU与张量,GPU与网络模型
摘要:5.6.0 头文件 import torch from torch import nn 5.6.1获取GPU # 获取指定GPU,如果指定编号的GPU存在,则返回gpu(i),否则返回cpu def try_gpu(i=0): if torch.cuda.device_count() >= i + 阅读全文
posted @ 2022-11-04 23:54 yc-limitless
4.4 欠拟合与过拟合
摘要:4.4.0 头文件 import math import numpy as np import torch from torch import nn from d2l import torch as d2l from matplotlib import pyplot as plt 4.4.1利用三阶 阅读全文
posted @ 2022-11-04 23:33 yc-limitless
4.3 多层感知机的框架实现
摘要:4.2.0 头文件 import torch from torch import nn from d2l import torch as d2l from matplotlib import pyplot as plt # 设置批量大小、学习率、训练轮数 batch_size, lr, num_ep 阅读全文
posted @ 2022-11-04 00:10 yc-limitless 阅读(56) 评论(0) 推荐(0)
4.2 从零实现多层感知机
摘要:4.2.0 头文件 import torch from torch import nn from d2l import torch as d2l from matplotlib import pyplot as plt 4.2.1 下载fashion_mnist数据集 # 定义批量大小 batch_ 阅读全文
posted @ 2022-11-03 23:52 yc-limitless
4.1 激活函数
摘要:4.1.0 头文件 import torch from d2l import torch as d2l from matplotlib import pyplot as plt 4.1.1 Relu激活函数 x = torch.arange(-8.0, 8.0, 0.1, requires_grad 阅读全文
posted @ 2022-11-03 23:06 yc-limitless
3.7 softmax回归的框架实现
摘要:3.7.0 头文件 import torch from torch import nn from d2l import torch as d2l from matplotlib import pyplot as plt 3.7.1 下载fashion_mnist数据集 # 定义批量大小 batch_ 阅读全文
posted @ 2022-11-03 22:52 yc-limitless
3.6 softmax回归的从零实现
摘要:3.6.0 头文件 import torch from IPython import display from d2l import torch as d2l from matplotlib import pyplot as plt 3.6.1 训练结果可视化 class Animator: """ 阅读全文
posted @ 2022-11-03 21:21 yc-limitless
3.5 FashionMNIST训练集和测试集
摘要:3.5.0 头文件 import torch import torchvision from torch.utils import data from torchvision import transforms from d2l import torch as d2l from matplotlib 阅读全文
posted @ 2022-11-03 17:34 yc-limitless
3.3 线性回归模型的框架实现
摘要:3.3.0 头文件 import numpy as np import torch from torch.utils import data from d2l import torch as d2l from torch import nn 3.3.1 Dataloader的详细使用说明 from 阅读全文
posted @ 2022-11-02 17:20 yc-limitless
3.2 线性回归模型的从零实现
摘要:3.2.0 头文件 import random import torch from d2l import torch as d2l 3.2.1 关于yield关键字 # 关于yield关键字 def foo(): print("starting...") while True: res = yiel 阅读全文
posted @ 2022-11-01 21:45 yc-limitless
3.1 定时器和矢量化加速
摘要:import math import time import numpy as np import torch from d2l import torch as d2l class Timer: #@save """记录多次运行时间""" def __init__(self): self.times 阅读全文
posted @ 2022-11-01 15:38 yc-limitless
2.4 计算梯度
摘要:2.4.1 计算梯度 import torch x=torch.arange(4.0,requires_grad=True) print(x) # 输出: # tensor([0., 1., 2., 3.], requires_grad=True) y = 2 * torch.dot(x, x) p 阅读全文
posted @ 2022-11-01 15:14 yc-limitless
2.3 线性代数
摘要:2.3.1 头文件 import torch 2.3.2 标量张量的计算 # 定义两个标量 x = torch.tensor(3.0) y = torch.tensor(2.0) # 加法 print(x + y) # 输出: # tensor(5.) # 减法 print(x - y) # 输出: 阅读全文
posted @ 2022-11-01 14:34 yc-limitless

上一页 1 2 3 下一页