# PyTorch implementations of Generative Adversarial Networks.

### Related tags

PyTorch-GAN
##### Overview

This repository has gone stale as I unfortunately do not have the time to maintain it anymore. If you would like to continue the development of it as a collaborator send me an email at [email protected].

## PyTorch-GAN

Collection of PyTorch implementations of Generative Adversarial Network varieties presented in research papers. Model architectures will not always mirror the ones proposed in the papers, but I have chosen to focus on getting the core ideas covered instead of getting every layer configuration right. Contributions and suggestions of GANs to implement are very welcomed.

## Installation

$git clone https://github.com/eriklindernoren/PyTorch-GAN$ cd PyTorch-GAN/
$python3 began.py  ### BicycleGAN Toward Multimodal Image-to-Image Translation #### Authors Jun-Yan Zhu, Richard Zhang, Deepak Pathak, Trevor Darrell, Alexei A. Efros, Oliver Wang, Eli Shechtman #### Abstract Many image-to-image translation problems are ambiguous, as a single input image may correspond to multiple possible outputs. In this work, we aim to model a \emph{distribution} of possible outputs in a conditional generative modeling setting. The ambiguity of the mapping is distilled in a low-dimensional latent vector, which can be randomly sampled at test time. A generator learns to map the given input, combined with this latent code, to the output. We explicitly encourage the connection between output and the latent code to be invertible. This helps prevent a many-to-one mapping from the latent code to the output during training, also known as the problem of mode collapse, and produces more diverse results. We explore several variants of this approach by employing different training objectives, network architectures, and methods of injecting the latent code. Our proposed method encourages bijective consistency between the latent encoding and output modes. We present a systematic comparison of our method and other variants on both perceptual realism and diversity. #### Run Example $ cd data/
$bash download_pix2pix_dataset.sh edges2shoes$ cd ../implementations/bicyclegan/
$python3 ccgan.py  ### Context Encoder Context Encoders: Feature Learning by Inpainting #### Authors Deepak Pathak, Philipp Krahenbuhl, Jeff Donahue, Trevor Darrell, Alexei A. Efros #### Abstract We present an unsupervised visual feature learning algorithm driven by context-based pixel prediction. By analogy with auto-encoders, we propose Context Encoders -- a convolutional neural network trained to generate the contents of an arbitrary image region conditioned on its surroundings. In order to succeed at this task, context encoders need to both understand the content of the entire image, as well as produce a plausible hypothesis for the missing part(s). When training context encoders, we have experimented with both a standard pixel-wise reconstruction loss, as well as a reconstruction plus an adversarial loss. The latter produces much sharper results because it can better handle multiple modes in the output. We found that a context encoder learns a representation that captures not just appearance but also the semantics of visual structures. We quantitatively demonstrate the effectiveness of our learned features for CNN pre-training on classification, detection, and segmentation tasks. Furthermore, context encoders can be used for semantic inpainting tasks, either stand-alone or as initialization for non-parametric methods. #### Run Example $ cd implementations/context_encoder/
<follow steps at the top of context_encoder.py>
python3 cogan.py  Generated MNIST and MNIST-M images ### CycleGAN Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks #### Authors Jun-Yan Zhu, Taesung Park, Phillip Isola, Alexei A. Efros #### Abstract Image-to-image translation is a class of vision and graphics problems where the goal is to learn the mapping between an input image and an output image using a training set of aligned image pairs. However, for many tasks, paired training data will not be available. We present an approach for learning to translate an image from a source domain X to a target domain Y in the absence of paired examples. Our goal is to learn a mapping G:X→Y such that the distribution of images from G(X) is indistinguishable from the distribution Y using an adversarial loss. Because this mapping is highly under-constrained, we couple it with an inverse mapping F:Y→X and introduce a cycle consistency loss to push F(G(X))≈X (and vice versa). Qualitative results are presented on several tasks where paired training data does not exist, including collection style transfer, object transfiguration, season transfer, photo enhancement, etc. Quantitative comparisons against several prior methods demonstrate the superiority of our approach. #### Run Example  cd data/
$bash download_cyclegan_dataset.sh monet2photo$ cd ../implementations/cyclegan/
$python3 dcgan.py  ### DiscoGAN Learning to Discover Cross-Domain Relations with Generative Adversarial Networks #### Authors Taeksoo Kim, Moonsu Cha, Hyunsoo Kim, Jung Kwon Lee, Jiwon Kim #### Abstract While humans easily recognize relations between data from different domains without any supervision, learning to automatically discover them is in general very challenging and needs many ground-truth pairs that illustrate the relations. To avoid costly pairing, we address the task of discovering cross-domain relations given unpaired data. We propose a method based on generative adversarial networks that learns to discover relations between different domains (DiscoGAN). Using the discovered relations, our proposed network successfully transfers style from one domain to another while preserving key attributes such as orientation and face identity. #### Run Example $ cd data/
$bash download_pix2pix_dataset.sh edges2shoes$ cd ../implementations/discogan/
$python3 dragan.py  ### DualGAN DualGAN: Unsupervised Dual Learning for Image-to-Image Translation #### Authors Zili Yi, Hao Zhang, Ping Tan, Minglun Gong #### Abstract Conditional Generative Adversarial Networks (GANs) for cross-domain image-to-image translation have made much progress recently. Depending on the task complexity, thousands to millions of labeled image pairs are needed to train a conditional GAN. However, human labeling is expensive, even impractical, and large quantities of data may not always be available. Inspired by dual learning from natural language translation, we develop a novel dual-GAN mechanism, which enables image translators to be trained from two sets of unlabeled images from two domains. In our architecture, the primal GAN learns to translate images from domain U to those in domain V, while the dual GAN learns to invert the task. The closed loop made by the primal and dual tasks allows images from either domain to be translated and then reconstructed. Hence a loss function that accounts for the reconstruction error of images can be used to train the translators. Experiments on multiple image translation tasks with unlabeled data show considerable performance gain of DualGAN over a single GAN. For some tasks, DualGAN can even achieve comparable or slightly better results than conditional GAN trained on fully labeled data. #### Run Example $ cd data/
$bash download_pix2pix_dataset.sh facades$ cd ../implementations/dualgan/
$python3 ebgan.py  ### Enhanced Super-Resolution GAN ESRGAN: Enhanced Super-Resolution Generative Adversarial Networks #### Authors Xintao Wang, Ke Yu, Shixiang Wu, Jinjin Gu, Yihao Liu, Chao Dong, Chen Change Loy, Yu Qiao, Xiaoou Tang #### Abstract The Super-Resolution Generative Adversarial Network (SRGAN) is a seminal work that is capable of generating realistic textures during single image super-resolution. However, the hallucinated details are often accompanied with unpleasant artifacts. To further enhance the visual quality, we thoroughly study three key components of SRGAN - network architecture, adversarial loss and perceptual loss, and improve each of them to derive an Enhanced SRGAN (ESRGAN). In particular, we introduce the Residual-in-Residual Dense Block (RRDB) without batch normalization as the basic network building unit. Moreover, we borrow the idea from relativistic GAN to let the discriminator predict relative realness instead of the absolute value. Finally, we improve the perceptual loss by using the features before activation, which could provide stronger supervision for brightness consistency and texture recovery. Benefiting from these improvements, the proposed ESRGAN achieves consistently better visual quality with more realistic and natural textures than SRGAN and won the first place in the PIRM2018-SR Challenge. The code is available at this https URL. #### Run Example $ cd implementations/esrgan/
<follow steps at the top of esrgan.py>
$python3 lsgan.py  ### MUNIT Multimodal Unsupervised Image-to-Image Translation #### Authors Xun Huang, Ming-Yu Liu, Serge Belongie, Jan Kautz #### Abstract Unsupervised image-to-image translation is an important and challenging problem in computer vision. Given an image in the source domain, the goal is to learn the conditional distribution of corresponding images in the target domain, without seeing any pairs of corresponding images. While this conditional distribution is inherently multimodal, existing approaches make an overly simplified assumption, modeling it as a deterministic one-to-one mapping. As a result, they fail to generate diverse outputs from a given source domain image. To address this limitation, we propose a Multimodal Unsupervised Image-to-image Translation (MUNIT) framework. We assume that the image representation can be decomposed into a content code that is domain-invariant, and a style code that captures domain-specific properties. To translate an image to another domain, we recombine its content code with a random style code sampled from the style space of the target domain. We analyze the proposed framework and establish several theoretical results. Extensive experiments with comparisons to the state-of-the-art approaches further demonstrates the advantage of the proposed framework. Moreover, our framework allows users to control the style of translation outputs by providing an example style image. Code and pretrained models are available at this https URL #### Run Example $ cd data/
$bash download_pix2pix_dataset.sh edges2shoes$ cd ../implementations/munit/
$python3 munit.py --dataset_name edges2shoes  Results by varying the style code. ### Pix2Pix Unpaired Image-to-Image Translation with Conditional Adversarial Networks #### Authors Phillip Isola, Jun-Yan Zhu, Tinghui Zhou, Alexei A. Efros #### Abstract We investigate conditional adversarial networks as a general-purpose solution to image-to-image translation problems. These networks not only learn the mapping from input image to output image, but also learn a loss function to train this mapping. This makes it possible to apply the same generic approach to problems that traditionally would require very different loss formulations. We demonstrate that this approach is effective at synthesizing photos from label maps, reconstructing objects from edge maps, and colorizing images, among other tasks. Indeed, since the release of the pix2pix software associated with this paper, a large number of internet users (many of them artists) have posted their own experiments with our system, further demonstrating its wide applicability and ease of adoption without the need for parameter tweaking. As a community, we no longer hand-engineer our mapping functions, and this work suggests we can achieve reasonable results without hand-engineering our loss functions either. #### Run Example $ cd data/
$bash download_pix2pix_dataset.sh facades$ cd ../implementations/pix2pix/
$python3 pixelda.py  Method Accuracy Naive 55% PixelDA 95% Rows from top to bottom: (1) Real images from MNIST (2) Translated images from MNIST to MNIST-M (3) Examples of images from MNIST-M ### Relativistic GAN The relativistic discriminator: a key element missing from standard GAN #### Authors Alexia Jolicoeur-Martineau #### Abstract In standard generative adversarial network (SGAN), the discriminator estimates the probability that the input data is real. The generator is trained to increase the probability that fake data is real. We argue that it should also simultaneously decrease the probability that real data is real because 1) this would account for a priori knowledge that half of the data in the mini-batch is fake, 2) this would be observed with divergence minimization, and 3) in optimal settings, SGAN would be equivalent to integral probability metric (IPM) GANs. We show that this property can be induced by using a relativistic discriminator which estimate the probability that the given real data is more realistic than a randomly sampled fake data. We also present a variant in which the discriminator estimate the probability that the given real data is more realistic than fake data, on average. We generalize both approaches to non-standard GAN loss functions and we refer to them respectively as Relativistic GANs (RGANs) and Relativistic average GANs (RaGANs). We show that IPM-based GANs are a subset of RGANs which use the identity function. Empirically, we observe that 1) RGANs and RaGANs are significantly more stable and generate higher quality data samples than their non-relativistic counterparts, 2) Standard RaGAN with gradient penalty generate data of better quality than WGAN-GP while only requiring a single discriminator update per generator update (reducing the time taken for reaching the state-of-the-art by 400%), and 3) RaGANs are able to generate plausible high resolutions images (256x256) from a very small sample (N=2011), while GAN and LSGAN cannot; these images are of significantly better quality than the ones generated by WGAN-GP and SGAN with spectral normalization. #### Run Example $ cd implementations/relativistic_gan/
$python3 relativistic_gan.py # Relativistic Standard GAN$ python3 relativistic_gan.py --rel_avg_gan   # Relativistic Average GAN


