GAN快速入門資料推薦:17種變體的Keras開源代碼

sasldk 6年前發布 | 39K 次閱讀 Keras 開源

圖片來源:Kaggle blog

從2014年誕生至今,生成對抗網絡(GAN)始終廣受關注,已經出現了200多種有名有姓的變體。

這項“造假神技”的創作范圍,已經從最初的手寫數字和幾百像素小渣圖,拓展到了壁紙級高清照片、明星臉,甚至藝術畫作。

心癢難耐想趕快入門?

通過自己動手、探索模型代碼來學習,當然是墜吼的~如果用簡單易上手的Keras框架,那就更贊了。

一位GitHub群眾eriklindernoren就發布了17種GAN的Keras實現,得到Keras親爸爸Fran?ois Chollet在推ter上的熱情推薦。

干貨往下看:

https://github.com/eriklindernoren/Keras-GAN

AC-GAN

帶輔助分類器的GAN,全稱Auxiliary Classifier GAN。

在這類GAN變體中,生成器生成的每張圖像,都帶有一個類別標簽,鑒別器也會同時針對來源和類別標簽給出兩個概率分布。

論文中描述的模型,可以生成符合1000個ImageNet類別的128×128圖像。

code:

https://github.com/eriklindernoren/Keras-GAN/blob/master/acgan/acgan.py

paper:

Conditional Image Synthesis With Auxiliary Classifier GANs

Augustus Odena, Christopher Olah, Jonathon Shlens

https://arxiv.org/abs/1610.09585

Adversarial Autoencoder

這種模型簡稱AAE,是一種概率性自編碼器,運用GAN,通過將自編碼器的隱藏編碼向量和任意先驗分布進行匹配來進行變分推斷,可以用于半監督分類、分離圖像的風格和內容、無監督聚類、降維、數據可視化等方面。

在論文中,研究人員給出了用MNIST和多倫多人臉數據集 (TFD)訓練的模型所生成的樣本。

code:

https://github.com/eriklindernoren/Keras-GAN/blob/master/aae/adversarial_autoencoder.py

paper:

Adversarial Autoencoders

Alireza Makhzani, Jonathon Shlens, Navdeep Jaitly, Ian Goodfellow, Brendan Frey

https://arxiv.org/abs/1511.05644>

BiGAN

全稱Bidirectional GAN,也就是雙向GAN。這種變體能學習反向的映射,也就是將數據投射回隱藏空間。

Code:

https://github.com/eriklindernoren/Keras-GAN/blob/master/bigan/bigan.py

Paper:

Adversarial Feature Learning

Jeff Donahue, Philipp Kr?henbühl, Trevor Darrell

https://arxiv.org/abs/1605.09782

BGAN

雖然簡稱和上一類變體只差個i,但這兩種GAN完全不同。BGAN的全稱是boundary-seeking GAN。

原版GAN不適用于離散數據,而BGAN用來自鑒別器的估計差異度量來計算生成樣本的重要性權重,為訓練生成器來提供策略梯度,因此可以用離散數據進行訓練。

BGAN里生成樣本的重要性權重和鑒別器的判定邊界緊密相關,因此叫做“尋找邊界的GAN”。

Code:

https://github.com/eriklindernoren/Keras-GAN/blob/master/bgan/bgan.py

Paper:

Boundary-Seeking Generative Adversarial Networks

R Devon Hjelm, Athul Paul Jacob, Tong Che, Adam Trischler, Kyunghyun Cho, Yoshua Bengio

https://arxiv.org/abs/1702.08431

CC-GAN

這種模型能用半監督學習的方法,修補圖像上缺失的部分。

Code:

https://github.com/eriklindernoren/Keras-GAN/blob/master/ccgan/ccgan.py

Paper:

Semi-Supervised Learning with Context-Conditional Generative Adversarial Networks

Emily Denton, Sam Gross, Rob Fergus

https://arxiv.org/abs/1611.06430

CGAN

條件式生成對抗網絡,也就是conditional GAN,其中的生成器和鑒別器都以某種外部信息為條件,比如類別標簽或者其他形式的數據。

Code:

https://github.com/eriklindernoren/Keras-GAN/blob/master/cgan/cgan.py

Paper:

Conditional Generative Adversarial Nets

Mehdi Mirza, Simon Osindero

https://arxiv.org/abs/1411.1784

Context Encoder

這是一個修補圖像的卷積神經網絡(CNN),能根據周圍像素來生成圖像上任意區域的內容。

Code:

https://github.com/eriklindernoren/Keras-GAN/blob/master/context_encoder/context_encoder.py

Paper:

Context Encoders: Feature Learning by Inpainting

Deepak Pathak, Philipp Krahenbuhl, Jeff Donahue, Trevor Darrell, Alexei A. Efros

https://arxiv.org/abs/1604.07379>

CoGAN

這類變體全名叫coupled GANs,也就是耦合對抗生成網絡,其中包含一對GAN,將兩個生成模型前幾層、兩個辨別模型最后幾層的權重分別綁定起來,能學習多個域的圖像的聯合分布。

Code:

https://github.com/eriklindernoren/Keras-GAN/blob/master/cogan/cogan.py

Paper:

Coupled Generative Adversarial Networks

Ming-Yu Liu, Oncel Tuzel

https://arxiv.org/abs/1606.07536

CycleGAN

