Giter VIP home page Giter VIP logo

pytorch_gan_zoo's Introduction

Pytorch GAN Zoo

A GAN toolbox for researchers and developers with:

illustration

Picture: Generated samples from GANs trained on celebaHQ, fashionGen, DTD.

celeba

Picture: fake faces with celebaHQ

This code also implements diverse tools:

Requirements

This project requires:

  • pytorch
  • torchvision
  • numpy
  • scipy
  • h5py (fashionGen)

Optional:

  • visdom
  • nevergrad (inspirational generation)

If you don't already have pytorch or torchvision please have a look at https://pytorch.org/ as the installation command may vary depending on your OS and your version of CUDA.

You can install all other dependencies with pip by running:

pip install -r requirements.txt

Recommended datasets

Quick training

The datasets.py script allows you to prepare your datasets and build their corresponding configuration files.

If you want to waste no time and just launch a training session on celeba cropped

python datasets.py celeba_cropped $PATH_TO_CELEBA/img_align_celeba/ -o $OUTPUT_DATASET
python train.py PGAN -c config_celeba_cropped.json --restart -n celeba_cropped

And wait for a few days. Your checkpoints will be dumped in output_networks/celeba_cropped. You should get 128x128 generations at the end.

For celebaHQ:

python datasets.py celebaHQ $PATH_TO_CELEBAHQ -o $OUTPUT_DATASET - f
python train.py PGAN -c config_celebaHQ.json --restart -n celebaHQ

Your checkpoints will be dumped in output_networks/celebaHQ. You should get 1024x1024 generations at the end.

For fashionGen:

python datasets.py fashionGen $PATH_TO_FASHIONGEN_RES_256 -o $OUTPUT_DIR
python train.py PGAN -c config_fashionGen.json --restart -n fashionGen

The above command will train the fashionGen model up resolution 256x256. If you want to train fashionGen on a specific sub-dataset for example CLOTHING, run:

python train.py PGAN -c config_fashionGen.json --restart -n fashionGen -v CLOTHING

Four sub-datasets are available: CLOTHING, SHOES, BAGS and ACCESSORIES.

For the DTD texture dataset:

python datasets.py dtd $PATH_TO_DTD
python train.py PGAN -c config_dtd.json --restart -n dtd

For cifar10:

python datasets.py cifar10 $PATH_TO_CIFAR10 -o $OUTPUT_DATASET
python train.py PGAN -c config_cifar10.json --restart -n cifar10

Load a pretrained model with torch.hub

Models trained on celebaHQ, fashionGen, cifar10 and celeba cropped are available with torch.hub.

Checkpoints:

See hubconf.py for how to load a checkpoint !

GDPP

To apply the GDPP loss to your model just add the option --GDPP true to your training command.

(beta) StyleGAN

To run StyleGAN, use the model name StyleGAN when running train.py. Besides,to run StyleGAN you can use the pre-computed configurations for celeba and celebaHQ. For example:

python train.py StyleGAN -c config_celebaHQ.json --restart -n style_gan_celeba

Advanced guidelines

How to run a training session ?

python train.py $MODEL_NAME -c $CONFIGURATION_FILE[-n $RUN_NAME][-d $OUTPUT_DIRECTORY][OVERRIDES]

Where:

1 - MODEL_NAME is the name of the model you want to run. Currently, two models are available: - PGAN(progressive growing of gan) - PPGAN(decoupled version of PGAN)

2 - CONFIGURATION_FILE(mandatory): path to a training configuration file. This file is a json file containing at least a pathDB entry with the path to the training dataset. See below for more informations about this file.

3 - RUN_NAME is the name you want to give to your training session. All checkpoints will be saved in $OUTPUT_DIRECTORY/$RUN_NAME. Default value is default

4 - OUTPUT_DIRECTORY is the directory were all training sessions are saved. Default value is output_networks

5 - OVERRIDES: you can overrides some of the models parameters defined in "config" field of the configuration file(see below) in the command line. For example:

python train.py PPGAN -c coin.json -n PAN --learningRate 0.2

