Git Product home page Git Product logo

lucidrains / stylegan2-pytorch Goto Github PK

View Code? Open in Web Editor NEW
3.7K 70.0 589.0 4.99 MB

Simplest working implementation of Stylegan2, state of the art generative adversarial network, in Pytorch. Enabling everyone to experience disentanglement

Home Page: https://thispersondoesnotexist.com

License: MIT License

Python 100.00%
generative-adversarial-network artificial-intelligence pytorch machine-learning generative-model

stylegan2-pytorch's Introduction

Simple StyleGan2 for Pytorch

PyPI version

Simple Pytorch implementation of Stylegan2 based on https://arxiv.org/abs/1912.04958 that can be completely trained from the command-line, no coding needed.

Below are some flowers that do not exist.

Neither do these hands

Nor these cities

Nor these celebrities (trained by @yoniker)

Install

You will need a machine with a GPU and CUDA installed. Then pip install the package like this

$ pip install stylegan2_pytorch

If you are using a windows machine, the following commands reportedly works.

$ conda install pytorch torchvision -c python
$ pip install stylegan2_pytorch

Use

$ stylegan2_pytorch --data /path/to/images

That's it. Sample images will be saved to results/default and models will be saved periodically to models/default.

Advanced Use

You can specify the name of your project with

$ stylegan2_pytorch --data /path/to/images --name my-project-name

You can also specify the location where intermediate results and model checkpoints should be stored with

$ stylegan2_pytorch --data /path/to/images --name my-project-name --results_dir /path/to/results/dir --models_dir /path/to/models/dir

You can increase the network capacity (which defaults to 16) to improve generation results, at the cost of more memory.

$ stylegan2_pytorch --data /path/to/images --network-capacity 256

By default, if the training gets cut off, it will automatically resume from the last checkpointed file. If you want to restart with new settings, just add a new flag

$ stylegan2_pytorch --new --data /path/to/images --name my-project-name --image-size 512 --batch-size 1 --gradient-accumulate-every 16 --network-capacity 10

Once you have finished training, you can generate images from your latest checkpoint like so.

$ stylegan2_pytorch  --generate

To generate a video of a interpolation through two random points in latent space.

$ stylegan2_pytorch --generate-interpolation --interpolation-num-steps 100

To save each individual frame of the interpolation

$ stylegan2_pytorch --generate-interpolation --save-frames

If a previous checkpoint contained a better generator, (which often happens as generators start degrading towards the end of training), you can load from a previous checkpoint with another flag

$ stylegan2_pytorch --generate --load-from {checkpoint number}

A technique used in both StyleGAN and BigGAN is truncating the latent values so that their values fall close to the mean. The small the truncation value, the better the samples will appear at the cost of sample variety. You can control this with the --trunc-psi, where values typically fall between 0.5 and 1. It is set at 0.75 as default

$ stylegan2_pytorch --generate --trunc-psi 0.5

Multi-GPU training

If you have one machine with multiple GPUs, the repository offers a way to utilize all of them for training. With multiple GPUs, each batch will be divided evenly amongst the GPUs available. For example, for 2 GPUs, with a batch size of 32, each GPU will see 16 samples.

You simply have to add a --multi-gpus flag, everyting else is taken care of. If you would like to restrict to specific GPUs, you can use the CUDA_VISIBLE_DEVICES environment variable to control what devices can be used. (ex. CUDA_VISIBLE_DEVICES=0,2,3 only devices 0, 2, 3 are available)

$ stylegan2_pytorch --data ./data --multi-gpus --batch-size 32 --gradient-accumulate-every 1

Low amounts of Training Data

In the past, GANs needed a lot of data to learn how to generate well. The faces model took 70k high quality images from Flickr, as an example.

However, in the month of May 2020, researchers all across the world independently converged on a simple technique to reduce that number to as low as 1-2k. That simple idea was to differentiably augment all images, generated or real, going into the discriminator during training.

If one were to augment at a low enough probability, the augmentations will not 'leak' into the generations.

In the setting of low data, you can use the feature with a simple flag.

# find a suitable probability between 0. -> 0.7 at maximum
$ stylegan2_pytorch --data ./data --aug-prob 0.25

By default, the augmentations used are translation and cutout. If you would like to add color, you can do so with the --aug-types argument.

# make sure there are no spaces between items!
$ stylegan2_pytorch --data ./data --aug-prob 0.25 --aug-types [translation,cutout,color]

You can customize it to any combination of the three you would like. The differentiable augmentation code was copied and slightly modified from here.

When do I stop training?

For as long as possible until the adversarial game between the two neural nets fall apart (we call this divergence). By default, the number of training steps is set to 150000 for 128x128 images, but you will certainly want this number to be higher if the GAN doesn't diverge by the end of training, or if you are training at a higher resolution.

$ stylegan2_pytorch --data ./data --image-size 512 --num-train-steps 1000000

Attention

This framework also allows for you to add an efficient form of self-attention to the designated layers of the discriminator (and the symmetric layer of the generator), which will greatly improve results. The more attention you can afford, the better!

# add self attention after the output of layer 1
$ stylegan2_pytorch --data ./data --attn-layers 1
# add self attention after the output of layers 1 and 2
# do not put a space after the comma in the list!
$ stylegan2_pytorch --data ./data --attn-layers [1,2]

Bonus

Training on transparent images

$ stylegan2_pytorch --data ./transparent/images/path --transparent

Memory considerations

The more GPU memory you have, the bigger and better the image generation will be. Nvidia recommended having up to 16GB for training 1024x1024 images. If you have less than that, there are a couple settings you can play with so that the model fits.

$ stylegan2_pytorch --data /path/to/data \
    --batch-size 3 \
    --gradient-accumulate-every 5 \
    --network-capacity 16
  1. Batch size - You can decrease the batch-size down to 1, but you should increase the gradient-accumulate-every correspondingly so that the mini-batch the network sees is not too small. This may be confusing to a layperson, so I'll think about how I would automate the choice of gradient-accumulate-every going forward.

  2. Network capacity - You can decrease the neural network capacity to lessen the memory requirements. Just be aware that this has been shown to degrade generation performance.

If none of this works, you can settle for 'Lightweight' GAN, which will allow you to tradeoff quality to train at greater resolutions in reasonable amount of time.

Deployment on AWS

Below are some steps which may be helpful for deployment using Amazon Web Services. In order to use this, you will have to provision a GPU-backed EC2 instance. An appropriate instance type would be from a p2 or p3 series. I (iboates) tried a p2.xlarge (the cheapest option) and it was quite slow, slower in fact than using Google Colab. More powerful instance types may be better but they are more expensive. You can read more about them here.

Setup steps

  1. Archive your training data and upload it to an S3 bucket
  2. Provision your EC2 instance (I used an Ubuntu AMI)
  3. Log into your EC2 instance via SSH
  4. Install the aws CLI client and configure it:
sudo snap install aws-cli --classic
aws configure

You will then have to enter your AWS access keys, which you can retrieve from the management console under AWS Management Console > Profile > My Security Credentials > Access Keys

Then, run these commands, or maybe put them in a shell script and execute that:

mkdir data
curl -O https://bootstrap.pypa.io/get-pip.py
sudo apt-get install python3-distutils
python3 get-pip.py
pip3 install stylegan2_pytorch
export PATH=$PATH:/home/ubuntu/.local/bin
aws s3 sync s3://<Your bucket name> ~/data
cd data
tar -xf ../train.tar.gz

Now you should be able to train by simplying calling stylegan2_pytorch [args].

Notes:

  • If you have a lot of training data, you may need to provision extra block storage via EBS.
  • Also, you may need to spread your data across multiple archives.
  • You should run this on a screen window so it won't terminate once you log out of the SSH session.

Research

FID Scores

