Code Monkey home page Code Monkey logo

stylegan_pytorch's Introduction

“GitAds”/


This advert was placed by GitAds

A PyTorch Implementation of StyleGAN (Unofficial)

Github Github Github Github

This repository contains a PyTorch implementation of the following paper:

A Style-Based Generator Architecture for Generative Adversarial Networks
Tero Karras (NVIDIA), Samuli Laine (NVIDIA), Timo Aila (NVIDIA)
http://stylegan.xyz/paper

Abstract: We propose an alternative generator architecture for generative adversarial networks, borrowing from style transfer literature. The new architecture leads to an automatically learned, unsupervised separation of high-level attributes (e.g., pose and identity when trained on human faces) and stochastic variation in the generated images (e.g., freckles, hair), and it enables intuitive, scale-specific control of the synthesis. The new generator improves the state-of-the-art in terms of traditional distribution quality metrics, leads to demonstrably better interpolation properties, and also better disentangles the latent factors of variation. To quantify interpolation quality and disentanglement, we propose two new, automated methods that are applicable to any generator architecture. Finally, we introduce a new, highly varied and high-quality dataset of human faces.

Teaser image Picture: These people are not real – they were produced by our generator that allows control over different aspects of the image.

Motivation

To the best of my knowledge, there is still not a similar pytorch 1.0 implementation of styleGAN as NvLabs released(Tensorflow), therefore, i wanna implement it on pytorch1.0.1 to extend its usage in pytorch community.

Notice

@date: 2019.10.21

@info: The noteworthy thing I just ignore to highlight is you need to change default Star dataset to your own dataset (such as FFHQ or others) in opts.py. Sorry for my carelessness for this.

Author

Training

# ① pass your own dataset of training, batchsize and common settings in TrainOpts of `opts.py`.

# ② run train_stylegan.py
python3 train_stylegan.py

# ③ you can get intermediate pics generated by stylegenerator in `opts.det/images/`

Project

we follow the release code of styleGAN carefully and if you found any bug or mistake in implementation, please tell us and improve it, thank u very much!

Finished

  • blur2d mechanism. (a step which takes much gpu memory and if you don't have enough resouces, please set it to None.)
  • truncation tricks.
  • Two kind of upsample method in G_synthesis.
  • Two kind of downsample method in StyleDiscriminator.
  • PixelNorm and InstanceNorm.
  • Noise mechanism.
  • styleMixed mechanism.
  • add Multi-GPU support.

Unfinished

  • Inference code.

Related

1. StyleGAN - Official TensorFlow Implementation

2. The re-implementation of style-based generator idea

3. ptrblck_styleGAN

System Requirements

  • Ubuntu18.04
  • PyTorch 1.0.1
  • Numpy 1.13.3
  • torchvision 0.2.1
  • scikit-image 0.15.0
  • tqdm
  • GTX 1080Ti or above

Q&A

Acknowledgements

Our code can run 1024 x 1024 resolution image generation task on 1080Ti, if you have stronger graphic card or GPU, then you may train your model with large batchsize and self-define your multi-gpu version of this code.

My Email is [email protected], if you have any question and wanna to PR, please let me know, thank you.

stylegan_pytorch's People

Contributors

tomguluson92 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stylegan_pytorch's Issues

Some questions about `networks_stylegan.py`

Thanks for your reimplementation!

  1. In networks_stylegan.py, line 107 f = f[:, :, ::-1, ::-1], I think you should consider use f = torch.flip(f, [2, 3])
  2. In networks_stylegan.py, line 247, x = self.noise(x, noise), I think you should consider add a condition judgement before this line, like if self.noise is not None:
  3. In defination of forward function of the class GBlock, do you miss a 3x3 convolution between upsmaple and the first adaIn1?

style mixing with styleGAN

It seems that styleGAN only needs one dataset, unlike cycleGAN. But the offical video does show that it could do something like style mixing or transfer.
How to do that with styleGAN?

Thanks for your consideration and look forward to your early reply!

Question about the styleGAN performance in pytorch

Hi~

Very thanksful for your pytorch code sharing. I am very interested in the performance of the this styleGAN in pytorch. Have you test it in some metric, like FID, or check the generated results in the middle phase of training?

thanks,

EK

The Intermediate file is almost blank

Hi,
Thanks a lot for your pytorch version code.
I am training my own dataset with this model. But, the intermediate file till 80 epoch is still almost blank.
since my dataset has a lot of white background images, I am wondering if it is the main reason.
63

Is progressive growing supported?

Thanks for the good work. But I can't find where you implemented the progressive growing, which is one of the essential part of StyleGAN. It seems in the G_synthesis module in networks_stylegan.py, only the 'fixed' mode is supported. Does it mean the whole training process isn't conducted in the progressive growing fashion when I do "python train_stylegan.py"? And do you intend to support this feature in the future?

What is the licensing on this?

I am not entirely sure, but if you're creating the codebase from scratch (from the paper) then would the artifacts generated then be a property of the licensor/owner of the intellectual property? If not then what is the commercial usage restriction on it?

implementation not running

Hello,
First of all thank you for the code in pytorch. I am currently trying to run your implementation without any change except for the dataset. It seems that from the beginning itself the Generator Loss and the Discriminator Loss is saturating at 0.6 and 1.3 respectively. After a few epochs they are generating nan values. Could you please help me with this.
Thank you

the LeakyReLU layer after dense1

Hi, thanks for your reimplementation. It is so elegant.

But I found that you have a LeakyReLU layer after dense1, which does not exist in the tensorflow implementation.

x = F.leaky_relu(self.dense1(x), 0.2, inplace=True)

https://github.com/NVlabs/stylegan/blob/66813a32aac5045fcde72751522a0c0ba963f6f2/training/networks_stylegan.py#L617

I think that adding activation after the last fully connected layer is not a good idea.

Confusion about training results

Hi~ thank you for converting styleGAN to its pytorch version, which is pretty meaningful. I've noticed that there are some people who can not get resonable training results. Unfortunately, i am one of them. I've only got the results below:
0
The training set i am using have 30k images, so i don't think that is caused by the number of training set images. Hope that you can help me with it~

A question about the code

Thanks for your code!
I run the program with default parameters and images in star folder , but only the noise image is generated after 300 epochs.
Is there a problem with my operation?

Possible to run on a 1080 with 8GB? (memory error)

I have a DELL XPS with an nVidia 1080 w 8GB. My hope was to run StyleGAN on this rather than needing to jump to the cloud. Possible?

I disable blur2d by commenting out the lines including it

Getting this error:

:\Users\Powerpop\Anaconda3\lib\site-packages\skimage\transform\_warps.py:110: UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images.
  warn("Anti-aliasing will be enabled by default in skimage 0.15 to "
Traceback (most recent call last):
  File "train_stylegan.py", line 164, in <module>
    main(opts)
  File "train_stylegan.py", line 98, in main
    real_logit = D(real_img)
  File "C:\Users\Powerpop\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "C:\Users\Powerpop\Desktop\StyleGAN\networks_stylegan.py", line 651, in forward
    x = F.leaky_relu(self.conv6(x), 0.2, inplace=True)
  File "C:\Users\Powerpop\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "C:\Users\Powerpop\Anaconda3\lib\site-packages\torch\nn\modules\conv.py", line 338, in forward
    self.padding, self.dilation, self.groups)
RuntimeError: CUDA out of memory. Tried to allocate 4.00 GiB (GPU 0; 8.00 GiB total capacity; 4.19 GiB already allocated; 2.06 GiB free; 8.04 MiB cached)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.