Will force the learning rate to be 0.2 in the training whatever the configuration file coin.json specifies.

To get all the possible override options, please type:

python train.py $MODEL_NAME --overrides

Configuration file of a training session

The minimum configuration file for a training session is a json file with the following lines

{
    "pathDB": PATH_TO_YOUR_DATASET
}

Where a dataset can be:

  • a folder with all your images in .jpg, .png or .npy format
  • a folder with N subfolder and images in it (see imagefolderDataset = True below)
  • a .h5 file(cf fashionGen)

To this you can add a "config" entry giving overrides to the standard configuration. See models/trainer/standard_configurations to see all possible options. For example:

{
    "pathDB": PATH_TO_YOUR_DATASET,
    "config": {"baseLearningRate": 0.1,
               "miniBatchSize": 22}
}

Will override the learning rate and the mini-batch-size. Please note that if you specify a - -baseLearningRate option in your command line, the command line will prevail. Depending on how you work you might prefer to have specific configuration files for each run or only rely on one configuration file and input your training parameters via the command line.

Other fields are available on the configuration file, like:

  • pathAttribDict(string): path to a .json file matching each image with its attributes. To be more precise with a standard dataset, it is a dictionary with the following entries:
{
    image_name1.jpg: {attribute1: label, attribute2, label ...}
    image_name2.jpg: {attribute1: label, attribute2, label ...}
    ...
}

With a dataset in the fashionGen format(.h5) it's a dictionary summing up statistics on the class to be sampled.

  • imagefolderDataset(bool): set to true to handle datasets in the torchvision.datasets.ImageFolder format
  • selectedAttributes(list): if specified, learn only the given attributes during the training session
  • pathPartition(string): path to a partition of the training dataset
  • partitionValue(string): if pathPartition is specified, name of the partition to choose
  • miniBatchScheduler(dictionary): dictionary updating the size of the mini batch at different scale of the training ex {"2": 16, "7": 8} meaning that the mini batch size will be 16 from scale 16 to 6 and 8 from scale 7
  • configScheduler(dictionary): dictionary updating the model configuration at different scale of the training ex {"2": {"baseLearningRate": 0.1, "epsilonD": 1}} meaning that the learning rate and epsilonD will be updated to 0.1 and 1 from scale 2 and beyond

How to run a evaluation of the results of your training session ?

You need to use the eval.py script.

Image generation

You can generate more images from an existing checkpoint using:

python eval.py visualization -n $modelName -m $modelType

Where modelType is in [PGAN, PPGAN, DCGAN] and modelName is the name given to your model. This script will load the last checkpoint detected at testNets/$modelName. If you want to load a specific iteration, please call:

python eval.py visualization -n $modelName -m $modelType -s $SCALE -i $ITER

If your model is conditioned, you can ask the visualizer to print out some conditioned generations. First, use --showLabels to see all the available categories and their labels.

python eval.py visualization -n $modelName -m $modelType --showLabels

Then, run your generation with:

python eval.py visualization -n $modelName -m $modelType --$CATEGORY_NAME $LABEL_NAME

For example with a model trained on fashionGen:

python eval.py visualization -n $modelName -m $modelType --Class T_SHIRT

Will plot a batch of T_SHIRTS in visdom.

Fake dataset generation

To save a randomly generated fake dataset from a checkpoint please use:

python eval.py visualization -n $modelName -m $modelType --save_dataset $PATH_TO_THE_OUTPUT_DATASET --size_dataset $SIZE_OF_THE_OUTPUT

SWD metric

Using the same kind of configuration file as above, just launch:

python eval.py laplacian_SWD -c $CONFIGURATION_FILE -n $modelName -m $modelType

Where $CONFIGURATION_FILE is the training configuration file called by train.py (see above): it must contains a "pathDB" field pointing to path to the dataset's directory. For example, if you followed the instruction of the Quick Training section to launch a training session on celebaHQ your configuration file will be config_celebaHQ.json.