Thanks to GetsEclectic, you can now calculate the FID score periodically! Again, made super simple with one extra argument, as shown below.

Firstly, install the pytorch_fid package

$ pip install pytorch-fid

Followed by

$ stylegan2_pytorch --data ./data --calculate-fid-every 5000

FID results will be logged to ./results/{name}/fid_scores.txt

Coding

If you would like to sample images programmatically, you can do so with the following simple ModelLoader class.

import torch
from torchvision.utils import save_image
from stylegan2_pytorch import ModelLoader

loader = ModelLoader(
    base_dir = '/path/to/directory',   # path to where you invoked the command line tool
    name = 'default'                   # the project name, defaults to 'default'
)

noise   = torch.randn(1, 512).cuda() # noise
styles  = loader.noise_to_styles(noise, trunc_psi = 0.7)  # pass through mapping network
images  = loader.styles_to_images(styles) # call the generator on intermediate style vectors

save_image(images, './sample.jpg') # save your images, or do whatever you desire

Logging to experiment tracker

To log the losses to an open source experiment tracker (Aim), you simply need to pass an extra flag like so.

$ stylegan2_pytorch --data ./data --log

Then, you need to make sure you have Docker installed. Following the instructions at Aim, you execute the following in your terminal.

$ aim up

Then open up your browser to the address and you should see

Experimental

Top-k Training for Generator

A new paper has produced evidence that by simply zero-ing out the gradient contributions from samples that are deemed fake by the discriminator, the generator learns significantly better, achieving new state of the art.

$ stylegan2_pytorch --data ./data --top-k-training

Gamma is a decay schedule that slowly decreases the topk from the full batch size to the target fraction of 50% (also modifiable hyperparameter).

$ stylegan2_pytorch --data ./data --top-k-training --generate-top-k-frac 0.5 --generate-top-k-gamma 0.99

Feature Quantization

A recent paper reported improved results if intermediate representations of the discriminator are vector quantized. Although I have not noticed any dramatic changes, I have decided to add this as a feature, so other minds out there can investigate. To use, you have to specify which layer(s) you would like to vector quantize. Default dictionary size is 256 and is also tunable.

# feature quantize layers 1 and 2, with a dictionary size of 512 each
# do not put a space after the comma in the list!
$ stylegan2_pytorch --data ./data --fq-layers [1,2] --fq-dict-size 512

Contrastive Loss Regularization

I have tried contrastive learning on the discriminator (in step with the usual GAN training) and possibly observed improved stability and quality of final results. You can turn on this experimental feature with a simple flag as shown below.

$ stylegan2_pytorch --data ./data --cl-reg

Relativistic Discriminator Loss

This was proposed in the Relativistic GAN paper to stabilize training. I have had mixed results, but will include the feature for those who want to experiment with it.

$ stylegan2_pytorch --data ./data --rel-disc-loss

Non-constant 4x4 Block

By default, the StyleGAN architecture styles a constant learned 4x4 block as it is progressively upsampled. This is an experimental feature that makes it so the 4x4 block is learned from the style vector w instead.

$ stylegan2_pytorch --data ./data --no-const

Dual Contrastive Loss

A recent paper has proposed that a novel contrastive loss between the real and fake logits can improve quality over other types of losses. (The default in this repository is hinge loss, and the paper shows a slight improvement)

$ stylegan2_pytorch --data ./data --dual-contrast-loss

Alternatives

Stylegan2 + Unet Discriminator

I have gotten really good results with a unet discriminator, but the architecturally change was too big to fit as an option in this repository. If you are aiming for perfection, feel free to try it.

If you would like me to give the royal treatment to some other GAN architecture (BigGAN), feel free to reach out at my email. Happy to hear your pitch.

Appreciation

Thank you to Matthew Mann for his inspiring simple port for Tensorflow 2.0

References

@article{Karras2019stylegan2,
    title   = {Analyzing and Improving the Image Quality of {StyleGAN}},
    author  = {Tero Karras and Samuli Laine and Miika Aittala and Janne Hellsten and Jaakko Lehtinen and Timo Aila},
    journal = {CoRR},
    volume  = {abs/1912.04958},
    year    = {2019},
}
@misc{zhao2020feature,
    title   = {Feature Quantization Improves GAN Training},
    author  = {Yang Zhao and Chunyuan Li and Ping Yu and Jianfeng Gao and Changyou Chen},
    year    = {2020}
}
@misc{chen2020simple,
    title   = {A Simple Framework for Contrastive Learning of Visual Representations},
    author  = {Ting Chen and Simon Kornblith and Mohammad Norouzi and Geoffrey Hinton},
    year    = {2020}
}
@article{,
    title     = {Oxford 102 Flowers},
    author    = {Nilsback, M-E. and Zisserman, A., 2008},
    abstract  = {A 102 category dataset consisting of 102 flower categories, commonly occuring in the United Kingdom. Each class consists of 40 to 258 images. The images have large scale, pose and light variations.}
}
@article{afifi201911k,
    title   = {11K Hands: gender recognition and biometric identification using a large dataset of hand images},
    author  = {Afifi, Mahmoud},
    journal = {Multimedia Tools and Applications}
}
@misc{zhang2018selfattention,
    title   = {Self-Attention Generative Adversarial Networks},
    author  = {Han Zhang and Ian Goodfellow and Dimitris Metaxas and Augustus Odena},
    year    = {2018},
    eprint  = {1805.08318},
    archivePrefix = {arXiv}
}
@article{shen2019efficient,
    author    = {Zhuoran Shen and
               Mingyuan Zhang and
               Haiyu Zhao and
               Shuai Yi and
               Hongsheng Li},
    title     = {Efficient Attention: Attention with Linear Complexities},
    journal   = {CoRR},  
    year      = {2018},
    url       = {http://arxiv.org/abs/1812.01243},
}
@article{zhao2020diffaugment,
    title   = {Differentiable Augmentation for Data-Efficient GAN Training},
    author  = {Zhao, Shengyu and Liu, Zhijian and Lin, Ji and Zhu, Jun-Yan and Han, Song},
    journal = {arXiv preprint arXiv:2006.10738},
    year    = {2020}
}
@misc{zhao2020image,
    title  = {Image Augmentations for GAN Training},
    author = {Zhengli Zhao and Zizhao Zhang and Ting Chen and Sameer Singh and Han Zhang},
    year   = {2020},
    eprint = {2006.02595},
    archivePrefix = {arXiv}
}
@misc{karras2020training,
    title   = {Training Generative Adversarial Networks with Limited Data},
    author  = {Tero Karras and Miika Aittala and Janne Hellsten and Samuli Laine and Jaakko Lehtinen and Timo Aila},
    year    = {2020},
    eprint  = {2006.06676},
    archivePrefix = {arXiv},
    primaryClass = {cs.CV}
}
@misc{jolicoeurmartineau2018relativistic,
    title   = {The relativistic discriminator: a key element missing from standard GAN},
    author  = {Alexia Jolicoeur-Martineau},
    year    = {2018},
    eprint  = {1807.00734},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG}
}
@misc{sinha2020topk,
    title   = {Top-k Training of GANs: Improving GAN Performance by Throwing Away Bad Samples},
    author  = {Samarth Sinha and Zhengli Zhao and Anirudh Goyal and Colin Raffel and Augustus Odena},
    year    = {2020},
    eprint  = {2002.06224},
    archivePrefix = {arXiv},
    primaryClass = {stat.ML}
}
@misc{yu2021dual,
    title   = {Dual Contrastive Loss and Attention for GANs},
    author  = {Ning Yu and Guilin Liu and Aysegul Dundar and Andrew Tao and Bryan Catanzaro and Larry Davis and Mario Fritz},
    year    = {2021},
    eprint  = {2103.16748},
    archivePrefix = {arXiv},
    primaryClass = {cs.CV}
}

stylegan2-pytorch's People

