{"id":13711249,"url":"https://github.com/facebookresearch/pytorch_GAN_zoo","last_synced_at":"2025-05-06T20:32:28.208Z","repository":{"id":44543788,"uuid":"166202080","full_name":"facebookresearch/pytorch_GAN_zoo","owner":"facebookresearch","description":"A mix of GAN implementations including progressive growing","archived":true,"fork":false,"pushed_at":"2021-10-12T21:33:09.000Z","size":2108,"stargazers_count":1624,"open_issues_count":34,"forks_count":270,"subscribers_count":34,"default_branch":"main","last_synced_at":"2025-02-23T00:13:56.931Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/facebookresearch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-17T09:52:30.000Z","updated_at":"2025-01-19T12:45:40.000Z","dependencies_parsed_at":"2022-08-01T01:17:58.360Z","dependency_job_id":null,"html_url":"https://github.com/facebookresearch/pytorch_GAN_zoo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebookresearch%2Fpytorch_GAN_zoo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebookresearch%2Fpytorch_GAN_zoo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebookresearch%2Fpytorch_GAN_zoo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebookresearch%2Fpytorch_GAN_zoo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/facebookresearch","download_url":"https://codeload.github.com/facebookresearch/pytorch_GAN_zoo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252764635,"owners_count":21800722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T23:01:06.158Z","updated_at":"2025-05-06T20:32:27.787Z","avatar_url":"https://github.com/facebookresearch.png","language":"Python","funding_links":[],"categories":["Computer Vision","Python","**Programming (learning)**"],"sub_categories":["Image / Video Generation","**Developer\\'s Tools**"],"readme":"# Pytorch GAN Zoo\n\nA GAN toolbox for researchers and developers with:\n- Progressive Growing of GAN(PGAN): https://arxiv.org/pdf/1710.10196.pdf\n- DCGAN: https://arxiv.org/pdf/1511.06434.pdf\n- StyleGAN (beta): https://arxiv.org/abs/1812.04948\n\n\u003cimg src=\"illustration.png\" alt=\"illustration\"\u003e\nPicture: Generated samples from GANs trained on celebaHQ, fashionGen, DTD.\n\n\n\u003cimg src=\"illustartionCelebaHQ.jpg\" alt=\"celeba\"\u003e\nPicture: fake faces with celebaHQ\n\nThis code also implements diverse tools:\n- GDPP method from [GDPP: Learning Diverse Generations Using Determinantal Point Process](https://arxiv.org/abs/1812.00068)\n- Image generation \"inspired\" from a reference image using an already trained GAN from [Inspirational Adversarial Image Generation](https://arxiv.org/abs/1906.11661)\n- AC-GAN conditioning from [Conditional Image Synthesis With Auxiliary Classifier GANs](https://arxiv.org/abs/1610.09585)\n- [SWD metric](https://hal.archives-ouvertes.fr/hal-00476064/document)\n- [Inception Score](https://papers.nips.cc/paper/6125-improved-techniques-for-training-gans.pdf)\n- Logistic loss from [Which training method of GANs actually converge](https://arxiv.org/pdf/1801.04406.pdf)\n\n## Requirements\n\nThis project requires:\n- pytorch\n- torchvision\n- numpy\n- scipy\n- h5py (fashionGen)\n\nOptional:\n- visdom\n- nevergrad (inspirational generation)\n\nIf 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.\n\nYou can install all other dependencies with pip by running:\n\n```\npip install -r requirements.txt\n```\n\n## Recommended datasets\n - celebA: http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html\n - celebAHQ: https://github.com/nperraud/download-celebA-HQ\n - fashionGen: https://fashion-gen.com/\n - DTD: https://www.robots.ox.ac.uk/~vgg/data/dtd/\n - CIFAR10: http://www.cs.toronto.edu/~kriz/cifar.html\n\n## Quick training\n\nThe datasets.py script allows you to prepare your datasets and build their corresponding configuration files.\n\nIf you want to waste no time and just launch a training session on celeba cropped\n\n```\npython datasets.py celeba_cropped $PATH_TO_CELEBA/img_align_celeba/ -o $OUTPUT_DATASET\npython train.py PGAN -c config_celeba_cropped.json --restart -n celeba_cropped\n```\n\nAnd wait for a few days. Your checkpoints will be dumped in output_networks/celeba_cropped. You should get 128x128 generations at the end.\n\nFor celebaHQ:\n\n```\npython datasets.py celebaHQ $PATH_TO_CELEBAHQ -o $OUTPUT_DATASET - f\npython train.py PGAN -c config_celebaHQ.json --restart -n celebaHQ\n```\n\nYour checkpoints will be dumped in output_networks/celebaHQ. You should get 1024x1024 generations at the end.\n\nFor fashionGen:\n\n```\npython datasets.py fashionGen $PATH_TO_FASHIONGEN_RES_256 -o $OUTPUT_DIR\npython train.py PGAN -c config_fashionGen.json --restart -n fashionGen\n```\n\nThe 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:\n\n```\npython train.py PGAN -c config_fashionGen.json --restart -n fashionGen -v CLOTHING\n```\n\nFour sub-datasets are available: CLOTHING, SHOES, BAGS and ACCESSORIES.\n\nFor the DTD texture dataset:\n\n```\npython datasets.py dtd $PATH_TO_DTD\npython train.py PGAN -c config_dtd.json --restart -n dtd\n```\n\nFor cifar10:\n\n```\npython datasets.py cifar10 $PATH_TO_CIFAR10 -o $OUTPUT_DATASET\npython train.py PGAN -c config_cifar10.json --restart -n cifar10\n```\n\n## Load a pretrained model with torch.hub\n\nModels trained on celebaHQ, fashionGen, cifar10 and celeba cropped are available with [torch.hub](https://pytorch.org/docs/stable/hub.html).\n\nCheckpoints:\n- PGAN:\n  - celebaHQ https://dl.fbaipublicfiles.com/gan_zoo/PGAN/celebaHQ_s6_i80000-6196db68.pth\n  - celeba_cropped https://dl.fbaipublicfiles.com/gan_zoo/PGAN/celebaCropped_s5_i83000-2b0acc76.pth\n  - dtd https://dl.fbaipublicfiles.com/gan_zoo/PGAN/testDTD_s5_i96000-04efa39f.pth\n\n- DCGAN\n  - fashionGen https://dl.fbaipublicfiles.com/gan_zoo/DCGAN_fashionGen-1d67302.pth\n\nSee hubconf.py for how to load a checkpoint !\n\n## GDPP\n\nTo apply the GDPP loss to your model just add the option --GDPP true to your training command.\n\n## (beta) StyleGAN\n\nTo 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:\n\n```\npython train.py StyleGAN -c config_celebaHQ.json --restart -n style_gan_celeba\n```\n\n## Advanced guidelines\n\n### How to run a training session ?\n\n```\npython train.py $MODEL_NAME -c $CONFIGURATION_FILE[-n $RUN_NAME][-d $OUTPUT_DIRECTORY][OVERRIDES]\n```\n\nWhere:\n\n1 - MODEL_NAME is the name of the model you want to run. Currently, two models are available:\n    - PGAN(progressive growing of gan)\n    - PPGAN(decoupled version of PGAN)\n\n2 - 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.\n\n3 - 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\n\n4 - OUTPUT_DIRECTORY is the directory were all training sessions are saved. Default value is output_networks\n\n5 - 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:\n\n```\npython train.py PPGAN -c coin.json -n PAN --learningRate 0.2\n```\n\nWill force the learning rate to be 0.2 in the training whatever the configuration file coin.json specifies.\n\nTo get all the possible override options, please type:\n\n```\npython train.py $MODEL_NAME --overrides\n```\n\n## Configuration file of a training session\n\nThe minimum configuration file for a training session is a json file with the following lines\n\n```\n{\n    \"pathDB\": PATH_TO_YOUR_DATASET\n}\n```\n\nWhere a dataset can be:\n- a folder with all your images in .jpg, .png or .npy format\n- a folder with N subfolder and images in it (see imagefolderDataset = True below)\n- a .h5 file(cf fashionGen)\n\nTo 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:\n\n```\n{\n    \"pathDB\": PATH_TO_YOUR_DATASET,\n    \"config\": {\"baseLearningRate\": 0.1,\n               \"miniBatchSize\": 22}\n}\n```\n\nWill 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.\n\nOther fields are available on the configuration file, like:\n- 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:\n\n```\n{\n    image_name1.jpg: {attribute1: label, attribute2, label ...}\n    image_name2.jpg: {attribute1: label, attribute2, label ...}\n    ...\n}\n```\n\nWith a dataset in the fashionGen format(.h5) it's a dictionary summing up statistics on the class to be sampled.\n\n- imagefolderDataset(bool): set to true to handle datasets in the torchvision.datasets.ImageFolder format\n- selectedAttributes(list): if specified, learn only the given attributes during the training session\n- pathPartition(string): path to a partition of the training dataset\n- partitionValue(string): if pathPartition is specified, name of the partition to choose\n- miniBatchScheduler(dictionary): dictionary updating the size of the mini batch at different scale of the training\nex {\"2\": 16, \"7\": 8} meaning that the mini batch size will be 16 from scale 16 to 6 and 8 from scale 7\n- configScheduler(dictionary): dictionary updating the model configuration at different scale of the training\nex {\"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\n\n## How to run a evaluation of the results of your training session ?\n\nYou need to use the eval.py script.\n\n### Image generation\n\nYou can generate more images from an existing checkpoint using:\n```\npython eval.py visualization -n $modelName -m $modelType\n```\n\nWhere 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:\n\n```\npython eval.py visualization -n $modelName -m $modelType -s $SCALE -i $ITER\n```\n\nIf 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. \n\n```\npython eval.py visualization -n $modelName -m $modelType --showLabels\n```\n\nThen, run your generation with:\n\n```\npython eval.py visualization -n $modelName -m $modelType --$CATEGORY_NAME $LABEL_NAME\n```\n\nFor example with a model trained on fashionGen:\n\n```\npython eval.py visualization -n $modelName -m $modelType --Class T_SHIRT\n```\n\nWill plot a batch of T_SHIRTS in visdom.\n\n### Fake dataset generation\n\nTo save a randomly generated fake dataset from a checkpoint please use:\n\n```\npython eval.py visualization -n $modelName -m $modelType --save_dataset $PATH_TO_THE_OUTPUT_DATASET --size_dataset $SIZE_OF_THE_OUTPUT\n```\n\n### SWD metric\n\nUsing the same kind of configuration file as above, just launch:\n\n```\npython eval.py laplacian_SWD -c $CONFIGURATION_FILE -n $modelName -m $modelType\n```\n\nWhere $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.\n\nYou can add optional arguments:\n\n- -s $SCALE: specify the scale at which the evaluation should be done(if not set, will take the highest one)\n- -i $ITER: specify the iteration to evaluate(if not set, will take the highest one)\n- --selfNoise: returns the typical noise of the SWD distance for each resolution\n\n### Inspirational generation\n\nTo make an inspirational generation, you first need to build a feature extractor:\n\n```\npython save_feature_extractor.py {vgg16, vgg19} $PATH_TO_THE_OUTPUT_FEATURE_EXTRACTOR --layers 3 4 5\n```\n\nThen run your model:\n\n```\npython eval.py inspirational_generation -n $modelName -m $modelType --inputImage $pathTotheInputImage -f $PATH_TO_THE_OUTPUT_FEATURE_EXTRACTOR\n```\n\n### I have generated my metrics. How can i plot them on visdom ?\n\nJust run\n```\npython eval.py metric_plot  -n $modelName\n```\n\n## LICENSE\n\nThis project is under BSD-3 license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffacebookresearch%2Fpytorch_GAN_zoo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffacebookresearch%2Fpytorch_GAN_zoo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffacebookresearch%2Fpytorch_GAN_zoo/lists"}