### Semi-Supervised GAN

Semi-Supervised Generative Adversarial Network

Augustus Odena

#### Abstract

We extend Generative Adversarial Networks (GANs) to the semi-supervised context by forcing the discriminator network to output class labels. We train a generative model G and a discriminator D on a dataset with inputs belonging to one of N classes. At training time, D is made to predict which of N+1 classes the input belongs to, where an extra class is added to correspond to the outputs of G. We show that this method can be used to create a more data-efficient classifier and that it allows for generating higher quality samples than a regular GAN.

#### Run Example

$cd implementations/sgan/$ python3 sgan.py


### Softmax GAN

Softmax GAN

Min Lin

#### Abstract

Softmax GAN is a novel variant of Generative Adversarial Network (GAN). The key idea of Softmax GAN is to replace the classification loss in the original GAN with a softmax cross-entropy loss in the sample space of one single batch. In the adversarial learning of N real training samples and M generated samples, the target of discriminator training is to distribute all the probability mass to the real samples, each with probability 1M, and distribute zero probability to generated data. In the generator training phase, the target is to assign equal probability to all data points in the batch, each with probability 1M+N. While the original GAN is closely related to Noise Contrastive Estimation (NCE), we show that Softmax GAN is the Importance Sampling version of GAN. We futher demonstrate with experiments that this simple change stabilizes GAN training.

