当前位置:网站首页>mm中的GAN模型架构
mm中的GAN模型架构
2022-07-02 23:09:00 【Kun Li】
mmgeneration中的GAN的架构包括,输入一张真实图像,如果是条件gan的话,输入的是一张真实图像和相应的标签,
1.首先对判别器进行训练,对判别器中梯度在训练时保存,和对判别器优化器进行zero_grad(),gan中生成器和判别器各有一个优化器,其实是两个相对独立的训练过程。
2.在训练判别器时也先使用生成器生成一个假样本,注意此时的生成器是不训练,仅仅是生成一个假样本,在条件gan时,还存在一个batch_accumulation_step的步骤,它在生成器训练时会多训练几次。
3.用判别器分别对真样本和假样本进行判别,计算判别器训练时的损失,正常的ganloss以及相应的辅助损失,放在disc_auxiliary_loss中,感觉gan中能够扩展的方向并不多,从架构上讲是transformers或者self-attention之类的,在理论上大体就是损失函数,l约束上的一些操作,所以此时的gen_auxiliary_loss是不同的一个点。判别器的loss本质上是个二分类,负样本输入,给的标签是0,正样本输入给的标签是1.
4.计算完损失之后,loss_disc.bachward()反向传播,optimizer['disciminator'].step()梯度更新,到这里判别器就训练完成了。
5.进行5-8轮的判别器训练之后开始转向生成器训练,每次训练前其实都对梯度进行了清零,相当于在每一轮时并不进行梯度累计,首先对判别器的梯度不进行保存,注意一开始训练判别器时,判别器的梯度是保存的,然后对生成器梯度进行zero_grad()。
6.训练生成器,生成器的输入还是噪声,得到生成器的图像之后,进行一次判别器判定,判别器最后一层一般是个Linear(n,1)的层,也就是输出是个N,1维的,输入到gen_loss中,这里gen_loss中核心也是辅助损失gen_auxiliary_loss中,此处也可能添加一些l约束之类的。
7.计算完损失之后,loss_gen.backward()反向传播,optimizer['generator'].step()梯度更新,生成器训练完成。

上图是一个典型的生成器和判别器的结构,在生成器中,我们需要一个将噪声向量转换成为二维特征的模块,也就是noise2feat block。接下来需要连续经过几个上采样块将低分辨率的特征转成高分辨率的特征,在 DCGAN 中,我们使用的是 transposed convolution 来实现。最后,需要一个 to_rgb 块来将特征图的通道数映射为3通道,从而生成图片。那判别器其实就是生成器的一个反转,我们需要通过 img2feat 和大量的下采样块将特征图不断降低分辨率,最后输送给 decision head,来对当前的输入图片进行评判。
边栏推荐
- 95 pages of smart education solutions 2022
- Digital twin visualization solution digital twin visualization 3D platform
- 多进程编程(四):共享内存
- Unique line of "Gelu"
- How QT exports data to PDF files (qpdfwriter User Guide)
- [Chongqing Guangdong education] audio visual language reference materials of Xinyang Normal University
- MFC file operation
- Hit the industry directly! The propeller launched the industry's first model selection tool
- Form form instantiation
- 详解用OpenCV的轮廓检测函数findContours()得到的轮廓拓扑结构(hiararchy)矩阵的意义、以及怎样用轮廓拓扑结构矩阵绘制轮廓拓扑结构图
猜你喜欢
![MATLAB signal processing [Q & a notes-1]](/img/53/ae081820fe81ce28e1f04914678a6f.png)
MATLAB signal processing [Q & a notes-1]
![[shutter] shutter open source project reference](/img/3f/b1d4edd8f8e8fd8e6b39548448270d.jpg)
[shutter] shutter open source project reference

Introduction of UART, RS232, RS485, I2C and SPI

多进程编程(二):管道

What website can you find English literature on?

130 pages of PPT from the brick boss introduces the new features of Apache spark 3.2 & 3.3 in depth

In February 2022, the ranking list of domestic databases: oceanbase regained its popularity with "three consecutive increases", and gaussdb is expected to achieve the largest increase this month

Install docker and use docker to install MySQL

Seckill system design

来自数砖大佬的 130页 PPT 深入介绍 Apache Spark 3.2 & 3.3 新功能
随机推荐
NC50965 Largest Rectangle in a Histogram
TypeError: Cannot read properties of undefined (reading ***)
Is there a specific format for English papers?
Talk with the interviewer about the pit of MySQL sorting (including: duplicate data problem in order by limit page)
Multiprocess programming (II): Pipeline
Understanding and application of least square method
Practical series - free commercial video material library
Bloom filter
数组常用操作方法整理(包含es6)及详细使用
[shutter] Introduction to the official example of shutter Gallery (project introduction | engineering construction)
MySQL advanced learning notes (4)
MySQL 23 classic interview hanging interviewer
Analyze ad654: Marketing Analytics
NC50528 滑动窗口
1380. Lucky numbers in the matrix
可下载《2022年中国数字化办公市场研究报告》详解1768亿元市场
经济学外文文献在哪查?
Define MySQL function to realize multi module call
zhvoice
Angled detection frame | calibrated depth feature for target detection (with implementation source code)