You can add optional arguments:

  • -s $SCALE: specify the scale at which the evaluation should be done(if not set, will take the highest one)
  • -i $ITER: specify the iteration to evaluate(if not set, will take the highest one)
  • --selfNoise: returns the typical noise of the SWD distance for each resolution

Inspirational generation

To make an inspirational generation, you first need to build a feature extractor:

python save_feature_extractor.py {vgg16, vgg19} $PATH_TO_THE_OUTPUT_FEATURE_EXTRACTOR --layers 3 4 5

Then run your model:

python eval.py inspirational_generation -n $modelName -m $modelType --inputImage $pathTotheInputImage -f $PATH_TO_THE_OUTPUT_FEATURE_EXTRACTOR

I have generated my metrics. How can i plot them on visdom ?

Just run

python eval.py metric_plot  -n $modelName

LICENSE

This project is under BSD-3 license.

pytorch_gan_zoo's People

Contributors

cclauss avatar helges avatar johnson-yue avatar molugan 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

pytorch_gan_zoo's Issues

A little bug

You should add this line to progressive_conv_net.py in line 164:
if self.normalizationLayer is not None:

How do I rebuild the discriminator for a pretrained model?

I am trying to pull the discriminator from a model I trained. I want to use the features for reID on a vehicle dataset. I use the celeba (size 128x128) config file to train. Now that the model is done training I want to rebuild the discriminator and load in the 'netD' weights from the generated .pt file.

How should I go about building the discriminator with the proper scales, number of layers etc. using your code?

AttributeError: 'module' object has no attribute 'functional'

Hello,

I am trying to get started with GAN zoo, but I cannot the steps of the instructions don't seem to work for me.

Which python version does it use? Python 2 or 3?

When I run the following line (as per instructions), I get several errors including a 'module' object has no attribute 'functional', which seems to point out to torch versioning issue.

I did not change anything in the code yet.

`ubuntu@ip-172-31-32-19:~/GAN-ZOO$ python train.py PGAN -c config_celeba_cropped.json --restart -n celeba_cropped
2.7.15 |Anaconda, Inc.| (default, May 1 2018, 23:32:55)
[GCC 7.2.0]
True
WARNING:root:Setting up a new session...
Exception in user code:

Traceback (most recent call last):
File "/home/ubuntu/anaconda3/lib/python2.7/site-packages/visdom/init.py", line 548, in _send
data=json.dumps(msg),
File "/home/ubuntu/anaconda3/lib/python2.7/site-packages/requests/sessions.py", line 581, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/home/ubuntu/anaconda3/lib/python2.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/home/ubuntu/anaconda3/lib/python2.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/home/ubuntu/anaconda3/lib/python2.7/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
ConnectionError: HTTPConnectionPool(host='localhost', port=8097): Max retries exceeded with url: /env/main (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fbc3e858b50>: Failed to establish a new connection: [Errno 111] Connection refused',))
WARNING:visdom:Visdom python client failed to establish socket to get messages from the server. This feature is optional and can be disabled by initializing Visdom with use_incoming_socket=False, which will prevent waiting for this request to timeout.
Running PGAN
ERROR:visdom:[Errno 111] Connection refused
('size', 10)
125854 images found
125854 images detected
('size', (4, 4))
125854 images found
Traceback (most recent call last):
File "train.py", line 138, in
GANTrainer.train()
File "/home/ubuntu/pycharm/arno-victor/GAN-ZOO/models/trainer/progressive_gan_trainer.py", line 239, in train
maxIter=self.modelConfig.maxIterAtScale[scale])
File "/home/ubuntu/pycharm/arno-victor/GAN-ZOO/models/trainer/gan_trainer.py", line 469, in trainOnEpoch
for item, data in enumerate(dbLoader, 0):
File "/home/ubuntu/anaconda3/lib/python2.7/site-packages/torch/utils/data/dataloader.py", line 286, in next
return self._process_next_batch(batch)
File "/home/ubuntu/anaconda3/lib/python2.7/site-packages/torch/utils/data/dataloader.py", line 307, in _process_next_batch
raise batch.exc_type(batch.exc_msg)
AttributeError: Traceback (most recent call last):
File "/home/ubuntu/anaconda3/lib/python2.7/site-packages/torch/utils/data/dataloader.py", line 57, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/home/ubuntu/pycharm/arno-victor/GAN-ZOO/models/datasets/attrib_dataset.py", line 215, in getitem
img = self.transform(img)
File "/home/ubuntu/anaconda3/lib/python2.7/site-packages/torchvision/transforms.py", line 29, in call
img = t(img)
File "/home/ubuntu/pycharm/arno-victor/GAN-ZOO/models/utils/image_transform.py", line 71, in call
return Transforms.functional.to_tensor(img)
AttributeError: 'module' object has no attribute 'functional'
`