#### Run Example

$cd implementations/softmax_gan/$ python3 softmax_gan.py


### StarGAN

StarGAN: Unified Generative Adversarial Networks for Multi-Domain Image-to-Image Translation

#### Authors

Yunjey Choi, Minje Choi, Munyoung Kim, Jung-Woo Ha, Sunghun Kim, Jaegul Choo

#### Abstract

Recent studies have shown remarkable success in image-to-image translation for two domains. However, existing approaches have limited scalability and robustness in handling more than two domains, since different models should be built independently for every pair of image domains. To address this limitation, we propose StarGAN, a novel and scalable approach that can perform image-to-image translations for multiple domains using only a single model. Such a unified model architecture of StarGAN allows simultaneous training of multiple datasets with different domains within a single network. This leads to StarGAN's superior quality of translated images compared to existing models as well as the novel capability of flexibly translating an input image to any desired target domain. We empirically demonstrate the effectiveness of our approach on a facial attribute transfer and a facial expression synthesis tasks.

#### Run Example

$cd implementations/stargan/ <follow steps at the top of stargan.py>$ python3 stargan.py


Original | Black Hair | Blonde Hair | Brown Hair | Gender Flip | Aged

### Super-Resolution GAN

Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network

#### Authors

Christian Ledig, Lucas Theis, Ferenc Huszar, Jose Caballero, Andrew Cunningham, Alejandro Acosta, Andrew Aitken, Alykhan Tejani, Johannes Totz, Zehan Wang, Wenzhe Shi

