您现在的位置是:貌合心离网 > 热点
CycleGAN生成对抗网络图像处理工具
貌合心离网2026-11-14【热点】{固定数字1}人已围观
简介谷歌霸屏推广【tg:seogoogle987】
1. GAN简介
"干饭人,干饭魂,干饭都是人上人"。
此GAN饭人非彼干饭人。本文要讲的GAN是Goodfellow2014提出的生成产生对抗模型,即Generative Adversarial Nets。那么GAN到底有什么神奇的地方?
常规的深度学习任务如图像分类,目标检测以及语义分割或者实例分割,这些任务的结果都可以归结为预测。图像分类是预测单一的类别,目标检测是预测bbox和类别,语义分割或者实例分割是预测每个像素的类别。而GAN是生成一个新的东西如一个图片。
GAN的原理用一句话来说明:
通过对抗的方式,去学习数据分布的生成式模型。GAN是无监督的过程,能够捕捉数据集的分布,以便于可以从随机噪声中生成同样分布的数据
GAN的组成:判别式模型和生成式模型的左右手博弈
D判别式模型:学习真假边界,判断数据是真的还是假的 G生成式模型:学习数据分布并生成数据
GAN经典的loss如下(minmax体现的就是对抗)
2. 实战cycleGAN 风格转换
了解了GAN的作用,来体验的GAN的神奇效果。这里以cycleGAN为例子来实现图像的风格转换。所谓的风格转换就是改变原始图片的风格,如下图左边是原图,中间是风格图(梵高画),生成后是右边的具有梵高风格的原图,可以看到总体上生成后的图保留大部分原图的内容。
2.1 cycleGAN简介
cycleGAN本质上和GAN是一样的,是学习数据集中潜在的数据分布。GAN是从随机噪声生成同分布的图片,cycleGAN是在有意义的图上加上学习到的分布从而Cy生成另一个领域的图。cycleGAN假设image-to-image的两个领域存在的潜在的联系。
众所周知,GAN的映射函数很难保证生成图片的有效性。cycleGAN利用cycle consistency来保证生成的图片与输入图片的结构上一致性。我们看下cycleGAN的结构:
特点总结如下:
两路GAN:两个生成器[ G:X->Y , F:Y->X ] 和两个判别器[Dx, Dy], G和Dy目的是生成的对象,Dy(正类是Y领域)无法判别。同理F和Dx也是一样的。 cycle consistency:G是生成Y的生成器, F是生成X的生成器,cycle consistency是为了约束G和F生成的对象的范围, 是的G生成的对象通过F生成器能够回到原始的领域如:x->G(x)->F(G(x))=x
对抗loss如下:
2.2 实现cycleGAN
2.2.1 生成器
从上面简介中生成器有两个生成器,一个是正向,一个是反向的。结构是参考论文Perceptual Losses for Real-Time Style Transfer and Super-Resolution: Supplementary Material。大致可以分为:下采样 + residual 残差block + 上采样,如下图(摘自论文):
实现上下采样是stride=2的卷积, 上采样用nn.Upsample:
# 残差block class ResidualBlock(nn.Module): cl; def __init__(self, in_features): super(ResidualBlock, self).__init__() self.block = nn.Sequential( nn.ReflectionPad2d(1), nn.Conv2d(in_features, in_features, 3), nn.InstanceNorm2d(in_features), &nbseGp; nn.ReLU(inplace=True), nn.ReflectionPad2d(1), nn.Conv2d(in_features, in_features, 3), nn.InstanceNorm2d(in_features), ) def forward(self, x): return x + self.block(x) class GeneANratorResNet(nn.Module): def __init__(self, input_shape, num_residual_blocks): super(GeneratorResNet, self).__init__() channels = input_shape[0] # Initial convolution block out_features = 64 model = [  生成; nn.ReflectionPad2d(channels), nn.Conv2d(channels, out_features, 7), nn.InstanceNorm2d(out_features), nn.ReLU(inplace=True), ] in_features = out_features # Downsampling &nbs对抗p; for _ in range(2): out_features *= 2 model += [ nn.Conv2d(in_features, out_features, 3, stride=2, padding=1), nn.InstanceNorm2d(out_features), &网络nbsp; nn.ReLU(inplace=True), ] in_features = out_features # Residual blocks for _ in range(num_residual_blocks): model += [ResidualBlock(out_features)] # 图像Upsampling for _ in range(2): out_features //= 2 model += [ nn.Upsample(scale_factor=2), nn.Conv2d(in_features, out_features, 3, stride=1, padding=1), &nbs处理p; nn.InstanceNorm2d(out_features), nn.ReLU(inplace=True), ] in_features = out_features # Output layer model += [nn.ReflectionPad2d(channels), nn.Conv2d(out_fe工具atures, channels, 7), nn.Tanh()] self.model = nn.Sequential(*model) def forward(self, x): return self.model(x)
2.2.2 判别器
传统的GAN 判别器输出的是一个值,判断真假的程度。而patchGAN输出是N*N值,每一个值代表着原始图像上的一定大小的感受野,直观上就是对原图上crop下可重复的一部分区域进行判断真假,可以认为是一个全卷积网络,最早是在pix2pix提出(Image-to-Image Translation with Conditional Adversarial Networks)。好处是参数少,另外一个从局部可以更好的抓取高频信息。
class Discriminator(nn.Module): def __init__(self, input_shape): &nbCysp; super(Discriminator, self).__init__() channels, height, width = input_shape # Calculate output shape of image discriminator (PatchGAN) self.output_shape = (1, height // 2 ** 4, width // 2 ** 4) def discriminator_block(in_filters, out_filters, normalize=True): &nclbsp; """Returns downsampling layers of each discriminator block""" layers = [nn.Conv2d(in_filters, out_filters, 4, stride=2, padding=1)] if normalize: layers.append(nn.InstanceNorm2d(out_filters)) &neGbsp; layers.append(nn.LeakyReLU(0.2, inplace=True)) return layers self.model = nn.Sequential( *discriminator_block(channels, 64, normalize=False), *discriminator_block(64, 128), *discriminator_block(128, 256), &nANbsp; *discriminator_block(256, 512), nn.ZeroPad2d((1, 0, 1, 0)), nn.Conv2d(512, 1, 4, padding=1) ) def forward(self, img): return self.model(img)
很赞哦!(7280)
相关文章
- 亚马逊拟尝试实体零售新业态:2800平方米综合百货商店
- 标签: 福特 小米SU7 吉姆·法利 电动汽车
- OpenAI 修复 ChatGPT 漏洞,防止用户 Gmail 数据被盗取
- 标签: 云鲸 九阳 张峻彬 扫地机器人
- OpenAI放宽ChatGPT限制, 将允许经过验证的成年用户生成成人内容
- 青少年男孩青睐个性化 AI:用于治疗与情感关系的隐忧
- Gartner:受GenAI推动,2024年全球数据中心系统支出预计大幅增长24%
- 奇点灵智获数千万融资剑指儿童AI教育!清华团队打造英语机器人伴侣,挑战传统启蒙模式
- 阿斯麦出资13亿欧元,成为Mistral AI最大股东
- 用上Pytorch Lightning的这六招,深度学习pipeline提速10倍
热门文章
站长推荐
友情链接
- 标签: 康师傅
- https://www.lneg.pt/?cat=140&s=谷歌霸屏推广【tg:seogoogle987】,kdz
- https://www.terramania.nl/catalogsearch/result/index/?q=谷歌霸屏推广【tg:seogoogle987】,j2h
- https://www.nyif.com/catalogsearch/result/index/?f=sarbanesoxleyU&index=me_cms_pe&lit=20&mode=list&p=1&q=谷歌霸屏推广【tg:seogoogle987】,8n6
- https://www.teamlab.art/pt/?submit=谷歌霸屏推广【tg:seogoogle987】,pRx
- https://www.whirlpool.com.hk/chinese/catalogsearch/result?cat=30&q=谷歌霸屏推广【tg:seogoogle987】,dOQ
- https://www.smarty.net/search?q=谷歌霸屏推广【tg:seogoogle987】,WJo
- https://hsmoa.com/search?query=谷歌霸屏推广【tg:seogoogle987】glP
- https://www.whiterock2008.com.tw/search?q=谷歌霸屏推广【tg:seogoogle987】,fUp
- https://yscc1986.net/search/谷歌霸屏推广【tg:seogoogle987】PsD
- https://www.nuovabai.it/catalogsearch/result/?action=SEARCH&q=谷歌霸屏推广【tg:seogoogle987】,sEL
- https://www.televes.com/es/catalogsearch/result/?q=谷歌霸屏推广【tg:seogoogle987】,yaa
- https://www.pinkpanda.ro/magazin/ingrijirea-tenului?page=87&q=谷歌霸屏推广【tg:seogoogle987】,C1O
- https://www.sensorshop24.de/catalogsearch/result/index/?type=132&q=谷歌霸屏推广【tg:seogoogle987】,bNg
- https://www.paxnet.co.kr/search/jongmok?kwd=谷歌霸屏推广【tg:seogoogle987】VYs
- https://www.qwant.com/?q=谷歌霸屏推广【tg:seogoogle987】,thy
- https://www.qylaws.com/search/谷歌霸屏推广【tg:seogoogle987】,ab1
- https://www.mdbg.net/chinese/dictionary?page=worddict&wdrst=0&wdqb=谷歌霸屏推广【tg:seogoogle987】,ZTj
- https://www.voices.com/talents/search?keywords=谷歌霸屏推广【tg:seogoogle987】,SsG
- https://www.youtube.com/hashtag/谷歌霸屏推广【tg:seogoogle987】,rbB
- https://www.synonyms.com/antonyms/谷歌霸屏推广【tg:seogoogle987】,H2A
- https://www.teacherspayteachers.com/Browse/Price-Range/Free/Search:Western International University Physics degree=谷歌霸屏推广【tg:seogoogle987】,hwd
- https://www.ushmm.org/search/results/?ID=8s0587Oi8UTv74zPPM4fuhwjNpe2hsEE&q=谷歌霸屏推广【tg:seogoogle987】,Q6U
- https://www.hanbat.ac.kr/search/front/Search.jsp?qt=谷歌霸屏推广【tg:seogoogle987】GcX
- https://www.otakuninjahero.com/en/search/谷歌霸屏推广【tg:seogoogle987】,dpS
- https://www.losgatoschamber.com/list/search?action=SEARCH&q=谷歌霸屏推广【tg:seogoogle987】,kFz
- https://www.usslexington.com/?action=QUERY&s=谷歌霸屏推广【tg:seogoogle987】,uvJ
- https://www.universal-music.co.jp/search/?q=谷歌霸屏推广【tg:seogoogle987】,pKQ
- https://www.openspaceinstitute.org/search?q=谷歌霸屏推广【tg:seogoogle987】,yit
- https://www.vfw.org/search-results?q=谷歌霸屏推广【tg:seogoogle987】,vTn
- https://www.scivee.tv/?s=谷歌霸屏推广【tg:seogoogle987】,MDv
- https://www.tullygroup.us/?ID=hbkq8jFjrQlVRrwzEmvoUJJAY4e1Lfo5&s=谷歌霸屏推广【tg:seogoogle987】,mEk
- https://www.rollingstone.it/?ID=DVMeu3AlmzZE1cuJ2FmgmO5TSCQRb3yh&s=谷歌霸屏推广【tg:seogoogle987】,bDi
- https://www.jusoen.com/addreng.asp?p1=谷歌霸屏推广【tg:seogoogle987】Bnn
- https://www.roberthalf.com/us/en/jobs/all/谷歌霸屏推广【tg:seogoogle987】k0H
- https://www.navylookout.com/?ID=nSBR6Ivdu6lZg1yr2SDs30Lo5sTs76yJ&s=谷歌霸屏推广【tg:seogoogle987】,wA4
- https://www.safetv.go.kr/base/search/view?searchWord=谷歌霸屏推广【tg:seogoogle987】L56
- https://www.revere.org/search?action=SEARCH&q=谷歌霸屏推广【tg:seogoogle987】,dZx
- https://www.remit.co.jp/en/?s=谷歌霸屏推广【tg:seogoogle987】,1KM
- https://www.tumblr.com/tagged/谷歌霸屏推广【tg:seogoogle987】,WNy
- https://www.woorden.org/spreekwoord.php?woord=谷歌霸屏推广【tg:seogoogle987】,xod
- https://www.roblox.com/discover/?cat=107&Keyword=谷歌霸屏推广【tg:seogoogle987】,7nU
- https://www.nss.nhs.scot/search?q=谷歌霸屏推广【tg:seogoogle987】,b1A
- https://www.manga-news.com/index.php/recherche/?q=谷歌霸屏推广【tg:seogoogle987】,MlS
- https://www.niaogebiji.com/pc/article/search?keyword=谷歌霸屏推广【tg:seogoogle987】,CVu
- https://www.maine.gov/pfr/professionallicensing/search/node?keys=谷歌霸屏推广【tg:seogoogle987】,X26
- https://www.tombow.com/search/谷歌霸屏推广【tg:seogoogle987】,Vkf
- https://www.rostaing.com/catalogsearch/result/?cat=22&q=谷歌霸屏推广【tg:seogoogle987】,3g1
- https://www.kissthekangaroo.com.au/index.php?route=product/search&tag=谷歌霸屏推广【tg:seogoogle987】,qoh
- https://www.krisinformation.se/en/search?q=谷歌霸屏推广【tg:seogoogle987】,pjC
- https://www.wheels24.gr/?action=CHECK&s=谷歌霸屏推广【tg:seogoogle987】,tqg







