对战人工智能:-人工智能之核心技术 深度学习 第六章 生成对抗网络(GAN) - error-icon{fill:#552222
人工智能之核心技术 深度学习
第六章 生成对抗网络(GAN)
文章目录
人工智能之核心技术 深度学习前言:生成对抗网络(GAN)—— 生成模型核心一、GAN 基础原理1.1 核心思想:对抗训练1.2 数学形式:极小极大博弈1.3 训练流程(交替更新)
二、经典 GAN 变体2.1 DCGAN(Deep Convolutional GAN, 2015)创新设计:
2.2 WGAN(Wasserstein GAN, 2017)核心改进:
2.3 StyleGAN(2019, NVIDIA)核心创新:
三、GAN 应用场景四、配套代码实现(DCGAN for MNIST)五、GAN 的挑战与未来当前挑战:未来方向:
六、总结对比
资料关注 拼多多帮助力入口
前言:生成对抗网络(GAN)—— 生成模型核心
生成对抗网络(Generative Adversarial Network, GAN)由 Ian Goodfellow 等人在 2014 年提出,被誉为“深度学习中最酷的想法之一”。它通过让两个神经网络相互博弈的方式,学会生成高度逼真的数据(如人脸、风景、艺术画等),开启了生成式 AI 的新纪元。
一、GAN 基础原理
1.1 核心思想:对抗训练
想象一个“造假者”和一个“鉴伪专家”的博弈:
生成器(Generator, G):试图伪造逼真的假币(或图像)判别器(Discriminator, D):试图区分真币和假币
目标:
G 要骗过 D(让 D 认为假图是真图)D 要准确识别真假(不被 G 欺骗)
随着训练进行,G 越来越擅长生成逼真样本,D 也越来越难分辨真假——最终达到纳什均衡。
#mermaid-svg-739qZc56PQl9iG2W{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-739qZc56PQl9iG2W .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-739qZc56PQl9iG2W .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-739qZc56PQl9iG2W .error-icon{fill:#552222;}#mermaid-svg-739qZc56PQl9iG2W .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-739qZc56PQl9iG2W .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-739qZc56PQl9iG2W .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-739qZc56PQl9iG2W .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-739qZc56PQl9iG2W .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-739qZc56PQl9iG2W .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-739qZc56PQl9iG2W .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-739qZc56PQl9iG2W .marker{fill:#333333;stroke:#333333;}#mermaid-svg-739qZc56PQl9iG2W .marker.cross{stroke:#333333;}#mermaid-svg-739qZc56PQl9iG2W svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-739qZc56PQl9iG2W p{margin:0;}#mermaid-svg-739qZc56PQl9iG2W .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-739qZc56PQl9iG2W .cluster-label text{fill:#333;}#mermaid-svg-739qZc56PQl9iG2W .cluster-label span{color:#333;}#mermaid-svg-739qZc56PQl9iG2W .cluster-label span p{background-color:transparent;}#mermaid-svg-739qZc56PQl9iG2W .label text,#mermaid-svg-739qZc56PQl9iG2W span{fill:#333;color:#333;}#mermaid-svg-739qZc56PQl9iG2W .node rect,#mermaid-svg-739qZc56PQl9iG2W .node circle,#mermaid-svg-739qZc56PQl9iG2W .node ellipse,#mermaid-svg-739qZc56PQl9iG2W .node polygon,#mermaid-svg-739qZc56PQl9iG2W .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-739qZc56PQl9iG2W .rough-node .label text,#mermaid-svg-739qZc56PQl9iG2W .node .label text,#mermaid-svg-739qZc56PQl9iG2W .image-shape .label,#mermaid-svg-739qZc56PQl9iG2W .icon-shape .label{text-anchor:middle;}#mermaid-svg-739qZc56PQl9iG2W .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-739qZc56PQl9iG2W .rough-node .label,#mermaid-svg-739qZc56PQl9iG2W .node .label,#mermaid-svg-739qZc56PQl9iG2W .image-shape .label,#mermaid-svg-739qZc56PQl9iG2W .icon-shape .label{text-align:center;}#mermaid-svg-739qZc56PQl9iG2W .node.clickable{cursor:pointer;}#mermaid-svg-739qZc56PQl9iG2W .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-739qZc56PQl9iG2W .arrowheadPath{fill:#333333;}#mermaid-svg-739qZc56PQl9iG2W .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-739qZc56PQl9iG2W .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-739qZc56PQl9iG2W .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-739qZc56PQl9iG2W .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-739qZc56PQl9iG2W .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-739qZc56PQl9iG2W .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-739qZc56PQl9iG2W .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-739qZc56PQl9iG2W .cluster text{fill:#333;}#mermaid-svg-739qZc56PQl9iG2W .cluster span{color:#333;}#mermaid-svg-739qZc56PQl9iG2W div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-739qZc56PQl9iG2W .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-739qZc56PQl9iG2W rect.text{fill:none;stroke-width:0;}#mermaid-svg-739qZc56PQl9iG2W .icon-shape,#mermaid-svg-739qZc56PQl9iG2W .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-739qZc56PQl9iG2W .icon-shape p,#mermaid-svg-739qZc56PQl9iG2W .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-739qZc56PQl9iG2W .icon-shape rect,#mermaid-svg-739qZc56PQl9iG2W .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-739qZc56PQl9iG2W .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-739qZc56PQl9iG2W .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-739qZc56PQl9iG2W :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}
反馈
反馈
随机噪声 z ~ N(0,1)
生成器 G
假图像 G(z)
真实图像 x
判别器 D
输出:真假概率
1.2 数学形式:极小极大博弈
GAN 的损失函数是一个极小极大优化问题:
min
G
max
D
V
(
D
,
G
)
=
E
x
∼
p
data
(
x
)
[
log
D
(
x
)
]
+
E
z
∼
p
z
(
z
)
[
log
(
1
−
D
(
G
(
z
)
)
)
]
\min_G \max_D V(D, G) = \mathbb{E}_{x \sim p_{\text{data}}(x)}[\log D(x)] + \mathbb{E}_{z \sim p_z(z)}[\log(1 - D(G(z)))]
GminDmaxV(D,G)=Ex∼pdata(x)[logD(x)]+Ez∼pz(z)[log(1−D(G(z)))]
判别器 D 的目标:最大化
V
(
D
,
G
)
V(D, G)
V(D,G) → 对真实样本输出高概率,对假样本输出低概率生成器 G 的目标:最小化
V
(
D
,
G
)
V(D, G)
V(D,G) → 让
D
(
G
(
z
)
)
D(G(z))
D(G(z)) 尽可能大(即骗过 D)
⚠️ 训练技巧: 实际中常将 G 的损失改为
min
G
−
E
[
log
D
(
G
(
z
)
)
]
\min_G -\mathbb{E}[\log D(G(z))]
minG−E[logD(G(z))],避免训练初期梯度消失。
1.3 训练流程(交替更新)
for epoch in epochs:
# 1. 固定 G,更新 D
real_loss = BCE(D(real_img), 1) # 真图标签=1
fake_loss = BCE(D(G(noise)), 0) # 假图标签=0
d_loss = real_loss + fake_loss
update D
# 2. 固定 D,更新 G
g_loss = BCE(D(G(noise)), 1) # 假图标签=1(骗 D)
update G
关键:D 和 G 交替训练,不能同时更新!
二、经典 GAN 变体
2.1 DCGAN(Deep Convolutional GAN, 2015)
首次成功将 CNN 引入 GAN,大幅提升图像生成质量。
创新设计:
组件设计原则生成器使用转置卷积(Transposed Conv) 上采样(替代全连接层)判别器标准 CNN(无池化,用 stride 卷积降采样)其他- 批归一化(BatchNorm)- ReLU(G)、LeakyReLU(D)
✅ 效果:可生成 64×64 清晰人脸、卧室等图像
2.2 WGAN(Wasserstein GAN, 2017)
解决原始 GAN 的两大痛点:
训练不稳定模式崩溃(Mode Collapse):G 只生成少数几种样本
核心改进:
使用 Wasserstein 距离(Earth Mover’s Distance) 替代 JS 散度判别器称为 Critic,输出实数值(非概率)对 Critic 参数强制 Lipschitz 连续 → 采用 权重裁剪 或 梯度惩罚(WGAN-GP)
WGAN-GP 损失:
L
D
=
E
[
D
(
G
(
z
)
)
]
−
E
[
D
(
x
)
]
+
λ
E
x
^
[
(
∥
∇
x
^
D
(
x
^
)
∥
2
−
1
)
2
]
L
G
=
−
E
[
D
(
G
(
z
)
)
]
\begin{aligned} \mathcal{L}_D &= \mathbb{E}[D(G(z))] - \mathbb{E}[D(x)] + \lambda \mathbb{E}_{\hat{x}}[(\|\nabla_{\hat{x}} D(\hat{x})\|_2 - 1)^2] \\ \mathcal{L}_G &= -\mathbb{E}[D(G(z))] \end{aligned}
LDLG=E[D(G(z))]−E[D(x)]+λEx^[(∥∇x^D(x^)∥2−1)2]=−E[D(G(z))]
✅ 优势:损失值与生成质量正相关,可作为调参指标!
2.3 StyleGAN(2019, NVIDIA)
实现高分辨率、高保真、可控风格的人脸生成。
核心创新:
风格迁移架构:将生成过程分解为“风格”和“内容”自适应实例归一化(AdaIN):在每一层注入风格向量渐进式增长:从 4×4 开始,逐步增加分辨率至 1024×1024映射网络(Mapping Network):将随机噪声
z
z
z 映射到中间空间
w
w
w,提升解耦性
#mermaid-svg-ZankFEeoRkw9jVf4{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-ZankFEeoRkw9jVf4 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-ZankFEeoRkw9jVf4 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-ZankFEeoRkw9jVf4 .error-icon{fill:#552222;}#mermaid-svg-ZankFEeoRkw9jVf4 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-ZankFEeoRkw9jVf4 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-ZankFEeoRkw9jVf4 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-ZankFEeoRkw9jVf4 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-ZankFEeoRkw9jVf4 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-ZankFEeoRkw9jVf4 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-ZankFEeoRkw9jVf4 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-ZankFEeoRkw9jVf4 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-ZankFEeoRkw9jVf4 .marker.cross{stroke:#333333;}#mermaid-svg-ZankFEeoRkw9jVf4 svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-ZankFEeoRkw9jVf4 p{margin:0;}#mermaid-svg-ZankFEeoRkw9jVf4 .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-ZankFEeoRkw9jVf4 .cluster-label text{fill:#333;}#mermaid-svg-ZankFEeoRkw9jVf4 .cluster-label span{color:#333;}#mermaid-svg-ZankFEeoRkw9jVf4 .cluster-label span p{background-color:transparent;}#mermaid-svg-ZankFEeoRkw9jVf4 .label text,#mermaid-svg-ZankFEeoRkw9jVf4 span{fill:#333;color:#333;}#mermaid-svg-ZankFEeoRkw9jVf4 .node rect,#mermaid-svg-ZankFEeoRkw9jVf4 .node circle,#mermaid-svg-ZankFEeoRkw9jVf4 .node ellipse,#mermaid-svg-ZankFEeoRkw9jVf4 .node polygon,#mermaid-svg-ZankFEeoRkw9jVf4 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-ZankFEeoRkw9jVf4 .rough-node .label text,#mermaid-svg-ZankFEeoRkw9jVf4 .node .label text,#mermaid-svg-ZankFEeoRkw9jVf4 .image-shape .label,#mermaid-svg-ZankFEeoRkw9jVf4 .icon-shape .label{text-anchor:middle;}#mermaid-svg-ZankFEeoRkw9jVf4 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-ZankFEeoRkw9jVf4 .rough-node .label,#mermaid-svg-ZankFEeoRkw9jVf4 .node .label,#mermaid-svg-ZankFEeoRkw9jVf4 .image-shape .label,#mermaid-svg-ZankFEeoRkw9jVf4 .icon-shape .label{text-align:center;}#mermaid-svg-ZankFEeoRkw9jVf4 .node.clickable{cursor:pointer;}#mermaid-svg-ZankFEeoRkw9jVf4 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-ZankFEeoRkw9jVf4 .arrowheadPath{fill:#333333;}#mermaid-svg-ZankFEeoRkw9jVf4 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-ZankFEeoRkw9jVf4 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-ZankFEeoRkw9jVf4 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-ZankFEeoRkw9jVf4 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-ZankFEeoRkw9jVf4 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-ZankFEeoRkw9jVf4 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-ZankFEeoRkw9jVf4 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-ZankFEeoRkw9jVf4 .cluster text{fill:#333;}#mermaid-svg-ZankFEeoRkw9jVf4 .cluster span{color:#333;}#mermaid-svg-ZankFEeoRkw9jVf4 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-ZankFEeoRkw9jVf4 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-ZankFEeoRkw9jVf4 rect.text{fill:none;stroke-width:0;}#mermaid-svg-ZankFEeoRkw9jVf4 .icon-shape,#mermaid-svg-ZankFEeoRkw9jVf4 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-ZankFEeoRkw9jVf4 .icon-shape p,#mermaid-svg-ZankFEeoRkw9jVf4 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-ZankFEeoRkw9jVf4 .icon-shape rect,#mermaid-svg-ZankFEeoRkw9jVf4 .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-ZankFEeoRkw9jVf4 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-ZankFEeoRkw9jVf4 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-ZankFEeoRkw9jVf4 :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}
z ~ N(0,1)
MLP: z → w
w
AdaIN1
AdaIN2
AdaIN3
常量张量
Conv1
Conv2
...
Output
效果:可独立控制人脸姿态、肤色、发型等属性!
三、GAN 应用场景
应用说明代表工作图像生成生成逼真人脸、动物、艺术画StyleGAN, BigGAN图像修复(Inpainting)填补图像缺失区域Context Encoder + GAN超分辨率(SRGAN)低清 → 高清SRGAN, ESRGAN风格迁移将艺术风格迁移到照片CycleGAN, Neural Style Transfer文本到图像生成根据描述生成图像AttnGAN, DALL·E(早期)数据增强生成稀缺样本(如医学图像)Medical GAN
注意:GAN 在文本生成上效果有限(离散 token 难优化),现多被 Transformer 取代。
四、配套代码实现(DCGAN for MNIST)
import torch
import torch.nn as nn
import torch.optim as optim
# 1. 生成器(使用转置卷积)
class Generator(nn.Module):
def __init__(self, nz=100, ngf=64):
super().__init__()
self.main = nn.Sequential(
# 输入: [batch, nz, 1, 1]
nn.ConvTranspose2d(nz, ngf*4, 4, 1, 0, bias=False),
nn.BatchNorm2d(ngf*4),
nn.ReLU(True),
# 输出: [batch, ngf*4, 4, 4]
nn.ConvTranspose2d(ngf*4, ngf*2, 4, 2, 1, bias=False),
nn.BatchNorm2d(ngf*2),
nn.ReLU(True),
# 输出: [batch, ngf*2, 8, 8]
nn.ConvTranspose2d(ngf*2, ngf, 4, 2, 1, bias=False),
nn.BatchNorm2d(ngf),
nn.ReLU(True),
# 输出: [batch, ngf, 16, 16]
nn.ConvTranspose2d(ngf, 1, 4, 2, 1, bias=False),
nn.Tanh() # 输出 [-1, 1]
# 最终: [batch, 1, 28, 28]
)
def forward(self, z):
return self.main(z)
# 2. 判别器(标准 CNN)
class Discriminator(nn.Module):
def __init__(self, ndf=64):
super().__init__()
self.main = nn.Sequential(
# 输入: [batch, 1, 28, 28]
nn.Conv2d(1, ndf, 4, 2, 1, bias=False),
nn.LeakyReLU(0.2, inplace=True),
# 输出: [batch, ndf, 14, 14]
nn.Conv2d(ndf, ndf*2, 4, 2, 1, bias=False),
nn.BatchNorm2d(ndf*2),
nn.LeakyReLU(0.2, inplace=True),
# 输出: [batch, ndf*2, 7, 7]
nn.Conv2d(ndf*2, ndf*4, 4, 2, 1, bias=False),
nn.BatchNorm2d(ndf*4),
nn.LeakyReLU(0.2, inplace=True),
# 输出: [batch, ndf*4, 3, 3]
nn.Conv2d(ndf*4, 1, 3, 1, 0, bias=False),
nn.Sigmoid() # 输出 [0,1]
)
def forward(self, x):
return self.main(x).view(-1, 1).squeeze(1)
# 3. 训练设置
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
nz = 100 # 噪声维度
netG = Generator(nz).to(device)
netD = Discriminator().to(device)
criterion = nn.BCELoss()
optimizerG = optim.Adam(netG.parameters(), lr=0.0002, betas=(0.5, 0.999))
optimizerD = optim.Adam(netD.parameters(), lr=0.0002, betas=(0.5, 0.999))
# 4. 训练循环(简化版)
for epoch in range(100):
for i, (real_imgs, _) in enumerate(dataloader):
batch_size = real_imgs.size(0)
real_imgs = real_imgs.to(device)
real_labels = torch.ones(batch_size, device=device)
fake_labels = torch.zeros(batch_size, device=device)
# --- 更新判别器 ---
optimizerD.zero_grad()
# 真图损失
output = netD(real_imgs)
loss_real = criterion(output, real_labels)
# 假图损失
noise = torch.randn(batch_size, nz, 1, 1, device=device)
fake_imgs = netG(noise)
output = netD(fake_imgs.detach()) # detach 阻止梯度回传到 G
loss_fake = criterion(output, fake_labels)
loss_D = loss_real + loss_fake
loss_D.backward()
optimizerD.step()
# --- 更新生成器 ---
optimizerG.zero_grad()
output = netD(fake_imgs)
loss_G = criterion(output, real_labels) # 假图标签=1
loss_G.backward()
optimizerG.step()
print(f"Epoch {epoch}, Loss_D: {loss_D.item():.4f}, Loss_G: {loss_G.item():.4f}")
提示:
使用 Tanh() 生成器输出需将真实图像归一化到 [-1, 1]detach() 防止判别器梯度影响生成器Adam 优化器参数 betas=(0.5, 0.999) 是 GAN 常用设置
五、GAN 的挑战与未来
当前挑战:
问题描述训练不稳定G 和 D 难以平衡评估困难缺乏可靠指标(常用 FID、IS)模式崩溃G 生成多样性不足计算成本高高分辨率生成需大量 GPU 资源
未来方向:
与扩散模型融合(如 GAN + Diffusion)3D 生成(NeRF + GAN)可控生成(结合 CLIP 等多模态模型)
六、总结对比
模型核心贡献适用场景原始 GAN对抗训练框架理论奠基DCGANCNN 架构标准化中小图像生成WGAN/WGAN-GP稳定训练 + 解决模式崩溃通用改进StyleGAN高质量 + 属性解耦人脸/肖像生成
#mermaid-svg-knTF2pk7izcEI6rW{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-knTF2pk7izcEI6rW .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-knTF2pk7izcEI6rW .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-knTF2pk7izcEI6rW .error-icon{fill:#552222;}#mermaid-svg-knTF2pk7izcEI6rW .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-knTF2pk7izcEI6rW .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-knTF2pk7izcEI6rW .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-knTF2pk7izcEI6rW .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-knTF2pk7izcEI6rW .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-knTF2pk7izcEI6rW .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-knTF2pk7izcEI6rW .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-knTF2pk7izcEI6rW .marker{fill:#333333;stroke:#333333;}#mermaid-svg-knTF2pk7izcEI6rW .marker.cross{stroke:#333333;}#mermaid-svg-knTF2pk7izcEI6rW svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-knTF2pk7izcEI6rW p{margin:0;}#mermaid-svg-knTF2pk7izcEI6rW .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-knTF2pk7izcEI6rW .cluster-label text{fill:#333;}#mermaid-svg-knTF2pk7izcEI6rW .cluster-label span{color:#333;}#mermaid-svg-knTF2pk7izcEI6rW .cluster-label span p{background-color:transparent;}#mermaid-svg-knTF2pk7izcEI6rW .label text,#mermaid-svg-knTF2pk7izcEI6rW span{fill:#333;color:#333;}#mermaid-svg-knTF2pk7izcEI6rW .node rect,#mermaid-svg-knTF2pk7izcEI6rW .node circle,#mermaid-svg-knTF2pk7izcEI6rW .node ellipse,#mermaid-svg-knTF2pk7izcEI6rW .node polygon,#mermaid-svg-knTF2pk7izcEI6rW .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-knTF2pk7izcEI6rW .rough-node .label text,#mermaid-svg-knTF2pk7izcEI6rW .node .label text,#mermaid-svg-knTF2pk7izcEI6rW .image-shape .label,#mermaid-svg-knTF2pk7izcEI6rW .icon-shape .label{text-anchor:middle;}#mermaid-svg-knTF2pk7izcEI6rW .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-knTF2pk7izcEI6rW .rough-node .label,#mermaid-svg-knTF2pk7izcEI6rW .node .label,#mermaid-svg-knTF2pk7izcEI6rW .image-shape .label,#mermaid-svg-knTF2pk7izcEI6rW .icon-shape .label{text-align:center;}#mermaid-svg-knTF2pk7izcEI6rW .node.clickable{cursor:pointer;}#mermaid-svg-knTF2pk7izcEI6rW .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-knTF2pk7izcEI6rW .arrowheadPath{fill:#333333;}#mermaid-svg-knTF2pk7izcEI6rW .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-knTF2pk7izcEI6rW .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-knTF2pk7izcEI6rW .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-knTF2pk7izcEI6rW .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-knTF2pk7izcEI6rW .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-knTF2pk7izcEI6rW .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-knTF2pk7izcEI6rW .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-knTF2pk7izcEI6rW .cluster text{fill:#333;}#mermaid-svg-knTF2pk7izcEI6rW .cluster span{color:#333;}#mermaid-svg-knTF2pk7izcEI6rW div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-knTF2pk7izcEI6rW .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-knTF2pk7izcEI6rW rect.text{fill:none;stroke-width:0;}#mermaid-svg-knTF2pk7izcEI6rW .icon-shape,#mermaid-svg-knTF2pk7izcEI6rW .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-knTF2pk7izcEI6rW .icon-shape p,#mermaid-svg-knTF2pk7izcEI6rW .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-knTF2pk7izcEI6rW .icon-shape rect,#mermaid-svg-knTF2pk7izcEI6rW .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-knTF2pk7izcEI6rW .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-knTF2pk7izcEI6rW .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-knTF2pk7izcEI6rW :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}
原始 GAN
DCGANCNN 架构
WGAN稳定训练
StyleGAN高质量可控生成
StyleGAN2/3细节优化
✅ 实践建议:
入门实验 → DCGAN + MNIST/CIFAR10高质量人脸 → StyleGAN2-ADA稳定训练 → 优先尝试 WGAN-GP
资料关注
公众号:咚咚王 gitee:https://gitee.com/wy18585051844/ai_learning
《Python编程:从入门到实践》 《利用Python进行数据分析》 《算法导论中文第三版》 《概率论与数理统计(第四版) (盛骤) 》 《程序员的数学》 《线性代数应该这样学第3版》 《微积分和数学分析引论》 《(西瓜书)周志华-机器学习》 《TensorFlow机器学习实战指南》 《Sklearn与TensorFlow机器学习实用指南》 《模式识别(第四版)》 《深度学习 deep learning》伊恩·古德费洛著 花书 《Python深度学习第二版(中文版)【纯文本】 (登封大数据 (Francois Choliet)) (Z-Library)》 《深入浅出神经网络与深度学习+(迈克尔·尼尔森(Michael+Nielsen)》 《自然语言处理综论 第2版》 《Natural-Language-Processing-with-PyTorch》 《计算机视觉-算法与应用(中文版)》 《Learning OpenCV 4》 《AIGC:智能创作时代》杜雨+&+张孜铭 《AIGC原理与实践:零基础学大语言模型、扩散模型和多模态模型》 《从零构建大语言模型(中文版)》 《实战AI大模型》 《AI 3.0》,对战人工智能