#### Abstract

Despite the breakthroughs in accuracy and speed of single image super-resolution using faster and deeper convolutional neural networks, one central problem remains largely unsolved: how do we recover the finer texture details when we super-resolve at large upscaling factors? The behavior of optimization-based super-resolution methods is principally driven by the choice of the objective function. Recent work has largely focused on minimizing the mean squared reconstruction error. The resulting estimates have high peak signal-to-noise ratios, but they are often lacking high-frequency details and are perceptually unsatisfying in the sense that they fail to match the fidelity expected at the higher resolution. In this paper, we present SRGAN, a generative adversarial network (GAN) for image super-resolution (SR). To our knowledge, it is the first framework capable of inferring photo-realistic natural images for 4x upscaling factors. To achieve this, we propose a perceptual loss function which consists of an adversarial loss and a content loss. The adversarial loss pushes our solution to the natural image manifold using a discriminator network that is trained to differentiate between the super-resolved images and original photo-realistic images. In addition, we use a content loss motivated by perceptual similarity instead of similarity in pixel space. Our deep residual network is able to recover photo-realistic textures from heavily downsampled images on public benchmarks. An extensive mean-opinion-score (MOS) test shows hugely significant gains in perceptual quality using SRGAN. The MOS scores obtained with SRGAN are closer to those of the original high-resolution images than to those obtained with any state-of-the-art method.

#### Run Example

$cd implementations/srgan/ <follow steps at the top of srgan.py>$ python3 srgan.py


Nearest Neighbor Upsampling | SRGAN

### UNIT

Unsupervised Image-to-Image Translation Networks

#### Authors

Ming-Yu Liu, Thomas Breuel, Jan Kautz

#### Abstract

