[{"data":1,"prerenderedAt":550},["ShallowReactive",2],{"content-query-iaKhIivW0J":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"cover":11,"type":12,"category":13,"body":14,"_type":544,"_id":545,"_source":546,"_file":547,"_stem":548,"_extension":549},"/technology-blogs/zh/632","zh",false,"","技术干货 | 基于MindSpore深度解读SinGAN网络！","解读SinGAN网络，介绍MindSpore深特点及使用技巧","2021-07-01","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/4bd0f43aa2104689a7fe17a5afce4641.png","technology-blogs","开发者分享",{"type":15,"children":16,"toc":537},"root",[17,25,34,39,44,49,56,66,71,84,92,99,104,109,116,121,126,143,151,156,163,168,179,190,195,203,210,215,222,227,234,239,244,252,259,264,269,277,284,289,296,301,306,314,319,326,333,341,346,351,358,363,371,378,383,390,395,403,410,415,423,430,435,443,450,455,474,483,499,504,515,520,525,530],{"type":18,"tag":19,"props":20,"children":22},"element","h1",{"id":21},"技术干货-基于mindspore深度解读singan网络",[23],{"type":24,"value":8},"text",{"type":18,"tag":26,"props":27,"children":28},"p",{},[29],{"type":18,"tag":30,"props":31,"children":33},"img",{"alt":7,"src":32},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/3c0a03df4c494052ba1625ac4ad95d71.gif",[],{"type":18,"tag":26,"props":35,"children":36},{},[37],{"type":24,"value":38},"本文来源于：知乎",{"type":18,"tag":26,"props":40,"children":41},{},[42],{"type":24,"value":43},"作者：asd",{"type":18,"tag":26,"props":45,"children":46},{},[47],{"type":24,"value":48},"写这个系列文章的目的在于解读SinGAN网络的同时，介绍MindSpore深度学习框架的特点及其使用技巧。本系列文章将分为四篇文章介绍，包含论文解读、源码解读、动手复现。希望能在大家今后的工作学习当中更好的理解SinGAN网络。",{"type":18,"tag":26,"props":50,"children":51},{},[52],{"type":18,"tag":30,"props":53,"children":55},{"alt":7,"src":54},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/847c2f9fc6bb43ee80d9be98488c091d.png",[],{"type":18,"tag":57,"props":58,"children":60},"h2",{"id":59},"简介",[61],{"type":18,"tag":62,"props":63,"children":64},"strong",{},[65],{"type":24,"value":59},{"type":18,"tag":26,"props":67,"children":68},{},[69],{"type":24,"value":70},"设计了一个基于单张图片的非条件图像生成模型，并应用在图像随机生成，图像融合、手绘画转自然图像、图像编辑以及图像超分重建等领域。",{"type":18,"tag":26,"props":72,"children":73},{},[74,76],{"type":24,"value":75},"文献下载：",{"type":18,"tag":77,"props":78,"children":82},"a",{"href":79,"rel":80},"https://arxiv.org/pdf/1905.01164.pdf",[81],"nofollow",[83],{"type":24,"value":79},{"type":18,"tag":57,"props":85,"children":87},{"id":86},"网络特点",[88],{"type":18,"tag":62,"props":89,"children":90},{},[91],{"type":24,"value":86},{"type":18,"tag":26,"props":93,"children":94},{},[95],{"type":18,"tag":30,"props":96,"children":98},{"alt":7,"src":97},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/695c95f401684f1b893ec4a198c8cc0b.jpg",[],{"type":18,"tag":26,"props":100,"children":101},{},[102],{"type":24,"value":103},"SinGAN的网络结构",{"type":18,"tag":26,"props":105,"children":106},{},[107],{"type":24,"value":108},"SinGAN的网络结构如上图所示，由金字塔形状的多个GAN网络组成，从下到上，输出图片的尺寸由小到大，由粗糙到精细。第一个生成器输入一个随机噪音，生成非常粗糙的图片，之后采用迭代的思想不断让生成器学习更多的局部细节。下面解释迭代过程。",{"type":18,"tag":26,"props":110,"children":111},{},[112],{"type":18,"tag":30,"props":113,"children":115},{"alt":7,"src":114},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/919787f968f04113aa80cafe568ffa69.jpg",[],{"type":18,"tag":26,"props":117,"children":118},{},[119],{"type":24,"value":120},"SinGAN的单个生成器结构",{"type":18,"tag":26,"props":122,"children":123},{},[124],{"type":24,"value":125},"生成器和判别器采用同一网络结构，如上图所示的5层卷积层。前一个生成器的输出图像经过尺寸放大后叠加等大的随机噪音作为5层卷积层的输入图像，5层卷积层的输出图像叠加前一个生成器的放大输出图像即是当前生成器的输出结果。",{"type":18,"tag":26,"props":127,"children":128},{},[129,134,136,141],{"type":18,"tag":62,"props":130,"children":131},{},[132],{"type":24,"value":133},"随着迭代次数的增加",{"type":24,"value":135},"，",{"type":18,"tag":62,"props":137,"children":138},{},[139],{"type":24,"value":140},"生成图像将会越来越清晰",{"type":24,"value":142},"。",{"type":18,"tag":57,"props":144,"children":146},{"id":145},"损失函数",[147],{"type":18,"tag":62,"props":148,"children":149},{},[150],{"type":24,"value":145},{"type":18,"tag":26,"props":152,"children":153},{},[154],{"type":24,"value":155},"SinGAN网络的损失函数由两部分组成，一是对抗损失，二是重建损失。对抗损失是判别器判别图谱的平均值，原文献中采用了wgan-gp以增强训练的稳定性。重建损失是固定第一个生成器的输入噪音，后面生成器的噪音使用零矩阵替代，用于重建图像，采用均方误差和原始图像进行对比。",{"type":18,"tag":26,"props":157,"children":158},{},[159],{"type":18,"tag":30,"props":160,"children":162},{"alt":7,"src":161},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/15dd3e9ff1534c03b343527441593f50.png",[],{"type":18,"tag":26,"props":164,"children":165},{},[166],{"type":24,"value":167},"源码下载",{"type":18,"tag":26,"props":169,"children":170},{},[171,173],{"type":24,"value":172},"官方源码：",{"type":18,"tag":77,"props":174,"children":177},{"href":175,"rel":176},"https://github.com/tamarott/SinGAN",[81],[178],{"type":24,"value":175},{"type":18,"tag":26,"props":180,"children":181},{},[182,184],{"type":24,"value":183},"其他实现：",{"type":18,"tag":77,"props":185,"children":188},{"href":186,"rel":187},"https://github.com/FriedRonaldo/SinGAN",[81],[189],{"type":24,"value":186},{"type":18,"tag":26,"props":191,"children":192},{},[193],{"type":24,"value":194},"官方源码较为复杂，因此以其他人实现的代码进行解释，数据集采用随机图像",{"type":18,"tag":26,"props":196,"children":197},{},[198],{"type":18,"tag":62,"props":199,"children":200},{},[201],{"type":24,"value":202},"生成器",{"type":18,"tag":26,"props":204,"children":205},{},[206],{"type":18,"tag":30,"props":207,"children":209},{"alt":7,"src":208},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/2eb548451cd4463085bdb88ab5d8153a.jpg",[],{"type":18,"tag":26,"props":211,"children":212},{},[213],{"type":24,"value":214},"生成器初始化",{"type":18,"tag":26,"props":216,"children":217},{},[218],{"type":18,"tag":30,"props":219,"children":221},{"alt":7,"src":220},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/6213b2293aeb4067b143c08b94666e96.jpg",[],{"type":18,"tag":26,"props":223,"children":224},{},[225],{"type":24,"value":226},"生成器更新",{"type":18,"tag":26,"props":228,"children":229},{},[230],{"type":18,"tag":30,"props":231,"children":233},{"alt":7,"src":232},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/531695961bd5489b8150270931d8157a.jpg",[],{"type":18,"tag":26,"props":235,"children":236},{},[237],{"type":24,"value":238},"生成器前传",{"type":18,"tag":26,"props":240,"children":241},{},[242],{"type":24,"value":243},"生成器由5个卷积层组成，若前后两个生成器结构完全相同，后一个生成器初始化时继承前一个的权重和偏置，每个4个生成器翻倍一次卷积层的通道数，最开始的通道数为32个。",{"type":18,"tag":26,"props":245,"children":246},{},[247],{"type":18,"tag":62,"props":248,"children":249},{},[250],{"type":24,"value":251},"判别器",{"type":18,"tag":26,"props":253,"children":254},{},[255],{"type":18,"tag":30,"props":256,"children":258},{"alt":7,"src":257},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/ae38fb62cec44b5d9f31c2e776bc6779.jpg",[],{"type":18,"tag":26,"props":260,"children":261},{},[262],{"type":24,"value":263},"判别器前传",{"type":18,"tag":26,"props":265,"children":266},{},[267],{"type":24,"value":268},"判别器的网络结构和更新与生成器相同，判别器前传生成和输入图像相同的判别图谱。",{"type":18,"tag":26,"props":270,"children":271},{},[272],{"type":18,"tag":62,"props":273,"children":274},{},[275],{"type":24,"value":276},"训练阶段",{"type":18,"tag":26,"props":278,"children":279},{},[280],{"type":18,"tag":30,"props":281,"children":283},{"alt":7,"src":282},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/2151d40175a64673a705cc0c4f4ae9e6.jpg",[],{"type":18,"tag":26,"props":285,"children":286},{},[287],{"type":24,"value":288},"生成器的训练",{"type":18,"tag":26,"props":290,"children":291},{},[292],{"type":18,"tag":30,"props":293,"children":295},{"alt":7,"src":294},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/afa06a735c23435b9afddbb7bb6bac5b.jpg",[],{"type":18,"tag":26,"props":297,"children":298},{},[299],{"type":24,"value":300},"判别器的训练",{"type":18,"tag":26,"props":302,"children":303},{},[304],{"type":24,"value":305},"重建损失采用均方误差，对抗损失可选择wgan-gp、zero-gp和lsgan模式。第一个噪音采用符合标准正态分布的噪音，之后的噪音乘以均方根误差为系数。",{"type":18,"tag":26,"props":307,"children":308},{},[309],{"type":18,"tag":62,"props":310,"children":311},{},[312],{"type":24,"value":313},"验证阶段",{"type":18,"tag":26,"props":315,"children":316},{},[317],{"type":24,"value":318},"对固定的噪音和随机的噪音进行验证，固定的噪音生成重建图像，随机的噪音生成假图片。",{"type":18,"tag":26,"props":320,"children":321},{},[322],{"type":18,"tag":30,"props":323,"children":325},{"alt":7,"src":324},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/ef57791f806e4f37b1cfad1aad802760.jpg",[],{"type":18,"tag":26,"props":327,"children":328},{},[329],{"type":18,"tag":30,"props":330,"children":332},{"alt":7,"src":331},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/c6a6a8748e8f4f4aa05611bc21c108a4.png",[],{"type":18,"tag":26,"props":334,"children":335},{},[336],{"type":18,"tag":62,"props":337,"children":338},{},[339],{"type":24,"value":340},"loss设置",{"type":18,"tag":26,"props":342,"children":343},{},[344],{"type":24,"value":345},"与Pytorch不同，在MindSpore上的训练模型，loss和单步训练最好写成算子的形式。",{"type":18,"tag":26,"props":347,"children":348},{},[349],{"type":24,"value":350},"g_loss设置",{"type":18,"tag":26,"props":352,"children":353},{},[354],{"type":18,"tag":30,"props":355,"children":357},{"alt":7,"src":356},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/4d7a90e57f1741058f3be0cec08e73d1.jpg",[],{"type":18,"tag":26,"props":359,"children":360},{},[361],{"type":24,"value":362},"d_loss 设置",{"type":18,"tag":26,"props":364,"children":365},{},[366],{"type":18,"tag":62,"props":367,"children":368},{},[369],{"type":24,"value":370},"训练单步设置",{"type":18,"tag":26,"props":372,"children":373},{},[374],{"type":18,"tag":30,"props":375,"children":377},{"alt":7,"src":376},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/dffd6942e43742f7867040b642ef5833.jpg",[],{"type":18,"tag":26,"props":379,"children":380},{},[381],{"type":24,"value":382},"生成器训练单步设置",{"type":18,"tag":26,"props":384,"children":385},{},[386],{"type":18,"tag":30,"props":387,"children":389},{"alt":7,"src":388},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/fbc555910f9c4f9e9d22f037cfc42639.jpg",[],{"type":18,"tag":26,"props":391,"children":392},{},[393],{"type":24,"value":394},"判别器训练单步设置",{"type":18,"tag":26,"props":396,"children":397},{},[398],{"type":18,"tag":62,"props":399,"children":400},{},[401],{"type":24,"value":402},"训练设置",{"type":18,"tag":26,"props":404,"children":405},{},[406],{"type":18,"tag":30,"props":407,"children":409},{"alt":7,"src":408},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/30ec4bcb4ac94705b72ff838df8c35f0.jpg",[],{"type":18,"tag":26,"props":411,"children":412},{},[413],{"type":24,"value":414},"把原始图像调整至需要的scale，获取对应的生成器和判别器并进行初始化，采用列表的形式保存之前的生成器，保证旧生成器关闭求导功能，采用adam优化器，并和loss模块绑定成单步训练。",{"type":18,"tag":26,"props":416,"children":417},{},[418],{"type":18,"tag":62,"props":419,"children":420},{},[421],{"type":24,"value":422},"开始训练",{"type":18,"tag":26,"props":424,"children":425},{},[426],{"type":18,"tag":30,"props":427,"children":429},{"alt":7,"src":428},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/e7b27ef26ba44b0e90baf886bbc5270a.jpg",[],{"type":18,"tag":26,"props":431,"children":432},{},[433],{"type":24,"value":434},"得到当前生成器的输入图像和噪音，开始训练。",{"type":18,"tag":26,"props":436,"children":437},{},[438],{"type":18,"tag":62,"props":439,"children":440},{},[441],{"type":24,"value":442},"保存图像",{"type":18,"tag":26,"props":444,"children":445},{},[446],{"type":18,"tag":30,"props":447,"children":449},{"alt":7,"src":448},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/3df0515ba1fe4031b7cd50ff9e236670.jpg",[],{"type":18,"tag":26,"props":451,"children":452},{},[453],{"type":24,"value":454},"保存原始图像、重建图像和生成图像。",{"type":18,"tag":26,"props":456,"children":457},{},[458,465,467],{"type":18,"tag":77,"props":459,"children":462},{"href":460,"rel":461},"http://mp.weixin.qq.com/s?__biz=MzAxMDA1MDM0NQ==&mid=2247536752&idx=1&sn=d7243bec17e68017dd3039e58ce3369f&chksm=9b545e36ac23d72032f05ac3af7438bc3f0db736cf97fe082ebceaeaf31555f2df2d9a76b8a1&scene=21#wechat_redirect",[81],[463],{"type":24,"value":464},"→",{"type":24,"value":466}," ",{"type":18,"tag":77,"props":468,"children":471},{"href":469,"rel":470},"http://mp.weixin.qq.com/s?__biz=MzAxMDA1MDM0NQ==&mid=2247536589&idx=1&sn=5a7b2fef26f7c15b473bd9fbbc408268&chksm=9b54418bac23c89d742e38a7174aebd54e3b65457e6b2f22430b19fb5982ff8d9095edd14ef6&scene=21#wechat_redirect",[81],[472],{"type":24,"value":473},"MindCon | 第二届极客周狂欢活动：找茬也能赢大奖！",{"type":18,"tag":26,"props":475,"children":476},{},[477],{"type":18,"tag":77,"props":478,"children":480},{"href":460,"rel":479},[81],[481],{"type":24,"value":482},"→ 快速定位问题根因！MindSpore调试调优工具：MindInsight",{"type":18,"tag":26,"props":484,"children":485},{},[486,491,492],{"type":18,"tag":77,"props":487,"children":489},{"href":460,"rel":488},[81],[490],{"type":24,"value":464},{"type":24,"value":466},{"type":18,"tag":77,"props":493,"children":496},{"href":494,"rel":495},"http://mp.weixin.qq.com/s?__biz=MzAxMDA1MDM0NQ==&mid=2247535881&idx=1&sn=445e6b19615538ae5949608118180726&chksm=9b54434fac23ca59c9cad91123a99789b1fae39bd6f27b1cbc9078c47600d145d78c66b972a3&scene=21#wechat_redirect",[81],[497],{"type":24,"value":498},"『MindSpore 啃书吧』为你详解过拟合与欠拟合",{"type":18,"tag":26,"props":500,"children":501},{},[502],{"type":24,"value":503},"MindSpore官方资料",{"type":18,"tag":26,"props":505,"children":506},{},[507,509],{"type":24,"value":508},"GitHub : ",{"type":18,"tag":77,"props":510,"children":513},{"href":511,"rel":512},"https://github.com/mindspore-ai/mindspore",[81],[514],{"type":24,"value":511},{"type":18,"tag":26,"props":516,"children":517},{},[518],{"type":24,"value":519},"Gitee:https : //gitee.com/mindspore/mindspore",{"type":18,"tag":26,"props":521,"children":522},{},[523],{"type":24,"value":524},"官方QQ群 : 871543426",{"type":18,"tag":26,"props":526,"children":527},{},[528],{"type":24,"value":529},"长按下方二维码加入MindSpore项目↓",{"type":18,"tag":26,"props":531,"children":532},{},[533],{"type":18,"tag":30,"props":534,"children":536},{"alt":7,"src":535},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/01/b8e0c281a8184dcfa98cec61a9524581.jpg",[],{"title":7,"searchDepth":538,"depth":538,"links":539},4,[540,542,543],{"id":59,"depth":541,"text":59},2,{"id":86,"depth":541,"text":86},{"id":145,"depth":541,"text":145},"markdown","content:technology-blogs:zh:632.md","content","technology-blogs/zh/632.md","technology-blogs/zh/632","md",1776506138999]