Automatic setup

1/ Sorry, it's really nitpicking, but when i see setup.py i think about this one https://stackoverflow.com/questions/1471994/what-is-setup-py ; maybe you would consider coming up with a less confusing name 🙂

2/ speaking of installation, it might be a good idea to have a requirements.txt so that folks can install all the requirements as
pip install -r requirements.txt - now you list them as text.

Display loss curves on Visdom

Hi, I'm training on an image dataset and I guess I should see the trend of the loss functions plotted in Visdom. I'm now at interaction 1700 and there's nothing displayed yet. Am I doing something wrong? I'm running the code in its standard configuration.

As commands, I gave the following:

python -m visdom.server &&
python train.py StyleGAN -c file.json

Bug in miniBatchStdDev

As far, as I understand, the miniBatchStdDev layer has a bug in this line

There the group and batch dimensions swap so after that std outputs tiled incorrectly.

We can try this on this code sample:

a = torch.tensor([0, 0, 0, 0, 1, 2, 3, 4, 100, 200, 300, 400], dtype=torch.float32)
a = a.reshape(-1, 1, 1, 1)
miniBatchStdDev(a, 4)[:, -1, 0, 0]

The output would be

tensor([ 99.5100,  99.5100,  99.5100,  99.5100, 149.1763, 149.1763, 149.1763,
        149.1763, 188.8589, 188.8589, 188.8589, 188.8589])

wich is obviously incorrect and should be

tensor([99.5100,  149.1763, 188.8589, 99.5100,  149.1763, 188.8589, 99.5100,  
        149.1763, 188.8589, 99.5100,  149.1763, 188.8589])

Am I right?

Discriminator variability on the same image when in different batches

Hi, I've been using the discriminator of the trained NN as a black box to distinguish between generated and real image. My main goal is to define the range of the discriminator output values (as it is acts as a critic and not a classifier I understand it is not bound to a specific range but it would be nice to have an estimation of it).

My problem is that If I were to take an image and run it with different images in the batch it's output would change (I assume it has something to do with the minibatch normalization).

Also, If I set the batchsize to one, it seems as there is a large bias to the discriminator output.
for example:

  • Running a single image usually result within the range -260 to -250. As you increase the batch size the results slowly getting bigger and bigger.

Is there a way to disable the affect of other images on each image result at inference?

GDPPLoss can become NaN

It's probably a rare edge case, but I noticed that in the normalization function a division by zero can occur if minV == maxV in which case the returned loss will become NaN and probably poison the rest of the model even if it just happens once.

So I'd propose to add a safeguard (I tried adding a small epsilon first, but that lead to wrong results)

def normalize_min_max(eigVals):
        minV, maxV = torch.min(eigVals), torch.max(eigVals)
        if minV == maxV:
            return eigVals
        return (eigVals - minV) / (maxV - minV)
 

How to generate images per class?

When I run eval.py it will generate 32x8 images as expected. But the 1 big image consists images from all classes
If I run:
python3 eval.py visualization -n animal -m PGAN --Class dog

It will produce:
eval.py: error: unrecognized arguments: --Class dog
I don't think there's a --Class flag in eval.py

How to use conditional GAN or generate the 1 big image for 1 class each? Thank you

imresize is deprecated