Unsupervised image-to-image translation aims at learning a joint distribution of images in different domains by using images from the marginal distributions in individual domains. Since there exists an infinite set of joint distributions that can arrive the given marginal distributions, one could infer nothing about the joint distribution from the marginal distributions without additional assumptions. To address the problem, we make a shared-latent space assumption and propose an unsupervised image-to-image translation framework based on Coupled GANs. We compare the proposed framework with competing approaches and present high quality image translation results on various challenging unsupervised image translation tasks, including street scene image translation, animal image translation, and face image translation. We also apply the proposed framework to domain adaptation and achieve state-of-the-art performance on benchmark datasets. Code and additional results are available in this https URL.

#### Run Example

$cd data/$ bash download_cyclegan_dataset.sh apple2orange
$cd implementations/unit/$ python3 unit.py --dataset_name apple2orange


### Wasserstein GAN

Wasserstein GAN

#### Authors

Martin Arjovsky, Soumith Chintala, Léon Bottou

#### Abstract

We introduce a new algorithm named WGAN, an alternative to traditional GAN training. In this new model, we show that we can improve the stability of learning, get rid of problems like mode collapse, and provide meaningful learning curves useful for debugging and hyperparameter searches. Furthermore, we show that the corresponding optimization problem is sound, and provide extensive theoretical work highlighting the deep connections to other distances between distributions.

#### Run Example

$cd implementations/wgan/$ python3 wgan.py


### Wasserstein GAN GP

Improved Training of Wasserstein GANs

#### Authors

Ishaan Gulrajani, Faruk Ahmed, Martin Arjovsky, Vincent Dumoulin, Aaron Courville

#### Abstract

Generative Adversarial Networks (GANs) are powerful generative models, but suffer from training instability. The recently proposed Wasserstein GAN (WGAN) makes progress toward stable training of GANs, but sometimes can still generate only low-quality samples or fail to converge. We find that these problems are often due to the use of weight clipping in WGAN to enforce a Lipschitz constraint on the critic, which can lead to undesired behavior. We propose an alternative to clipping weights: penalize the norm of gradient of the critic with respect to its input. Our proposed method performs better than standard WGAN and enables stable training of a wide variety of GAN architectures with almost no hyperparameter tuning, including 101-layer ResNets and language models over discrete data. We also achieve high quality generations on CIFAR-10 and LSUN bedrooms.

#### Run Example

$cd implementations/wgan_gp/$ python3 wgan_gp.py


### Wasserstein GAN DIV

Wasserstein Divergence for GANs

#### Authors

Jiqing Wu, Zhiwu Huang, Janine Thoma, Dinesh Acharya, Luc Van Gool

#### Abstract

In many domains of computer vision, generative adversarial networks (GANs) have achieved great success, among which the fam- ily of Wasserstein GANs (WGANs) is considered to be state-of-the-art due to the theoretical contributions and competitive qualitative performance. However, it is very challenging to approximate the k-Lipschitz constraint required by the Wasserstein-1 metric (W-met). In this paper, we propose a novel Wasserstein divergence (W-div), which is a relaxed version of W-met and does not require the k-Lipschitz constraint.As a concrete application, we introduce a Wasserstein divergence objective for GANs (WGAN-div), which can faithfully approximate W-div through optimization. Under various settings, including progressive growing training, we demonstrate the stability of the proposed WGAN-div owing to its theoretical and practical advantages over WGANs. Also, we study the quantitative and visual performance of WGAN-div on standard image synthesis benchmarks, showing the superior performance of WGAN-div compared to the state-of-the-art methods.

#### Run Example

$cd implementations/wgan_div/$ python3 wgan_div.py


• #### Error when run cyclegan.py

when I run cyclegan.py,it always has this error： ValueError: num_samples should be a positive integer value, but got num_samples=0

Traceback (most recent call last):
File "cyclegan.py", line 124, in <module>
num_workers=opt.n_cpu,
File "/home/×××/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 213, in __init__
sampler = RandomSampler(dataset)
File "/home/×××/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/utils/data/sampler.py", line 94, in __init__
"value, but got num_samples={}".format(self.num_samples))
ValueError: num_samples should be a positive integer value, but got num_samples=0


what's the matter with it？

