# 条件GAN

除了随机噪声之外，**还有人工控制的变量**，通过**控制这个变量可以生成不同类型的数据**。

* 生成模型除了随机向量，还输入有变量y，判别模型的输入中也有这个y
* 变量y称为条件变量，它是类别标签或其他信息

优化目标：

$$
min\_{G}max\_{D}=E\_{x \sim P\_{data}(x|y)}\[logD(x)]+E\_{z \sim P\_z(z)}\[log(1-D(G(z|y)))]
$$

> 实现时，如果条件变量作为类别变量，则可以采用one-hot向量编码方式
>
> 在**生成模型**中，向量y和随机噪声向量z**串联输入到神经网络**中
>
> **判别模型**将**x和y合并起来**送入神经网络进行训练， 这里是一个多分类问题

如图，生成器串联（x,y)，判别器合并(x,y)

![](/files/-LqHYr8WrjbRixJsxDeI)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://im-qianuxn.gitbook.io/pytorch/ji-suan-ji/shen-du-xue-xi-li-lun/gan/cgan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
