[ Pytorch教程 ] 神经网络的基本骨架 torch.nn -Neural Network

https://pytorch.org/docs

torch.nn 是 PyTorch 中构建神经网络的核心模块,它提供了:

  • 🏗️ 神经网络层(全连接、卷积、池化等)

  • 🔧 激活函数(ReLU、Sigmoid、Tanh等)

  • 📦 损失函数(交叉熵、MSE、L1等)

  • 🎯 模型容器(Sequential、ModuleList等)

  • ⚙️ 实用工具(参数初始化、Dropout等)

简单的模型

python 复制代码
import torch
from torch import nn
class Tudui(nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, input):  #override func
        output = input + 1
        return output


tudui = Tudui()
x = torch.tensor(1.0)
output = tudui(x)
print(output)

该模型Tudui继承nn.Module,然后重写函数forward(self, input),通过调用模型实例,实现tensor的加1,输出 tensor(2.)

相关推荐
明月醉窗台1 天前
深度学习(17)YOLO训练中的超参数详解
人工智能·深度学习·yolo
t_hj1 天前
大模型微调
人工智能·python·深度学习
z小猫不吃鱼1 天前
06 ViT 为什么需要大规模数据?从归纳偏置理解 ViT 的训练特点
深度学习·计算机视觉·cnn
nebula-AI1 天前
人工智能导论:模型与算法(核心技术)
人工智能·深度学习·神经网络·算法·机器学习·集成学习·sklearn
数智工坊1 天前
视觉-语言-动作模型解剖学:从模块、里程碑到核心挑战
论文阅读·人工智能·深度学习·算法·transformer
惊鸿一博1 天前
Transformer模型图解(简单易懂版)
人工智能·深度学习·transformer
Omics Pro1 天前
填补蛋白质组深度学习预处理教学空白
人工智能·python·深度学习·plotly·numpy·pandas·scikit-learn
解局易否结局1 天前
ops-transformer 的 FlashAttention:给昇腾NPU 配了个“高效厨房“
人工智能·深度学习·transformer
东湖山上1 天前
GTAC: A Generative Transformer for Approximate Circuits
服务器·人工智能·深度学习·transformer·gpu算力