opened by x-Sapphire 5
• #### Implements of Wasserstein Divergence for GANs

opened by Pinnh 5
• #### About the Identity loss in cyclegan.py

The source code of Identity loss is shown below: loss_id_A = criterion_identity(G_BA(real_A), real_A) loss_id_B = criterion_identity(G_AB(real_B), real_B)

This seems a little bit weird to me, maybe it should be: loss_id_A = criterion_identity(G_AB(real_A), real_A) loss_id_B = criterion_identity(G_BA(real_B), real_B)

opened by LittleQuteSweetie 4

opened by MrLinNing 4
• #### How to use WGAN_gp to generate pics of myself

hi,your code is so amazing.I want to use your WGAN_gp code to generate my images

opened by fmbao 4
• #### WGAN GP detach is necessary?

https://github.com/eriklindernoren/PyTorch-GAN/blob/22ce15edd1abeb4f735be11592569720e2dd3018/implementations/wgan_gp/wgan_gp.py#L122

@eriklindernoren I think you should put .detach() to real_samples and fake_samples. Isn't it?

opened by Oktai15 4
• #### UserWarning: nn.Upsample is deprecated.

Hi~

I found an error while using InfoGAN. The error is as follows. Hope to repair.

/usr/local/lib/python3.7/site-packages/torch/nn/modules/upsampling.py:129: UserWarning: nn.Upsample is deprecated. Use nn.functional.interpolate instead.
warnings.warn("nn.{} is deprecated. Use nn.functional.interpolate instead.".format(self.name))
/usr/local/lib/python3.7/site-packages/torch/nn/modules/container.py:92: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.
input = module(input)


Thank you for writing the code, gave me a lot of inspiration!

opened by Lornatang 4
• #### loss_D about wgan

Hi: Thanks for sharing your impressive repo, I found the loss_D in wan.py is : loss_D = -torch.mean(discriminator(real_imgs)) + torch.mean(discriminator(fake_imgs)) ,but the wgan's paper described the loss_D as follow:

So is it a bug or other reasons？

opened by jeejeeli 3

I run CycleGAN following all commands the author gave. But there is empty in images and saved_models. I tested that the cyclegan.py didn't enter the 140 line "for i, batch in enumerate(dataloader):". Any advices is appreciated.

opened by SummerHuiZhang 3
• #### Possible error in code

In line 265 the code does not look right :

code_input = Variable(FloatTensor(np.random.normal(-1, 1, (batch_size, opt.code_dim))))

instead of 'normal' shouldn't be 'uniform'?

• Mirtha
opened by mlucas491 3
• #### modify VGG19 feature map layer in srgan

The final srgan in its paper uses the feature map obtained by the 4-th convolution (after activation) before the 5-th maxpooling layer within the VGG19 network.

Also no tanh at the end of conv3 for the generator, just a convolution

opened by Hazarre 0
• #### ClusterGan inference

Hi, thank you for such a great work

I can't understand the final part of the ClusterGAN pipeline exactly. We train a GAN to be able to extract a representation for each image. After that, we can visualize images using these encodings via TSNE . However how can we seperate data into K groups? For instance, we can run K-means over these representations, right?

opened by EmreOzkose 0
• #### problem for ccgan

NameError: name 'weights_init_normal' is not defined

opened by LunarSun 1
• #### load and save checkpoint logic error

Save checkpoint code, for example in the MUNIT GAN:

parser.add_argument("--epoch", type=int, default=0, help="epoch to start training from")
parser.add_argument("--checkpoint_interval", type=int, default=1, help="interval between saving model checkpoints")
for epoch in range(opt.epoch, opt.n_epochs):
for i, batch in enumerate(dataloader):

if opt.checkpoint_interval != -1 and epoch % opt.checkpoint_interval == 0:
torch.save(Enc1.state_dict(), "saved_models/%s/Enc1_%d.pth" % (opt.dataset_name, epoch))


The Problem
You will save the first checkpoint with epoch 0, but in the restore function, u cannot load form an epoch 0.
Load checkpoints, for example in the MUNIT GAN:
if opt.epoch != 0:
# Load pretrained models

else:
# Initialize weights

opened by John155 1