Hi, when I executed train.py I got the following error related to imresize. I'm using newest version of Scipy (1.3.3) and imresize has been removed since 1.3.0, refer to https://stackoverflow.com/questions/56204985/how-to-fix-scipy-misc-has-no-attribute-imresize.

Traceback (most recent call last):
  File "train.py", line 137, in <module>
    GANTrainer.train()
  File "/ssd/gan/pytorch_GAN_zoo/models/trainer/progressive_gan_trainer.py", line 237, in train
    maxIter=self.modelConfig.maxIterAtScale[scale])
  File "/ssd/gan/pytorch_GAN_zoo/models/trainer/gan_trainer.py", line 470, in trainOnEpoch
    for item, data in enumerate(dbLoader, 0):
  File "/home/ivan/.local/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 819, in __next__
    return self._process_data(data)
  File "/home/ivan/.local/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 846, in _process_data
    data.reraise()
  File "/home/ivan/.local/lib/python3.6/site-packages/torch/_utils.py", line 369, in reraise
    raise self.exc_type(msg)
AttributeError: Caught AttributeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/home/ivan/.local/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File "/home/ivan/.local/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/ivan/.local/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 "/ssd/gan/pytorch_GAN_zoo/models/datasets/attrib_dataset.py", line 216, in __getitem__
    img = self.transform(img)
  File "/home/ivan/.local/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 61, in __call__
    img = t(img)
  File "/ssd/gan/pytorch_GAN_zoo/models/utils/image_transform.py", line 32, in __call__
    return scipy.misc.imresize(img, self.size, interp='bilinear')
AttributeError: module 'scipy.misc' has no attribute 'imresize'

Generate image from StyleGAN agent

One last question regarding the StyleGAN reimplementation: do you have any recommendation on how to run a snapshot agent and produce images? Alternatively, do you have any estimate on when this feature will be included in the repo? Thanks

Using multiple GPUs for progressive GAN

As the model can take a few days to train, it might be useful to add multiple GPU support. Is there any work on that?

If not, I can fork and create a pull request for a version with multiple GPUs.

Best,
Spandan

Manual seed

4/ I've also noticed that you often use seed() with no arguments - I'm not sure how common it is, but more often than not i find it useful to enable seeding from command line parameters that is called once from main, so that the results are more reproducible. Maybe you have reasons for this!

maxIterAtScale

I'm training my own dataset that's not very diverse so alpha gets down to zero rather quickly: say, 20k iterations when most default scale length values are 96k. And when alpha gets to zero, loss is starting to increase slowly. Looking at generated pictures they're still ok, but I wonder, if there's a rule of thumb on training length in such a case?

Also --Class was replaced with --Main, if I understood the code correctly, but --Class is still mentioned in Readme.

Add StyleGAN to hubconf.py

Hi, thanks for making your code available through the PyTorch hub! Its been very useful for a lecture I'm writing about GANs. I wanted to ask if StylGAN will be made available in the same manner, as the results are better and it makes the Colab notebooks much easier for students to run.

why gdpp loss always (almost) negative, it can't compute BCE loss

Hi, I was trying your gdpp loss with pytorch version, but when I add gdpp loss on G_loss, the training process crash, because the G_loss(~1.0) + gdpp_loss is negative. So, it can't compute BCE loss .

My question is why is gdpp loss always negative, does it make sense??

Update line in README

Hi, the example python train.py PPGAN -c coin.json -n PAN --learningRate 0.2 in the README should be updated to python train.py PGAN -c coin.json -n PAN --baseLearningRate 0.2. Motivation: fix typo and be consistent with current command form.

Undefined name 'PPGANTrainer' in DCGAN_trainer.py

flake8 testing of https://github.com/facebookresearch/pytorch_GAN_zoo on Python 3.7.1

$ flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics

./models/trainer/DCGAN_trainer.py:19:16: F821 undefined name 'PPGANTrainer'
        return PPGANTrainer._defaultConfig
               ^
1     F821 undefined name 'PPGANTrainer'
1