Contributors

anomal avatar cannon avatar dmd avatar getseclectic avatar lucidrains avatar netruk44 avatar niansa avatar rvdmaazen 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  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

stylegan2-pytorch's Issues

Add TPU support

I feel like this project should have a way to use a TPU instead of a GPU.

One usage example would be on Google Colab.

Torch optimizer error *novice*

Hey!

I get this message when I try to install the repository; "ERROR: torch-optimizer 0.0.1a11 has requirement torch>=1.1.0, but you'll have torch 0.1.2.post2 which is incompatible."

I'm an absolute novice at this, but I'd really like to learn through something I'm interested in; Can any of you folks help me with this?

Thanks in advance!

Generating faces

Hello,
I tried to train a model on 70k images of the FFHQ thumbnail dataset. The model should generate 128x128 images of faces, unfortunately, the results are not very convincing. I left all the parameters at there default value and trained over 500000 iterations. After 530000 iterations I stopped the training because the results started to decrease and the discriminator loss was 0 or close to 0.

Here are the results

What would be the best way to improve the results?
-Train on high-resolution images
-Use different training parameters
-Use more images

Some information about training in the README.md

It'd be nice to have some details about how the example results were trained. In particular, I'd be interested to see:

  • Were they trained with the default training parameters?
  • How many epochs?
  • How long did it take on what type of hardware?
  • How big were the datasets?

Thanks so much!

What does "ema" and "mr" mean in simple terms?

I'm trying to understand what these things mean, but I'm really not an expert in the theory of machine learning, it's more like an application-level interest for me. I know they stand for "something moving average" and "mixed regularity" Could you explain it in simple terms so I know a bit more about the outputs?

Sometimes it seems like these images are actually better than the "normal" one.

Pickle error

I'm trying to run the command as specified in the documentation but I keep getting this error regardless of the PyTorch version installed:

Traceback (most recent call last):
File "C:/Python36/Scripts/stylegan2_pytorch", line 66, in
fire.Fire(train_from_folder)
File "C:\python36\lib\site-packages\fire\core.py", line 138, in Fire
component_trace = _Fire(component, args, parsed_flag_args, context, name)
File "C:\python36\lib\site-packages\fire\core.py", line 468, in _Fire
target=component.name)
File "C:\python36\lib\site-packages\fire\core.py", line 672, in _CallAndUpdateTrace
component = fn(*varargs, **kwargs)
File "C:/Python36/Scripts/stylegan2_pytorch", line 61, in train_from_folder
retry_call(model.train, tries=3, exceptions=NanException)
File "C:\python36\lib\site-packages\retry\api.py", line 101, in retry_call
return __retry_internal(partial(f, *args, **kwargs), exceptions, tries, delay, max_delay, backoff, jitter, logger)
File "C:\python36\lib\site-packages\retry\api.py", line 33, in __retry_internal
return f()
File "C:\python36\lib\site-packages\stylegan2_pytorch\stylegan2_pytorch.py", line 529, in train
image_batch = next(self.loader).cuda()
File "C:\python36\lib\site-packages\stylegan2_pytorch\stylegan2_pytorch.py", line 63, in cycle
for i in iterable:
File "C:\python36\lib\site-packages\torch\utils\data\dataloader.py", line 278, in iter
return _MultiProcessingDataLoaderIter(self)
File "C:\python36\lib\site-packages\torch\utils\data\dataloader.py", line 682, in init
w.start()
File "C:\python36\lib\multiprocessing\process.py", line 105, in start
self._popen = self._Popen(self)
File "C:\python36\lib\multiprocessing\context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:\python36\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "C:\python36\lib\multiprocessing\popen_spawn_win32.py", line 65, in init
reduction.dump(process_obj, to_child)
File "C:\python36\lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'expand_greyscale..inner'

another problem in installing in windows ( for a newbie)

Hi
I use conda environment in windows.
According to the readme file, after installing torch and torchvision, i used the command
conda install stylegan2_pytorch but it didn't work. because "stylegan2_pytorch" is not in conda reops. I used pip install stylegan2_pytorch instead. and it worked.
After that, I use stylegan2_pytorch --data /path/to/images command. But error " 'stylegan2_pytorch' is not recognized as an internal or external command operable program or batch file."
Then i cloned the whole repo and moved to that folder. I ran the same command and the same error appeared.
Then i examined python stylegan2_pytorch --data /path/to/images error
"C:\Users\ASUS\Miniconda3\envs\SimpleStyleGan\python.exe: can't find 'main' module in 'stylegan2_pytorch'" appeared.
Then i moved exactly to where two init a and main python files are stored and then run the same command. another error:
"can't open file 'stylegan2_pytorch': [Errno 2] No such file or directory"
finally i used this command:
python -m stylegan2_pytorch --data /path/to/images and no error appeared. But nothing happens and command finishes without any progress or etc!
Sorry for long writing and bad language. The progress in readme seems very straightforward but for me is not. I need more help to run this.
Thanks.

Jetson Nano / minimal requirements?

Hi there,

I bought a Jetson Nano for experimentation and an arts project and would like to run the script. After some fiddling I managed to install the script, but I get out of memory errors. Is there some minimum necessary RAM (4GB on the nano), or should a big swap suffice?

Thnx!

OSError: Caught OSError in DataLoader worker process 0 / image file is truncated (1 bytes not processed)

This is very fun to play with - thanks for making it so easy to set up! I've been training it for an hour or so and it's already generating some interesting results. I have no experience with pytorch or GANs (and barely any python experience) so your motto "simplest working implementation" definitely rings true for me - only took a couple of minutes (mainly sorting out docker) for me to get up and running.

Okay, on to the bug report. I got the following error after about 10k images processed:

G: 2.58 | D: 1.06 | GP: 0.00 | PL: 0.73
 10%|#########2                                 | 10449/100000 [1:56:39<15:46:03,  1.58it/s]G: 1.87 | D: 1.53 | GP: 0.00 | PL: 0.73
 10%|#########3                                 | 10497/100000 [1:57:09<15:46:00,  1.58it/s]G: 1.06 | D: 1.14 | GP: 0.00 | PL: 0.72
Traceback (most recent call last):
  File "/home/user/miniconda/envs/py36/bin/stylegan2_pytorch", line 53, in <module>
    fire.Fire(train_from_folder)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/fire/core.py", line 138, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/fire/core.py", line 471, in _Fire
    target=component.__name__)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/fire/core.py", line 675, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/home/user/miniconda/envs/py36/bin/stylegan2_pytorch", line 48, in train_from_folder
    model.train()
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 441, in train
    image_batch = next(self.loader).cuda()
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 74, in cycle
    for i in iterable:
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 345, in __next__
    data = self._next_data()
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 856, in _next_data
    return self._process_data(data)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 881, in _process_data
    data.reraise()
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/_utils.py", line 394, in reraise
    raise self.exc_type(msg)
OSError: Caught OSError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 129, in __getitem__
    return self.transform(img)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 70, in __call__
    img = t(img)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 687, in __call__
    return F.resized_crop(img, i, j, h, w, self.size, self.interpolation)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torchvision/transforms/functional.py", line 407, in resized_crop
    img = crop(img, top, left, height, width)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torchvision/transforms/functional.py", line 367, in crop
    return img.crop((left, top, left + width, top + height))
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/PIL/Image.py", line 1105, in crop
    self.load()
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/PIL/ImageFile.py", line 247, in load
    "(%d bytes not processed)" % len(b)
OSError: image file is truncated (1 bytes not processed)

 10%|#########3                              | 10497/100000 [1:57:15<16:39:48,  1.49it/s]

Here are my reproduction steps:

sudo docker run --gpus all --rm -it anibali/pytorch:cuda-10.1 bash
# Use `docker cp` to copy images across to container: sudo docker cp /home/joe/Downloads/images container_name:/app/images
pip install stylegan2_pytorch
stylegan2_pytorch --data ./images