#### I recently trained pix2pix, and during the test I found that there seems to be no test part. So I want to ask if you can send me the code for the test part.

opened by MMMMMz 0
• #### Information About MUNIT

Dear, I would like to use MUNIT Example but i have some problem to download the datasets " pix2pix_dataset.sh edges2shoes". i used this "bash download_pix2pix_dataset.sh edges2shoes" code from Run Example . but in edge2shoes folder there is no any type of images . how can solve this problem .

opened by Yothe23 0
• #### Error in dcgan.py ?

https://github.com/eriklindernoren/PyTorch-GAN/blob/36d3c77e5ff20ebe0aeefd322326a134a279b93e/implementations/dcgan/dcgan.py#L91 the right code should be as following ? ds_size = opt.img_size // (2 ** 4) instead of ds_size = opt.img_size // 2 ** 4

opened by HuangZuShu 1
• #### Information about DiscoGAN and MUNIT

Dear, I would like to use your implementation with my personalized dataset for tuning the network after the training on edge2shoes. How can I make this possible?

opened by marcomameli1992 1
• #### A bug in AAE implementation ?

Hi,

Thanks for this repo!

The following code from the aae.py file line 197 - 199 confuse me a bit.

real_loss = adversarial_loss(discriminator(z), valid)
fake_loss = adversarial_loss(discriminator(encoded_imgs.detach()), fake)
d_loss = 0.5 * (real_loss + fake_loss)


AFAIK discriminator(z) should constitute fake examples while encoded_imgs.detach()) true examples. The goal of the discriminator is to correctly classify the noise z as fake embedding and encoded_imgs.detach() as valid. Hence, I suggest the following modification to this block of codes:

real_loss = adversarial_loss(discriminator(encoded_imgs.detach()), valid)
fake_loss = adversarial_loss(discriminator(z), fake)
d_loss = 0.5 * (real_loss + fake_loss)


Please let me know if I misunderstanding anything.

opened by Shentao-YANG 1
• #### Use of detach

Hello, I'm currently learning about PyTorch and GAN, I want to ask about this particular lines from the WGAN implementation here.

# Configure input
real_imgs = Variable(imgs.type(Tensor))

# ---------------------
#  Train Discriminator
# ---------------------

# Sample noise as generator input
z = Variable(Tensor(np.random.normal(0, 1, (imgs.shape[0], opt.latent_dim))))

# Generate a batch of images
fake_imgs = generator(z).detach()
loss_D = -torch.mean(discriminator(real_imgs)) + torch.mean(discriminator(fake_imgs))
loss_D.backward()
optimizer_D.step()


Why is the fake_imgs have .detach() function while the real_imgs doesn't? What would happen if I put .detach() on the real_imgs as well, will that mess with the discriminator update? Thank you.

opened by Indraa145 2
###### Erik Linder-Norén
ML engineer at Apple. Excited about machine learning, basketball and building things.
###### Annotated, understandable, and visually interpretable PyTorch implementations of: VAE, BIRVAE, NSGAN, MMGAN, WGAN, WGANGP, LSGAN, DRAGAN, BEGAN, RaGAN, InfoGAN, fGAN, FisherGAN

Overview PyTorch 0.4.1 | Python 3.6.5 Annotated implementations with comparative introductions for minimax, non-saturating, wasserstein, wasserstein g

454 Oct 4, 2021
###### The Incredible PyTorch: a curated list of tutorials, papers, projects, communities and more relating to PyTorch.

This is a curated list of tutorials, projects, libraries, videos, papers, books and anything related to the incredible PyTorch. Feel free to make a pu

8.5k Oct 22, 2021
###### A comprehensive list of published machine learning applications to cosmology

ml-in-cosmology This github attempts to maintain a comprehensive list of published machine learning applications to cosmology, organized by subject ma

211 Oct 15, 2021
###### Adversarial Robustness Toolbox (ART) - Python Library for Machine Learning Security - Evasion, Poisoning, Extraction, Inference - Red and Blue Teams