E901,E999,F821,F822,F823 are the "showstopper" flake8 issues that can halt the runtime with a SyntaxError, NameError, etc. These 5 are different from most other flake8 issues which are merely "style violations" -- useful for readability but they do not effect runtime safety.

  • F821: undefined name name
  • F822: undefined name name in __all__
  • F823: local variable name referenced before assignment
  • E901: SyntaxError or IndentationError
  • E999: SyntaxError -- failed to compile a file into an Abstract Syntax Tree

Weight scaling is applied to bias as well

x = self.module(x)
if self.equalized:
x *= self.weight

The above implementation applies the weight scaling to the bias tensor as well. However in the original implementation (https://github.com/tkarras/progressive_growing_of_gans/blob/master/networks.py#L53-L59) weight scaling is NOT applied to bias tensor.

This makes sense since He normal initialization takes into account fan-in and fan-out which depends on the dimensionality of the weights, not the biases. https://medium.com/@prateekvishnu/xavier-and-he-normal-he-et-al-initialization-8e3d7a087528

Connection refused & 'GNet' object has no attribute 'module'

I am using Python 3.8 and torch 1.3.1

python train.py PGAN -c config_celeba_cropped.json --restart -n celeba_cropped
Setting up a new session...
Exception in user code:
------------------------------------------------------------
Traceback (most recent call last):
  File "/home/anaconda3/envs/dlenv/lib/python3.8/site-packages/urllib3/connection.py", line 156, in _new_conn
    conn = connection.create_connection(
  File "/home//anaconda3/envs/dlenv/lib/python3.8/site-packages/urllib3/util/connection.py", line 84, in create_connection
    raise err
  File "/home//anaconda3/envs/dlenv/lib/python3.8/site-packages/urllib3/util/connection.py", line 74, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home//anaconda3/envs/dlenv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 665, in urlopen
    httplib_response = self._make_request(
  File "/home//anaconda3/envs/dlenv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 387, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/home//anaconda3/envs/dlenv/lib/python3.8/http/client.py", line 1230, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/home//anaconda3/envs/dlenv/lib/python3.8/http/client.py", line 1276, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/home//anaconda3/envs/dlenv/lib/python3.8/http/client.py", line 1225, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/home//anaconda3/envs/dlenv/lib/python3.8/http/client.py", line 1004, in _send_output
    self.send(msg)
  File "/home//anaconda3/envs/dlenv/lib/python3.8/http/client.py", line 944, in send
    self.connect()
  File "/home//anaconda3/envs/dlenv/lib/python3.8/site-packages/urllib3/connection.py", line 184, in connect
    conn = self._new_conn()
  File "/home//anaconda3/envs/dlenv/lib/python3.8/site-packages/urllib3/connection.py", line 168, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7efe258c68e0>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home//anaconda3/envs/dlenv/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/home//anaconda3/envs/dlenv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 719, in urlopen
    retries = retries.increment(
  File "/home//anaconda3/envs/dlenv/lib/python3.8/site-packages/urllib3/util/retry.py", line 436, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=8097): Max retries exceeded with url: /env/main (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7efe258c68e0>: Failed to establish a new connection: [Errno 111] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home//anaconda3/envs/dlenv/lib/python3.8/site-packages/visdom/__init__.py", line 708, in _send
    return self._handle_post(
  File "/home//anaconda3/envs/dlenv/lib/python3.8/site-packages/visdom/__init__.py", line 677, in _handle_post
    r = self.session.post(url, data=data)
  File "/home//anaconda3/envs/dlenv/lib/python3.8/site-packages/requests/sessions.py", line 581, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/home//anaconda3/envs/dlenv/lib/python3.8/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/home//anaconda3/envs/dlenv/lib/python3.8/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/home//anaconda3/envs/dlenv/lib/python3.8/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8097): Max retries exceeded with url: /env/main (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7efe258c68e0>: Failed to establish a new connection: [Errno 111] Connection refused'))
[Errno 111] Connection refused
Running PGAN
size 10
202599 images found
202599 images detected
size (4, 4)
202599 images found
Changing alpha to 0.000
Traceback (most recent call last):
  File "train.py", line 137, in <module>
    GANTrainer.train()
  File "/home//code/pytorch_GAN_zoo/models/trainer/progressive_gan_trainer.py", line 235, in train
    status = self.trainOnEpoch(dbLoader, scale,
  File "/home//code/pytorch_GAN_zoo/models/trainer/gan_trainer.py", line 479, in trainOnEpoch
    inputs_real = self.inScaleUpdate(i, scale, inputs_real)
  File "/home//code/pytorch_GAN_zoo/models/trainer/progressive_gan_trainer.py", line 166, in inScaleUpdate
    self.model.updateAlpha(alpha)
  File "/home//code/pytorch_GAN_zoo/models/progressive_gan.py", line 134, in updateAlpha
    self.avgG.module.setNewAlpha(newAlpha)
  File "/home//anaconda3/envs/dlenv/lib/python3.8/site-packages/torch/nn/modules/module.py", line 575, in __getattr__
    raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'GNet' object has no attribute 'module'

Getting better images from DTD using PGAN

I am trying to generate some images using the pre-trained DTD on PGAN but the results are not looking very good.
Here is the pseudo-code that I am using as well as the results. Any thought on why the resulting images are not looking good?
Thanks in advance

import torch
use_gpu = True if torch.cuda.is_available() else False
model = torch.hub.load('facebookresearch/pytorch_GAN_zoo:hub',
                       'PGAN', model_name='DTD',
                       pretrained=True, useGPU=use_gpu)
num_images = 4
noise, _ = model.buildNoiseData(num_images)
with torch.no_grad():
    generated_images = model.test(noise)

# let's plot these images using torchvision and matplotlib
import matplotlib.pyplot as plt
import torchvision
grid = torchvision.utils.make_grid(generated_images.clamp(min=-1, max=1), scale_each=True, normalize=True)
plt.imshow(grid.permute(1, 2, 0).cpu().numpy())
plt.show()

Screenshot 2020-04-17 at 13 43 31

I can't using GDPP config train any model

Hi, I will train PGAN with cifar10 dataset and GDPP using this command:

python datasets.py cifar10 $PATH_TO_CIFAR10 -o $OUTPUT_DATASET
python train.py PGAN -c config_cifar10.json --restart -n cifar10 --GDPP True

But, I got error
RuntimeError: Trying to backward through the graph a second time, but the buffers have already been freed. Specify retain_graph=True when calling backward the first time

When I check the code :
backward lossGFake the compute graph has been released. So when backward GDPP loss there is not compute graph or any node will be computed.
and Occur this error!!

ERROR:visdom:[Errno 111] Connection refused

Hi, I'm getting the following error when running "python3 train.py PGAN -c config_cifar10.json --restart -n cifar10" over a cifar10 dataset. Any hints?

Exception in user code:
------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 159, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 80, in create_connection
    raise err
  File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 70, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 354, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.7/http/client.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.7/http/client.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.7/http/client.py", line 1224, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.7/http/client.py", line 1016, in _send_output
    self.send(msg)
  File "/usr/lib/python3.7/http/client.py", line 956, in send
    self.connect()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 181, in connect
    conn = self._new_conn()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 168, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fb4b79df198>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=8097): Max retries exceeded with url: /env/main (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fb4b79df198>: Failed to establish a new connection: [Errno 111] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/visdom/__init__.py", line 548, in _send
    data=json.dumps(msg),
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 581, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8097): Max retries exceeded with url: /env/main (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fb4b79df198>: Failed to establish a new connection: [Errno 111] Connection refused'))
ERROR:visdom:[Errno 111] Connection refused
Running PGAN
size 10
50000 images found
AC-GAN classes : 
{'Main': {'order': 0, 'values': ['horse', 'ship', 'deer', 'bird', 'airplane', 'truck', 'dog', 'automobile', 'cat', 'frog']}}

BUG: torch.symeig

When GDPP is active, torch.symeig may generate NaN values depending on the random seed used for training.

PGGAN model on CIFAR10 obtains poor result on Inception score and FID

Hi, thanks for your great work. I use the official release tf code of Inception score and FID code to evaluate the PGGAN model on CIFAR10. It turns out the results are not good.

Here's my command to train:

python datasets.py cifar10 ~/dataset/cifar-10-batches-py -o data/cifar10
python train.py PGAN -c config_cifar10.json -n cifar10_eval --no_vis

The result I got is:

FID score: 42.96, Inception score: 6.34299373626709 ± 0.06940167397260666

How to generate more images?

Thanks for the great work. I'm using Cifar-10 dataset and I notice that it will generate 16 images (8x8) like this :
image

How to generate more than 8x8 images? Do I need to to modify the source code or the option is available in the config file?

pep8 them all

7/ there're still places where pep8 is not followed (apart from naming, eg number of spaces around == ) -- actually a radical way would be to install & launch autopep8 --recursive which would do all the job for you.

Error when training in StyleGAN mode using a database of npy files

Hi, I am trying to train StyleGAN using a database of npy files. When I launch python train.py PGAN -c maps.json things run fine, but when instead I use python train.py StyleGAN -c maps.json I get a CUDNN error (see below). Do you have suggestions on how to fix this? Thanks!

Traceback (most recent call last):
  File "train.py", line 137, in <module>
    GANTrainer.train()
  File "/home/alberto/Documents/StyleGAN_reimplementation/pytorch_GAN_zoo/models/trainer/progressive_gan_trainer.py", line 237, in train
    maxIter=self.modelConfig.maxIterAtScale[scale])
  File "/home/alberto/Documents/StyleGAN_reimplementation/pytorch_GAN_zoo/models/trainer/gan_trainer.py", line 487, in trainOnEpoch
    inputLabels=labels)
  File "/home/alberto/Documents/StyleGAN_reimplementation/pytorch_GAN_zoo/models/base_GAN.py", line 223, in optimizeParameters
    lossD.backward(retain_graph=True)
  File "/home/alberto/anaconda3/envs/SG_pytorch/lib/python3.6/site-packages/torch/tensor.py", line 195, in backward
    torch.autograd.backward(self, gradient, retain_graph, create_graph)
  File "/home/alberto/anaconda3/envs/SG_pytorch/lib/python3.6/site-packages/torch/autograd/__init__.py", line 99, in backward
    allow_unreachable=True)  # allow_unreachable flag
RuntimeError: cuDNN error: CUDNN_STATUS_NOT_SUPPORTED. This error may appear if you passed in a non-contiguous input.

PGAN 1024x1024 availability

Is there currently plans to make the CelebaHQ-1024 available on torch hub? The 512 model works pretty well, but I think 1024 would be great for generating even larger images.

FID metric

Add the FID metric to the evaluations

Pretrained model for CIFAR 10 dataset?

Is there any pretrained model for cifar 10 dataset? I tried to train using the code here but the loss diverges in the end and I can only get 5.2 inception score.

Out of memory when the resolution is more than 256x256

Hi,
Thanks for the great implementations! I'm trying to train a PGAN to generate images from a custom dataset of 1024x1024 images. Up until generation of 512x512 there is no issues but when it starts training for 512x512 it immediately stops and raises an out of memory error. I was wondering what would be the right way to lower the batch_size so I wouldn't run out of memory.

Here's my exact config, it's the same as the celeaHQ

{
  "pathDB": "dataset",
  "config": {},
  "miniBatchScheduler": {
    "7": 12,
    "8": 8
  }
}

Thanks!

EDIT: I don't know what I was thinking when I opened up this issue, answer is in the config. smh
Sorry for the inconvenience!

How to split generated image?

After evaluating the model using
python eval.py visualization -n $modelName -m $modelType
it will generate a big image consists of nImages = (256 // 2**(max(scale - 2, 3))) * 8 , for example 8x32 = 256 images.

How to split / save the small images separately instead of the combined big image? 1 jpg for 1 generated image

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.