這個模型是加州大學伯克利分校的一項研究成果,可以在沒有成對訓練數據的情況下,實現圖像風格的轉換。

這些例子,你大概不陌生:

Code:

https://github.com/eriklindernoren/Keras-GAN/blob/master/cyclegan/cyclegan.py

Paper:

Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks

Jun-Yan Zhu, Taesung Park, Phillip Isola, Alexei A. Efros

https://arxiv.org/abs/1703.10593>

論文原作者開源了Torch和PyTorch的實現代碼,詳情見項目主頁:

https://junyanz.github.io/CycleGAN/

DCGAN

深度卷積生成對抗網絡模型是作為無監督學習的一種方法而提出的,GAN在其中是最大似然率技術的一種替代。

Code:

https://github.com/eriklindernoren/Keras-GAN/blob/master/dcgan/dcgan.py

Paper:

Unsupervised Representation Learning with Deep Convolutional Generative Adversarial Networks

Alec Radford, Luke Metz, Soumith Chintala

https://arxiv.org/abs/1511.06434

DualGAN

這種變體能夠用兩組不同域的無標簽圖像來訓練圖像翻譯器,架構中的主要GAN學習將圖像從域U翻譯到域V,而它的對偶GAN學習一個相反的過程,形成一個閉環。

Code:

https://github.com/eriklindernoren/Keras-GAN/blob/master/dualgan/dualgan.py

Paper:

DualGAN: Unsupervised Dual Learning for Image-to-Image Translation

Zili Yi, Hao Zhang, Ping Tan, Minglun Gong

https://arxiv.org/abs/1704.02510>

GAN

對,就是Ian Goodfellow那個原版GAN。

Code:

https://github.com/eriklindernoren/Keras-GAN/blob/master/gan/gan.py

Paper:

Generative Adversarial Networks

Ian J. Goodfellow, Jean Pouget-Abadie, Mehdi Mirza, Bing Xu, David Warde-Farley, Sherjil Ozair, Aaron Courville, Yoshua Bengio

https://arxiv.org/abs/1406.2661

InfoGAN

這個變體是GAN的信息論擴展(information-theoretic extension),能完全無監督地分別學會不同表示。比如在MNIST數據集上,InfoGAN成功地分別學會了書寫風格和數字的形狀。

Code:

https://github.com/eriklindernoren/Keras-GAN/blob/master/infogan/infogan.py

Paper:

InfoGAN: Interpretable Representation Learning by Information Maximizing Generative Adversarial Nets

Xi Chen, Yan Duan, Rein Houthooft, John Schulman, Ilya Sutskever, Pieter Abbeel

https://arxiv.org/abs/1606.03657

LSGAN

最小平方GAN(Least Squares GAN)的提出,是為了解決GAN無監督學習訓練中梯度消失的問題,在鑒別器上使用了最小平方損失函數。

Code:

https://github.com/eriklindernoren/Keras-GAN/blob/master/lsgan/lsgan.py

Paper:

Least Squares Generative Adversarial Networks

Xudong Mao, Qing Li, Haoran Xie, Raymond Y.K. Lau, Zhen Wang, Stephen Paul Smolley

https://arxiv.org/abs/1611.04076

Pix2Pix

這個模型大家應該相當熟悉了。它和CycleGAN出自同一個伯克利團隊,是CGAN的一個應用案例,以整張圖像作為CGAN中的條件。

在它基礎上,衍生出了各種上色Demo,波及貓、人臉、房子、包包、漫畫等各類物品,甚至還有人用它來去除(愛情動作片中的)馬賽克。

Code:

https://github.com/eriklindernoren/Keras-GAN/blob/master/pix2pix/pix2pix.py

Paper:

Image-to-Image Translation with Conditional Adversarial Networks

Phillip Isola, Jun-Yan Zhu, Tinghui Zhou, Alexei A. Efros

https://arxiv.org/abs/1611.07004

Pix2Pix目前有開源的Torch、PyTorch、TensorFlow、Chainer、Keras模型,詳情見項目主頁:

https://phillipi.github.io/pix2pix/

SGAN

這個變體的全稱非常直白:半監督(Semi-Supervised)生成對抗網絡。它通過強制讓辨別器輸出類別標簽,實現了GAN在半監督環境下的訓練。

Code:

https://github.com/eriklindernoren/Keras-GAN/blob/master/sgan/sgan.py

Paper:

Semi-Supervised Learning with Generative Adversarial Networks

Augustus Odena

https://arxiv.org/abs/1606.01583

WGAN

這種變體全稱Wasserstein GAN,在學習分布上使用了Wasserstein距離,也叫Earth-Mover距離。新模型提高了學習的穩定性,消除了模型崩潰等問題,并給出了在debug或搜索超參數時有參考意義的學習曲線。

本文所介紹repo中的WGAN實現,使用了DCGAN的生成器和辨別器。

Code:

https://github.com/eriklindernoren/Keras-GAN/blob/master/wgan/wgan.py

Paper:

Wasserstein GAN

Martin Arjovsky, Soumith Chintala, Léon Bottou

https://arxiv.org/abs/1701.07875

最后補充一點,作者為了讓沒有GPU的人也能測試這些實現,比較傾向于使用密集層(dense layer),只要在模型中能得出合理的結果,就不會去用卷積層。

 

來自:https://baijia.baidu.com/s?id=1593986547481867618&wfr=pc&fr=ch_lst

 

 本文由用戶 sasldk 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!