Adversarial Robustness Toolbox (ART) is a Python library for Machine Learning Security. ART provides tools that enable developers and researchers to defend and evaluate Machine Learning models and applications against the adversarial threats of Evasion, Poisoning, Extraction, and Inference. ART supports all popular machine learning frameworks (TensorFlow, Keras, PyTorch, MXNet, scikit-learn, XGBoost, LightGBM, CatBoost, GPy, etc.), all data types (images, tables, audio, video, etc.) and machine learning tasks (classification, object detection, speech recognition, generation, certification, etc.).

2.5k Oct 22, 2021
###### Official repository for "On Generating Transferable Targeted Perturbations" (ICCV 2021)

On Generating Transferable Targeted Perturbations (ICCV'21) Muzammal Naseer, Salman Khan, Munawar Hayat, Fahad Shahbaz Khan, and Fatih Porikli Paper:

29 Sep 15, 2021
###### Based on the paper "Geometry-aware Instance-reweighted Adversarial Training" ICLR 2021 oral

Geometry-aware Instance-reweighted Adversarial Training This repository provides codes for Geometry-aware Instance-reweighted Adversarial Training (ht

34 Sep 8, 2021
###### A collection of resources on GAN Inversion.

This repo is a collection of resources on GAN inversion, as a supplement for our survey

357 Oct 16, 2021
###### GNN4Traffic - This is the repository for the collection of Graph Neural Network for Traffic Forecasting

GNN4Traffic - This is the repository for the collection of Graph Neural Network for Traffic Forecasting

215 Oct 18, 2021
###### Code for the paper: Adversarial Training Against Location-Optimized Adversarial Patches. ECCV-W 2020.

Adversarial Training Against Location-Optimized Adversarial Patches arXiv | Paper | Code | Video | Slides Code for the paper: Sukrut Rao, David Stutz,

19 Sep 23, 2021
###### Fast and Easy Infinite Neural Networks in Python

Neural Tangents ICLR 2020 Video | Paper | Quickstart | Install guide | Reference docs | Release notes Overview Neural Tangents is a high-level neural

1.6k Oct 24, 2021
###### Alias-Free Generative Adversarial Networks (StyleGAN3) Official PyTorch implementation

Alias-Free Generative Adversarial Networks (StyleGAN3) Official PyTorch implementation

2.6k Oct 22, 2021
###### Geometric Deep Learning Extension Library for PyTorch

Documentation | Paper | Colab Notebooks | External Resources | OGB Examples PyTorch Geometric (PyG) is a geometric deep learning extension library for

12.8k Oct 22, 2021
###### Advanced Deep Learning with TensorFlow 2 and Keras (Updated for 2nd Edition)

Advanced Deep Learning with TensorFlow 2 and Keras (Updated for 2nd Edition)

1.1k Oct 21, 2021
###### Tensors and Dynamic neural networks in Python with strong GPU acceleration

PyTorch is a Python package that provides two high-level features: Tensor computation (like NumPy) with strong GPU acceleration Deep neural networks b

51.4k Oct 14, 2021
###### Tensors and Dynamic neural networks in Python with strong GPU acceleration

PyTorch is a Python package that provides two high-level features: Tensor computation (like NumPy) with strong GPU acceleration Deep neural networks b

46.1k Feb 13, 2021
###### Image-to-Image Translation in PyTorch

CycleGAN and pix2pix in PyTorch New: Please check out contrastive-unpaired-translation (CUT), our new unpaired image-to-image translation model that e

16k Oct 23, 2021
###### A curated list of neural network pruning resources.

A curated list of neural network pruning and related resources. Inspired by awesome-deep-vision, awesome-adversarial-machine-learning, awesome-deep-learning-papers and Awesome-NAS.

1.3k Oct 15, 2021
###### GANsformer: Generative Adversarial Transformers Drew A

GANsformer: Generative Adversarial Transformers Drew A. Hudson* & C. Lawrence Zitnick *I wish to thank Christopher D. Manning for the fruitf

780 Oct 12, 2021
###### StudioGAN is a Pytorch library providing implementations of representative Generative Adversarial Networks (GANs) for conditional/unconditional image generation.

StudioGAN is a Pytorch library providing implementations of representative Generative Adversarial Networks (GANs) for conditional/unconditional image generation.

1.9k Oct 16, 2021