Files
python/Pytorch/nn/viFunc/readme.md
2025-09-09 15:56:55 +08:00

102 lines
3.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

好的 👍
`torch.nn` 里面确实包含了很多常用的神经网络模块,你可以把它们理解为深度学习中各种“积木”,主要分为 **层layers**、**容器containers** 和 **正则化/损失函数** 等几个类别。
下面我给你整理一份 **值得学习的网络层/模块清单**(重点是 `nn` 里面和建模相关的):
---
### 🔹 1. 基础层Linear & Embedding
* `nn.Linear` —— 全连接层MLP 基础积木)
* `nn.Bilinear` —— 双线性层
* `nn.Embedding` —— 词嵌入层
* `nn.EmbeddingBag` —— 变体,适合处理词袋模型
---
### 🔹 2. 卷积层Convolution Layers
* `nn.Conv1d` —— 一维卷积(常用于 NLP、语音
* `nn.Conv2d` —— 二维卷积(图像处理最常用)
* `nn.Conv3d` —— 三维卷积(视频、体数据)
* `nn.ConvTranspose1d/2d/3d` —— 反卷积(上采样/生成模型常用)
---
### 🔹 3. 池化层Pooling
* `nn.MaxPool1d/2d/3d` —— 最大池化
* `nn.AvgPool1d/2d/3d` —— 平均池化
* `nn.AdaptiveMaxPool1d/2d/3d` —— 自适应池化(固定输出大小)
* `nn.AdaptiveAvgPool1d/2d/3d` —— 自适应平均池化
---
### 🔹 4. 循环神经网络层RNN 系列)
* `nn.RNN` —— 基础循环网络
* `nn.LSTM` —— 长短期记忆网络
* `nn.GRU` —— 门控循环单元
---
### 🔹 5. Transformer 相关
* `nn.MultiheadAttention` —— 多头注意力机制
* `nn.Transformer` —— 整个 Transformer 模型(包含编码器+解码器)
* `nn.TransformerEncoder` / `nn.TransformerDecoder`
* `nn.TransformerEncoderLayer` / `nn.TransformerDecoderLayer`
---
### 🔹 6. 归一化Normalization
* `nn.BatchNorm1d/2d/3d` —— 批量归一化
* `nn.LayerNorm` —— 层归一化Transformer 常用)
* `nn.GroupNorm` —— 分组归一化
* `nn.InstanceNorm1d/2d/3d` —— 实例归一化(风格迁移常用)
* `nn.LocalResponseNorm` —— 局部响应归一化(早期 CNN
---
### 🔹 7. Dropout & 正则化
* `nn.Dropout` —— 全连接层 Dropout
* `nn.Dropout2d/3d` —— 用于卷积层的 Dropout
* `nn.AlphaDropout` —— 用于 SELU 激活的变体
---
### 🔹 8. 激活函数(很多都在 `torch.nn.functional`,但也有类)
* `nn.ReLU`, `nn.LeakyReLU`, `nn.PReLU`, `nn.RReLU`
* `nn.Sigmoid`, `nn.Tanh`, `nn.ELU`, `nn.CELU`
* `nn.SELU`, `nn.GELU`, `nn.SiLU`=Swish
* `nn.Softmax`, `nn.LogSoftmax`
* `nn.Softplus`, `nn.Softsign`
---
### 🔹 9. 稀疏与其他层
* `nn.SparseLinear`PyTorch 2.5+ 才有)
* `nn.PixelShuffle` —— 超分辨率常用(上采样)
* `nn.Upsample` —— 上采样
* `nn.Unfold / nn.Fold` —— 图像 Patch 提取和恢复
---
### 🔹 10. 容器(搭建网络时用)
* `nn.Sequential` —— 顺序容器
* `nn.ModuleList` —— 模块列表
* `nn.ModuleDict` —— 模块字典
* `nn.ParameterList / ParameterDict` —— 参数容器
---
👉 如果你是初学者,推荐学习路径大概是:
`Linear → Conv → Pool → BatchNorm/LayerNorm → Dropout → RNN/LSTM/GRU → Transformer → MultiheadAttention`
要不要我帮你整理一份 **按“难度/应用领域”分层的学习路线图**(比如入门 → 图像 → NLP → 高级网络)?