以下是一个简单的 PyTorch 生成对抗网络(GAN)的示例代码:
import torch
import torch.nn as nn
import torch.optim as optim
# 定义判别器网络
class Discriminator(nn.Module):
def __init__(self):
super(Discriminator, self).__init__()
self.model = nn.Sequential(
nn.Linear(784, 512),
nn.