Is this error perhaps caused by a corrupt image file? If so, maybe corrupt images could be skipped? Or the path of the image could be logged?

According to ImageMagic's identify command, all 100k images are valid jpgs. Tested using this command (from here):

for f in /home/joe/Downloads/images/*.jpg ; do identify $f > /dev/null || echo $f >> /tmp/fail ; done ; cat /tmp/fail

Here's the output of the file command for one of the images (they're all the same size and type):

JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 1024x1024, components 3

I've started the processing again with stylegan2_pytorch --data ./images, and it's at 3k images processed (out of 90k - so I'm guessing checkpoints are every 10k images?), and no error yet. Will update this if I get another error. Should only be an hour or so until it has passed the 10k mark again.

Also, a separate, minor thing is that I noticed that it doesn't work for smaller images:

sudo docker run --gpus all --rm -it anibali/pytorch:cuda-10.1 bash
sudo curl https://raw.githubusercontent.com/myleott/mnist_png/master/mnist_png.tar.gz > mnist_png.tar.gz
tar -xvzf mnist_png.tar.gz
pip install stylegan2_pytorch
stylegan2_pytorch --data ./mnist_png

That results in this:

  0%|                                                                                                | 0/100000 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "/home/user/miniconda/envs/py36/bin/stylegan2_pytorch", line 53, in <module>
    fire.Fire(train_from_folder)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/fire/core.py", line 138, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/fire/core.py", line 471, in _Fire
    target=component.__name__)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/fire/core.py", line 675, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/home/user/miniconda/envs/py36/bin/stylegan2_pytorch", line 48, in train_from_folder
    model.train()
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 443, in train
    real_output = self.GAN.D(image_batch)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 324, in forward
    x = self.blocks(x)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/nn/modules/container.py", line 100, in forward
    input = module(input)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 254, in forward
    res = self.conv_res(x)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 345, in forward
    return self.conv2d_forward(input, self.weight)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 342, in conv2d_forward
    self.padding, self.dilation, self.groups)
RuntimeError: Given groups=1, weight of size 16 3 1 1, expected input[3, 1, 128, 128] to have 3 channels, but got 1 channels instead

Maybe the images could be scaled up (I'm guessing 128x128 is the minimum?), or a better error message could be added?

Thanks again for this! Having a bunch of fun with it :)

Help generating images

My project finished training (completed at 100%), I can see all the generated images in the correct folders (yeah I ran them inside the bin folder).

But when I try to generate, it fails:

C:\Users\luiss\DevStuff\stylegan\bin>py stylegan2_pytorch --generate
continuing from previous epoch - 9
Traceback (most recent call last):
  File "stylegan2_pytorch", line 56, in <module>
    fire.Fire(train_from_folder)
  File "C:\Users\luiss\AppData\Local\Programs\Python\Python37\lib\site-packages\fire\core.py", line 138, in Fire        component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "C:\Users\luiss\AppData\Local\Programs\Python\Python37\lib\site-packages\fire\core.py", line 471, in _Fire       target=component.__name__)
  File "C:\Users\luiss\AppData\Local\Programs\Python\Python37\lib\site-packages\fire\core.py", line 675, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "stylegan2_pytorch", line 44, in train_from_folder
    model.evaluate(samples_name)
  File "C:\Users\luiss\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\autograd\grad_mode.py", line 49, in decorate_no_grad
    return func(*args, **kwargs)
  File "C:\Users\luiss\AppData\Local\Programs\Python\Python37\lib\site-packages\stylegan2_pytorch\stylegan2_pytorch.py", line 589, in evaluate
    torchvision.utils.save_image(generated_images, str(self.results_dir / self.name / f'{str(num)}.jpg'), nrow=num_rows)
  File "C:\Users\luiss\AppData\Local\Programs\Python\Python37\lib\site-packages\torchvision\utils.py", line 109, in save_image
    im.save(fp, format=format)
  File "C:\Users\luiss\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL\Image.py", line 2099, in save       fp = builtins.open(filename, "w+b")
OSError: [Errno 22] Invalid argument: 'results\\default\\generated-02-21-2020_09:01:40.jpg'

any ideas?

Parameters for Memory Considerations

In the section called "Memory Considerations", you mention 3 parameters:

$ stylegan2_pytorch --data /path/to/data \
    --batch-size 3 \
    --gradient-accumulate-every 5 \
    --network-capacity 16

I would like to know the equivalent parameters in the original StyleGAN2 repository.

For instance, in training_loop.py, I can see:

def training_schedule(
   # [...]
    minibatch_size_base     = 32,       # Global minibatch size.
   # [...]
    minibatch_gpu_base      = 4,        # Number of samples processed at a time by one GPU.
   # [...]
def training_loop(
   # [...]
    minibatch_repeats       = 4,        # Number of minibatches to run before adjusting training parameters.
   # [...]
    G_reg_interval          = 4,        # How often the perform regularization for G? Ignored if lazy_regularization=False.
    D_reg_interval          = 16,       # How often the perform regularization for D? Ignored if lazy_regularization=False.
   # [...]

I wonder whether:

  • batch-size is the equivalent of minibatch_gpu_base,
  • gradient-accumulate-every is the equivalent of minibatch_repeats,
  • network-capacity is the equivalent of minibatch_size_base.

These are blind guesses based on the default values and the suggested values.

I think it would be interesting to draw a parallel between the two implementations.

Unable to run command line argument

Hi, do help me with running the, 'stylegan2-pytorch --data /path'. I am unable to find in the code the options for arguments and not can I run it.

Issue running the code with the --generate label

Hi, I am training an agent to generate 512x512 images and I am trying to display intermediate results using the --generate flag. It looks like something is off (see errors here). Am I doing something wrong? The command I use is stylegan2_pytorch --generate.

meaningless results for road image generation

image
I have trained for 50 epochs on a dataset with 1350 pics, the training data look like the right part of this picture.
However, the intermediate results (left part of the picture) looks awful. I'm wondering if that stylegan can only generate highly-structured pics?
Thanks in advance.

How to run the .pt?

Hi, congrats for the nice work! I'm trying your code and I was wondering whether you have any suggestion on how to run the .pt snapshot files and generate some test images. Thanks!

Memory error during install

Hello
if i want to install stylegan2 the installation always fills up the RAM and swap file after almost downloading the second file
"https://files.pythonhosted.org/packages/46/ca/306bb933a68b888ab1c20ede0342506b85857635f04fb55a56e53065579b/torch-1.4.0-cp27-cp27mu-manylinux1_x86_64.whl"

at 99 % I can see that the installation process fills up the RAM to 90 % and the swap to 80 %.

After hours being in this state, it gave me a memory error.
Sadly I did not copy the code (It was late and I was frustrated ;) ) I will reply it if necessary.

But my first thought was:
Is there a maybe minimum memory requirement for stylegen2?

My system is a Xubuntu 19.04, I have 4 GB of RAM and 8 GB of Swap.
Maybe that is too less and that's why it crashes

Resizing of photos

What happens to non-square photos? Are they cut off at the sides where they are longer, are they resized without respect to aspect ratio or is it conserved by adding black/white bars?

Possible to safe more often?

Loving this repo, thank you!

I'm running it on Google Colab, but it hasn't been super stable. Sometimes it crashes right before the 10000 save. If I lower that number in the code would it also create more models?
SAVE_EVERY = 10000

Generate with project name

Hello!
quick question, when generating the results, how can I tell it to use the models from certain project? When training I can define a project name, but how about when generating stylegan2_pytorch --generate --name projectName?

thanks

Generate only 1 image

Would it be possible to generate only 1 image? similar to what thispersondoesnotexist.com does it?

I'm still training atm, but I figured the end result of the generation of images, is 8x8 collage of images, am I right?

Model collapse help

I know that this is a very tricky problem but I am hoping that maybe you will have some advice. I have been trying to no avail to train a GAN which will generate maps, training on OpenStreetMap tiles.

I have just over 40k images of maps, focused loosely on small towns and villages in Germany. Soem example images are below:

BB000000066
BB000000146
BB000000217
BB000000254
BB000000314
BB000000504
BB000000676
BB000000775
BB000000873

However, it seems that no matter what I try, the model begins to collapse around 70k iterations. Originally I thought the problem was too much variation in the data, that's why I focused mainly on small towns, since they mostly have some buildings and streets nearby.

Here is an example of the progression of the model as it is collapsing:

Iteration 30k:
30

Iteration 40k:
40

Iteration 50k:
49

Iteration 60k:
60

Iteration 70k:
70

It seems to peak rather consistently around 50k iterations, but it's just not quite able to make results that are sufficiently convincing to me (I know that I will never get perfection, with proper letters and all, but I was hoping for crisper definitions of buildings and streets at least!)

Do you have any ideas on what might help? If you want, I could give you access to my source data folder if you wanted to look at it in closer detail

Saving of models

Am I correct in the assumption that the save models get updated all the time and not just when saving and this save is just the creation of a permanent and non-changing model? Or is everything happening from the start to the first save point, 1000 by default I think, gone to waste if I were to stop it before reaching this mark?

What do the output letters signify?

What do the letters "G", "D", "GP" and "PL" in the output signify?

0% 0/90000 [00:00<?, ?it/s]G: 1.51 | D: 0.21 | GP: 0.00 | PL: 0.00
0% 49/90000 [02:46<81:43:57,  3.27s/it]G: 2.06 | D: 0.05 | GP: 0.50 | PL: 0.02
0% 97/90000 [05:04<71:55:48,  2.88s/it]G: 1.63 | D: 0.00 | GP: 0.00 | PL: 0.03
0% 149/90000 [07:35<72:52:45,  2.92s/it]G: 1.04 | D: 0.12 | GP: 0.00 | PL: 0.03

num_samples should be a positive integer value, but got num_samples=0

Steps to reproduce:

sudo docker run --gpus all --rm -it anibali/pytorch:cuda-10.1 bash
# Use `docker cp` to copy images across to container: sudo docker cp /path/to/images container_name:/app/images
pip install stylegan2_pytorch
stylegan2_pytorch --data ./images

Then, after 10k images processed of 100k total, I ran this:

stylegan2_pytorch --generate

and I got this error:

Traceback (most recent call last):
  File "/home/user/miniconda/envs/py36/bin/stylegan2_pytorch", line 55, in <module>
    fire.Fire(train_from_folder)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/fire/core.py", line 138, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/fire/core.py", line 471, in _Fire
    target=component.__name__)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/fire/core.py", line 675, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/home/user/miniconda/envs/py36/bin/stylegan2_pytorch", line 33, in train_from_folder
    num_workers = num_workers
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 406, in __init__
    self.loader = cycle(data.DataLoader(self.dataset, num_workers = default(num_workers, num_cores), batch_size = batch_size, drop_last = True, shuffle=True, pin_memory=True))
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 213, in __init__
    sampler = RandomSampler(dataset)
  File "/home/user/miniconda/envs/py36/lib/python3.6/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

The images being trained are 1024x1024. The images in ./results/default are being generated correctly (it's up to 10.jpg after 10k images processed), and training seems to be proceeding with no problems. The ./models/default folder contains model_0.pt and model_1.pt.

Thanks!

Error information

I just got this Error:

return self.lambd(img)
  File "/usr/local/lib/python3.6/dist-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 114, in expand_to_rgb
    return tensor.expand(3, -1, -1)
RuntimeError: The expanded size of the tensor (3) must match the existing size (2) at non-singleton dimension 0.  Target sizes: [3, -1, -1].  Tensor sizes: [2, 128, 128]

I suspect it comes from a picture that does not have 3 channels but 2, from the last line. But that seems strange to me so I wanted to ask what you believe is causing this.

name 'tqdm' is not defined

I am trying to go through the training process in a Google Colab just to get a basic workflow going from start to finish with some dummy images.

I run the commands in this order:

!pip install stylegan2_pytorch
!stylegan2_pytorch --data imgs/

But it immediately throws NameError: name 'tqdm' is not defined

I tried to install tqdm with !pip install tqdm, but it tells me that the requirement is already satisfied.

Any ideas?

Full stacktrace:

Traceback (most recent call last):
  File "/usr/local/bin/stylegan2_pytorch", line 36, in <module>
    fire.Fire(train_from_folder)
  File "/usr/local/lib/python3.6/dist-packages/fire/core.py", line 138, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/usr/local/lib/python3.6/dist-packages/fire/core.py", line 471, in _Fire
    target=component.__name__)
  File "/usr/local/lib/python3.6/dist-packages/fire/core.py", line 675, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/usr/local/bin/stylegan2_pytorch", line 30, in train_from_folder
    for _ in tqdm(range(num_train_steps - model.steps), mininterval=10.):
NameError: name 'tqdm' is not defined

If it helps, this is the output from running !pip install stylegan2_pytorch:

  Downloading https://files.pythonhosted.org/packages/c7/31/9bf4e412d3da8aa8b23a2f8ed3b6443f74e7d12be33e01e72df3c7a59794/stylegan2_pytorch-0.3.tar.gz
Collecting fire
  Downloading https://files.pythonhosted.org/packages/d9/69/faeaae8687f4de0f5973694d02e9d6c3eb827636a009157352d98de1129e/fire-0.2.1.tar.gz (76kB)
     |████████████████████████████████| 81kB 5.7MB/s 
Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from stylegan2_pytorch) (1.17.5)
Requirement already satisfied: tqdm in /usr/local/lib/python3.6/dist-packages (from stylegan2_pytorch) (4.28.1)
Requirement already satisfied: torch in /usr/local/lib/python3.6/dist-packages (from stylegan2_pytorch) (1.3.1)
Requirement already satisfied: torchvision in /usr/local/lib/python3.6/dist-packages (from stylegan2_pytorch) (0.4.2)
Requirement already satisfied: pillow in /usr/local/lib/python3.6/dist-packages (from stylegan2_pytorch) (6.2.2)
Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from fire->stylegan2_pytorch) (1.12.0)
Requirement already satisfied: termcolor in /usr/local/lib/python3.6/dist-packages (from fire->stylegan2_pytorch) (1.1.0)
Building wheels for collected packages: stylegan2-pytorch, fire
  Building wheel for stylegan2-pytorch (setup.py) ... done
  Created wheel for stylegan2-pytorch: filename=stylegan2_pytorch-0.3-cp36-none-any.whl size=7858 sha256=3e661430b2eecc2c0cf022ba6cdd78effbf0eac81915a3933c0035312e1f9e76
  Stored in directory: /root/.cache/pip/wheels/31/f6/3e/7fe4757e5f068d2cdc8a5ec79013e08c159cdd01c8efe32af5
  Building wheel for fire (setup.py) ... done
  Created wheel for fire: filename=fire-0.2.1-py2.py3-none-any.whl size=103527 sha256=f9ac6fcada01d33b0505fac6c7914890b51fce53465475feb5b41549555d948d
  Stored in directory: /root/.cache/pip/wheels/31/9c/c0/07b6dc7faf1844bb4688f46b569efe6cafaa2179c95db821da
Successfully built stylegan2-pytorch fire
Installing collected packages: fire, stylegan2-pytorch
Successfully installed fire-0.2.1 stylegan2-pytorch-0.3

Won't install on Windows

Hi I have a working installation of CUDA on windows. I tried to pip install in a fresh conda environment and this is the error:
`Building wheel for torch (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: 'C:\Users\Windows.conda\envs\sg2pt\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\Windows\AppData\Local\Temp\pip-install-z52d0319\torch\setup.py'"'"'; file='"'"'C:\Users\Windows\AppData\Local\Temp\pip-install-z52d0319\torch\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\Windows\AppData\Local\Temp\pip-wheel-qnj_g1p4'
cwd: C:\Users\Windows\AppData\Local\Temp\pip-install-z52d0319\torch
Complete output (30 lines):
running bdist_wheel
running build
running build_deps
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Windows\AppData\Local\Temp\pip-install-z52d0319\torch\setup.py", line 265, in
description="Tensors and Dynamic neural networks in Python with strong GPU acceleration",
File "C:\Users\Windows.conda\envs\sg2pt\lib\site-packages\setuptools_init_.py", line 145, in setup
return distutils.core.setup(**attrs)
File "C:\Users\Windows.conda\envs\sg2pt\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Users\Windows.conda\envs\sg2pt\lib\distutils\dist.py", line 966, in run_commands
self.run_command(cmd)
File "C:\Users\Windows.conda\envs\sg2pt\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\Windows.conda\envs\sg2pt\lib\site-packages\wheel\bdist_wheel.py", line 223, in run
self.run_command('build')
File "C:\Users\Windows.conda\envs\sg2pt\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Users\Windows.conda\envs\sg2pt\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\Windows.conda\envs\sg2pt\lib\distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "C:\Users\Windows.conda\envs\sg2pt\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Users\Windows.conda\envs\sg2pt\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\Windows\AppData\Local\Temp\pip-install-z52d0319\torch\setup.py", line 51, in run
from tools.nnwrap import generate_wrappers as generate_nn_wrappers
ModuleNotFoundError: No module named 'tools.nnwrap'

ERROR: Failed building wheel for torch
Running setup.py clean for torch
ERROR: Command errored out with exit status 1:
command: 'C:\Users\Windows.conda\envs\sg2pt\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\Windows\AppData\Local\Temp\pip-install-z52d0319\torch\setup.py'"'"'; file='"'"'C:\Users\Windows\AppData\Local\Temp\pip-install-z52d0319\torch\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' clean --all
cwd: C:\Users\Windows\AppData\Local\Temp\pip-install-z52d0319\torch
Complete output (2 lines):
running clean
error: [Errno 2] No such file or directory: '.gitignore'

ERROR: Failed cleaning build dir for torch
Building wheel for torch-optimizer (setup.py) ... done
Created wheel for torch-optimizer: filename=torch_optimizer-0.0.1a3-py3-none-any.whl size=27775 sha256=51d63835d9fc64c5405d1f78d9e80833dfee80060c47c02efb5f3a0184ba251f
Stored in directory: c:\users\windows\appdata\local\pip\cache\wheels\5a\8d\dd\ef34a7144ff43ca2c8ae6d58c147d760e77732c71702d63d17
Successfully built stylegan2-pytorch fire torch-optimizer
Failed to build torch
ERROR: torchvision 0.5.0 has requirement torch==1.4.0, but you'll have torch 0.1.2.post2 which is incompatible.
ERROR: torch-optimizer 0.0.1a3 has requirement torch>=1.1.0, but you'll have torch 0.1.2.post2 which is incompatible.
Installing collected packages: six, termcolor, fire, numpy, tqdm, pyyaml, torch, pillow, torchvision, torch-optimizer, stylegan2-pytorch
Running setup.py install for torch ... error
ERROR: Command errored out with exit status 1:
command: 'C:\Users\Windows.conda\envs\sg2pt\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\Windows\AppData\Local\Temp\pip-install-z52d0319\torch\setup.py'"'"'; file='"'"'C:\Users\Windows\AppData\Local\Temp\pip-install-z52d0319\torch\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\Windows\AppData\Local\Temp\pip-record-hsissqb0\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\Windows.conda\envs\sg2pt\Include\torch'
cwd: C:\Users\Windows\AppData\Local\Temp\pip-install-z52d0319\torch
Complete output (23 lines):
running install
running build_deps
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Windows\AppData\Local\Temp\pip-install-z52d0319\torch\setup.py", line 265, in
description="Tensors and Dynamic neural networks in Python with strong GPU acceleration",
File "C:\Users\Windows.conda\envs\sg2pt\lib\site-packages\setuptools_init_.py", line 145, in setup
return distutils.core.setup(**attrs)
File "C:\Users\Windows.conda\envs\sg2pt\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Users\Windows.conda\envs\sg2pt\lib\distutils\dist.py", line 966, in run_commands
self.run_command(cmd)
File "C:\Users\Windows.conda\envs\sg2pt\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\Windows\AppData\Local\Temp\pip-install-z52d0319\torch\setup.py", line 99, in run
self.run_command('build_deps')
File "C:\Users\Windows.conda\envs\sg2pt\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Users\Windows.conda\envs\sg2pt\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\Windows\AppData\Local\Temp\pip-install-z52d0319\torch\setup.py", line 51, in run
from tools.nnwrap import generate_wrappers as generate_nn_wrappers
ModuleNotFoundError: No module named 'tools.nnwrap'
----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\Windows.conda\envs\sg2pt\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\Windows\AppData\Local\Temp\pip-install-z52d0319\torch\setup.py'"'"'; file='"'"'C:\Users\Windows\AppData\Local\Temp\pip-install-z52d0319\torch\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\Windows\AppData\Local\Temp\pip-record-hsissqb0\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\Windows.conda\envs\sg2pt\Include\torch' Check the logs for full command output.`

completely new to this, I have GitHub, python and pip, need help

Hey, I only have a little coding experience but I'm trying this out. I have a virtualenv open and I did the first command but it comes up as "ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'". I have the requirements file in the same place as where I originally downloaded it, am I doing something wrong? on Mac

RuntimeError: Given groups=1, weight of size 16 3 1 1, expected input[3, 1, 128, 128] to have 3 channels, but got 1 channels instead

(Originally included this in my other issue, but figured it would make more sense to give it its own issue.)

It seems like training on smaller images still doesn't work? I just ran this:

sudo docker run --gpus all --rm -it anibali/pytorch:cuda-10.1 bash
sudo curl https://raw.githubusercontent.com/myleott/mnist_png/master/mnist_png.tar.gz > mnist_png.tar.gz
tar -xvzf mnist_png.tar.gz
pip install stylegan2_pytorch
stylegan2_pytorch --data ./mnist_png

and got this:

  0%|                                                | 0/100000 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "/home/user/miniconda/envs/py36/bin/stylegan2_pytorch", line 55, in <module>
    fire.Fire(train_from_folder)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/fire/core.py", line 138, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/fire/core.py", line 471, in _Fire
    target=component.__name__)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/fire/core.py", line 675, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/home/user/miniconda/envs/py36/bin/stylegan2_pytorch", line 50, in train_from_folder
    model.train()
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 452, in train
    real_output = self.GAN.D(image_batch)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 331, in forward
    x = self.blocks(x)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/nn/modules/container.py", line 100, in forward
    input = module(input)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 261, in forward
    res = self.conv_res(x)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 345, in forward
    return self.conv2d_forward(input, self.weight)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 342, in conv2d_forward
    self.padding, self.dilation, self.groups)
RuntimeError: Given groups=1, weight of size 16 3 1 1, expected input[3, 1, 128, 128] to have 3 channels, but got 1 channels instead

I also tested this on 72x72 pngs from here: https://github.com/twitter/twemoji/tree/master/assets/72x72 and got the same error message.

Thanks!

TypeError: sum() received an invalid combination of arguments

When I try to run this repository using the command,
$ stylegan2_pytorch --data /path/to/images
it failed with the following error.
I am wondered whether the input image size must be 1024*1024 in a square shape. May I use the rectangle image, and whether the rectangle image causes the error?
Looking forward to your reply. Thx very much for the repo.

Traceback (most recent call last):
File "/home/sunyu/.local/bin/stylegan2_pytorch", line 59, in
fire.Fire(train_from_folder)
File "/home/sunyu/.local/lib/python3.7/site-packages/fire/core.py", line 138, in Fire
component_trace = _Fire(component, args, parsed_flag_args, context, name)
File "/home/sunyu/.local/lib/python3.7/site-packages/fire/core.py", line 471, in _Fire
target=component.name)
File "/home/sunyu/.local/lib/python3.7/site-packages/fire/core.py", line 675, in _CallAndUpdateTrace
component = fn(*varargs, **kwargs)
File "/home/sunyu/.local/bin/stylegan2_pytorch", line 54, in train_from_folder
model.train()
File "/home/sunyu/.local/lib/python3.7/site-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 488, in train
generated_images = self.GAN.G(w_styles, noise).detach()
File "/home/env/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(*input, **kwargs)
File "/home/sunyu/.local/lib/python3.7/site-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 310, in forward
x, rgb = block(x, rgb, style, input_noise)
File "/home/env/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(*input, **kwargs)
File "/home/sunyu/.local/lib/python3.7/site-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 244, in forward
x = self.conv1(x, style1)
File "/home/env/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(*input, **kwargs)
File "/home/sunyu/.local/lib/python3.7/site-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 205, in forward
d = torch.rsqrt((weights ** 2).sum(dim=(2, 3, 4), keepdims=True) + EPS)
TypeError: sum() received an invalid combination of arguments - got (keepdims=bool, dim=tuple, ), but expected one of:

  • ()
  • (torch.dtype dtype)
  • (tuple of ints dim, torch.dtype dtype)
    didn't match because some of the keywords were incorrect: keepdims
  • (tuple of ints dim, bool keepdim, torch.dtype dtype)
  • (tuple of ints dim, bool keepdim)
    didn't match because some of the keywords were incorrect: keepdims

Sample diversity

Hello!
Thank you for your work.

I have trained the model on FFHQ 1024x1024 dataset (parameters: --batch-size 2 --gradient-accumulate-every 7 --network-capacity 16 --image-size 256)

The output looks really good. However the same faces with little variation tend to appear several times (mode collapse)? It rarely generates Asian or Black faces for example.

Is there a way to increase this diversity ? Or is it just because of the dataset ? I was surprised to see a blue haired woman generated on thispersondoesnotexist.com website, which would be very rare in most datasets.

159-ema

Training with two classes of data in order to improve quality

Say you had a dataset of 50K images split evenly between two boolean classes: E.g.
looks_good=True or looks_good=False

Since GANs appear to only train on one class of the dataset (looks_good=True in this case):

  1. Can you increase the GAN output quality subjectively, biasing the discriminator with a robust looks_good=False dataset?
  2. Or would you just train the GAN maximally, then train a second model to be an image classifier like ResNet with Imagenet weights on the 50k original samples, then pit this up against the GAN generations in a loop, only sampling looks_good=True with high probabilities?

The looks_good=False dataset would contain regular images and also maybe GAN generations that that did not yield satisfactory output.

Thanks for answering all of these questions. Learning a lot through this project!

Will training pick up where it left off?

I'm using Google Colab and from what I understand, VMs are recycled after something like 10 hours of inactivity. But by my calculations I'm going to need at least 30. If I save the content of the "models/default" folder, will it pick back up again where it started rather than starting again?

Starting stylegan2-pytorch on Windows

I installed pytorch and torchvision with conda, then installed stylegan2-pytorch with pip. How do I invoke the program?

Windows cannot find it:

>stylegan2_pytorch
'stylegan2_pytorch' is not recognized as an internal or external command,
operable program or batch file.

This isn't working for me either:

>python -m stylegan2_pytorch
C:\Users\Username\miniconda3\python.exe: No module named stylegan2_pytorch.__main__; 'stylegan2_pytorch' is a package and cannot be directly executed

The binary in the Scripts folder doesn't seem to work either:

>C:\Users\Username\miniconda3\Scripts\stylegan2_pytorch
'C:\Users\Username\miniconda3\Scripts\stylegan2_pytorch' is not recognized as an internal or external command,
operable program or batch file.

What's the proper way to run it?

Cannot run on windows

I always get the error message

'stylegan2_pytorch' is not recognized as an internal or external command,
operable program or batch file.

although it definitely is in my path.

Trouble finding out command-line arguments

I see in the README that there are command-line arguments, such as image-size, and I would like to find out the exhaustive list of possible command-line arguments.

However, I have a bit of trouble understanding the code in stylegan2_pytorch.py. I don't see any main() function. I am familiar with Python, but it seems that you are using it in a way which I don't know about, with that binary file in bin/.

Could you point out where I should look at?

Size mismatch issue when using --image_size != 128

When I run stylegan2_pytorch with the option --image_size set to a value different from 128, I get a set of size mismatch errors. I might be wrong, but I suspect the parameters of the architecture of the generator (and potentially of the discriminator) is static and does not scale with the desired image size?

Here is an example of the errors I get:

        size mismatch for GE.blocks.2.to_noise2.weight: copying a param with shape torch.Size([256, 1]) from checkpoint, the shape in current model is torch.Size([1024, 1]).
        size mismatch for GE.blocks.2.to_noise2.bias: copying a param with shape torch.Size([256]) from checkpoint, the shape in current model is torch.Size([1024]).
        size mismatch for GE.blocks.2.conv2.weight: copying a param with shape torch.Size([256, 256, 3, 3]) from checkpoint, the shape in current model is torch.Size([1024, 1024, 3, 3]).
        size mismatch for GE.blocks.2.to_rgb.to_style.weight: copying a param with shape torch.Size([256, 512]) from checkpoint, the shape in current model is torch.Size([1024, 512]).
        size mismatch for GE.blocks.2.to_rgb.to_style.bias: copying a param with shape torch.Size([256]) from checkpoint, the shape in current model is torch.Size([1024]).
        size mismatch for GE.blocks.2.to_rgb.conv.weight: copying a param with shape torch.Size([3, 256, 1, 1]) from checkpoint, the shape in current model is torch.Size([3, 1024, 1, 1]).
        size mismatch for GE.blocks.3.to_style1.weight: copying a param with shape torch.Size([256, 512]) from checkpoint, the shape in current model is torch.Size([1024, 512]).
        size mismatch for GE.blocks.3.to_style1.bias: copying a param with shape torch.Size([256]) from checkpoint, the shape in current model is torch.Size([1024]).
        size mismatch for GE.blocks.3.to_noise1.weight: copying a param with shape torch.Size([128, 1]) from checkpoint, the shape in current model is torch.Size([512, 1]).
        size mismatch for GE.blocks.3.to_noise1.bias: copying a param with shape torch.Size([128]) from checkpoint, the shape in current model is torch.Size([512]).
        size mismatch for GE.blocks.3.conv1.weight: copying a param with shape torch.Size([128, 256, 3, 3]) from checkpoint, the shape in current model is torch.Size([512, 1024, 3, 3]).
        size mismatch for GE.blocks.3.to_style2.weight: copying a param with shape torch.Size([128, 512]) from checkpoint, the shape in current model is torch.Size([512, 512]).
        size mismatch for GE.blocks.3.to_style2.bias: copying a param with shape torch.Size([128]) from checkpoint, the shape in current model is torch.Size([512]).
        size mismatch for GE.blocks.3.to_noise2.weight: copying a param with shape torch.Size([128, 1]) from checkpoint, the shape in current model is torch.Size([512, 1]).
        size mismatch for GE.blocks.3.to_noise2.bias: copying a param with shape torch.Size([128]) from checkpoint, the shape in current model is torch.Size([512]).
        size mismatch for GE.blocks.3.conv2.weight: copying a param with shape torch.Size([128, 128, 3, 3]) from checkpoint, the shape in current model is torch.Size([512, 512, 3, 3]).
        size mismatch for GE.blocks.3.to_rgb.to_style.weight: copying a param with shape torch.Size([128, 512]) from checkpoint, the shape in current model is torch.Size([512, 512]).
        size mismatch for GE.blocks.3.to_rgb.to_style.bias: copying a param with shape torch.Size([128]) from checkpoint, the shape in current model is torch.Size([512]).
        size mismatch for GE.blocks.3.to_rgb.conv.weight: copying a param with shape torch.Size([3, 128, 1, 1]) from checkpoint, the shape in current model is torch.Size([3, 512, 1, 1]).
        size mismatch for GE.blocks.4.to_style1.weight: copying a param with shape torch.Size([128, 512]) from checkpoint, the shape in current model is torch.Size([512, 512]).
        size mismatch for GE.blocks.4.to_style1.bias: copying a param with shape torch.Size([128]) from checkpoint, the shape in current model is torch.Size([512]).
        size mismatch for GE.blocks.4.to_noise1.weight: copying a param with shape torch.Size([64, 1]) from checkpoint, the shape in current model is torch.Size([256, 1]).
        size mismatch for GE.blocks.4.to_noise1.bias: copying a param with shape torch.Size([64]) from checkpoint, the shape in current model is torch.Size([256]).
        size mismatch for GE.blocks.4.conv1.weight: copying a param with shape torch.Size([64, 128, 3, 3]) from checkpoint, the shape in current model is torch.Size([256, 512, 3, 3]).
        size mismatch for GE.blocks.4.to_style2.weight: copying a param with shape torch.Size([64, 512]) from checkpoint, the shape in current model is torch.Size([256, 512]).
        size mismatch for GE.blocks.4.to_style2.bias: copying a param with shape torch.Size([64]) from checkpoint, the shape in current model is torch.Size([256]).
        size mismatch for GE.blocks.4.to_noise2.weight: copying a param with shape torch.Size([64, 1]) from checkpoint, the shape in current model is torch.Size([256, 1]).
        size mismatch for GE.blocks.4.to_noise2.bias: copying a param with shape torch.Size([64]) from checkpoint, the shape in current model is torch.Size([256]).
        size mismatch for GE.blocks.4.conv2.weight: copying a param with shape torch.Size([64, 64, 3, 3]) from checkpoint, the shape in current model is torch.Size([256, 256, 3, 3]).
        size mismatch for GE.blocks.4.to_rgb.to_style.weight: copying a param with shape torch.Size([64, 512]) from checkpoint, the shape in current model is torch.Size([256, 512]).
        size mismatch for GE.blocks.4.to_rgb.to_style.bias: copying a param with shape torch.Size([64]) from checkpoint, the shape in current model is torch.Size([256]).
        size mismatch for GE.blocks.4.to_rgb.conv.weight: copying a param with shape torch.Size([3, 64, 1, 1]) from checkpoint, the shape in current model is torch.Size([3, 256, 1, 1]).
        size mismatch for GE.blocks.5.to_style1.weight: copying a param with shape torch.Size([64, 512]) from checkpoint, the shape in current model is torch.Size([256, 512]).
        size mismatch for GE.blocks.5.to_style1.bias: copying a param with shape torch.Size([64]) from checkpoint, the shape in current model is torch.Size([256]).
        size mismatch for GE.blocks.5.to_noise1.weight: copying a param with shape torch.Size([32, 1]) from checkpoint, the shape in current model is torch.Size([128, 1]).
        size mismatch for GE.blocks.5.to_noise1.bias: copying a param with shape torch.Size([32]) from checkpoint, the shape in current model is torch.Size([128]).
        size mismatch for GE.blocks.5.conv1.weight: copying a param with shape torch.Size([32, 64, 3, 3]) from checkpoint, the shape in current model is torch.Size([128, 256, 3, 3]).
        size mismatch for GE.blocks.5.to_style2.weight: copying a param with shape torch.Size([32, 512]) from checkpoint, the shape in current model is torch.Size([128, 512]).
        size mismatch for GE.blocks.5.to_style2.bias: copying a param with shape torch.Size([32]) from checkpoint, the shape in current model is torch.Size([128]).
        size mismatch for GE.blocks.5.to_noise2.weight: copying a param with shape torch.Size([32, 1]) from checkpoint, the shape in current model is torch.Size([128, 1]).
        size mismatch for GE.blocks.5.to_noise2.bias: copying a param with shape torch.Size([32]) from checkpoint, the shape in current model is torch.Size([128]).
        size mismatch for GE.blocks.5.conv2.weight: copying a param with shape torch.Size([32, 32, 3, 3]) from checkpoint, the shape in current model is torch.Size([128, 128, 3, 3]).
        size mismatch for GE.blocks.5.to_rgb.to_style.weight: copying a param with shape torch.Size([32, 512]) from checkpoint, the shape in current model is torch.Size([128, 512]).
        size mismatch for GE.blocks.5.to_rgb.to_style.bias: copying a param with shape torch.Size([32]) from checkpoint, the shape in current model is torch.Size([128]).
        size mismatch for GE.blocks.5.to_rgb.conv.weight: copying a param with shape torch.Size([3, 32, 1, 1]) from checkpoint, the shape in current model is torch.Size([3, 128, 1, 1]).

Training data

I hope that i am at the right place but I did not find any alternative. So my question is how many pictures are recommended? Excuse for any incommodities. Thanks in advance

Recommended specs for training?

I asked this in my previous issue but because it was closed maybe it was not seen.

What kind of specs do you recommend for training this model? I was trying it on Google Colab but it was running extremely slowly (30s for a single iteration in a folder with 5 images), however this does not surprise me since Google Colab is by no means an industrial solution. If I want to scale this up to something significant, what would you recommend for minimum specifications?

generate options

Hi. I tried to find a way to control the generate function in a more flexible way. Could someone point me in the right direction? I am looking to make series of larger single images instead of the "contact sheet" style that it now outputs.

Transfer Learning

Is it possible to use a pre-trained model (for example FFHQ) as a starting point?

Size mismatch?

I have just collected >10k images as recommended, but I'm now hitting this error, complaining that there is a "size mismatch". Any ideas? I verified that every image in my training set is exactly 418x418 pixels.

Rolling back to version 0.4.11 did not help.

from google.colab import drive
drive.mount('/content/drive', force_remount=True)
!pip uninstall stylegan2_pytorch
!pip install stylegan2_pytorch
!stylegan2_pytorch --image-size 418 --data /content/drive/My\ Drive/BY/tiles --results-dir drive/My\ Drive/results --models-dir drive/My\ Drive/models --name 20200315_bayern_towns_villages
  0% 0/100000 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "/usr/local/bin/stylegan2_pytorch", line 59, in <module>
    fire.Fire(train_from_folder)
  File "/usr/local/lib/python3.6/dist-packages/fire/core.py", line 138, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/usr/local/lib/python3.6/dist-packages/fire/core.py", line 471, in _Fire
    target=component.__name__)
  File "/usr/local/lib/python3.6/dist-packages/fire/core.py", line 675, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/usr/local/bin/stylegan2_pytorch", line 54, in train_from_folder
    model.train()
  File "/usr/local/lib/python3.6/dist-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 492, in train
    real_output = self.GAN.D(image_batch)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 341, in forward
    x = self.to_logit(x)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/linear.py", line 87, in forward
    return F.linear(input, self.weight, self.bias)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py", line 1370, in linear
    ret = torch.addmm(bias, input, weight.t())
RuntimeError: size mismatch, m1: [3 x 32768], m2: [8192 x 1] at /pytorch/aten/src/THC/generic/THCTensorMathBlas.cu:290

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.