{"id":20063278,"url":"https://github.com/markdtw/least-squares-gan","last_synced_at":"2026-03-08T16:01:52.846Z","repository":{"id":93067254,"uuid":"95782530","full_name":"markdtw/least-squares-gan","owner":"markdtw","description":"GAN that adopts the least squares loss function for the discriminator in tensorflow","archived":false,"fork":false,"pushed_at":"2017-07-09T14:57:22.000Z","size":989,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-24T01:57:05.065Z","etag":null,"topics":["generative-adversarial-network","tensorflow"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markdtw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-29T13:49:50.000Z","updated_at":"2022-01-17T15:28:46.000Z","dependencies_parsed_at":"2023-06-04T15:00:35.410Z","dependency_job_id":null,"html_url":"https://github.com/markdtw/least-squares-gan","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/markdtw/least-squares-gan","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markdtw%2Fleast-squares-gan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markdtw%2Fleast-squares-gan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markdtw%2Fleast-squares-gan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markdtw%2Fleast-squares-gan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markdtw","download_url":"https://codeload.github.com/markdtw/least-squares-gan/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markdtw%2Fleast-squares-gan/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30263673,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T14:54:00.943Z","status":"ssl_error","status_checked_at":"2026-03-08T14:53:54.486Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["generative-adversarial-network","tensorflow"],"created_at":"2024-11-13T13:41:29.139Z","updated_at":"2026-03-08T16:01:52.828Z","avatar_url":"https://github.com/markdtw.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Least Squares Generative Adversarial Networks\nTensorflow implementation of [Least Squares Generative Adversarial Networks by Mao et al](https://arxiv.org/abs/1611.04076) (LSGAN).\n\n## Prerequisites\n- Python 2.7+\n- [NumPy](http://www.numpy.org/)\n- [SciPy](https://www.scipy.org/)\n- [tqdm](https://pypi.python.org/pypi/tqdm)\n- [Tensorflow r1.0+](https://www.tensorflow.org/install/)\n- [lmdb](https://lmdb.readthedocs.io/en/release/) (for processing LSUN dataset only)\n\n\n## Data\n- [LSUN Scene Classification](http://lsun.cs.princeton.edu/)\n- [CelebA](http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html)\n\n\n## Preparation\n1. Clone this repo, create `ckpt/` folder:\n   ```bash\n   git clone https://github.com/markdtw/least-squares-gan.git\n   cd least-squares-gan\n   mkdir ckpt\n   ```\n2. To train on LSUN, use the [provided tools](https://github.com/fyu/lsun) to download and extract. For example:\n   ```bash\n   python download.py -c conference_room\n   unzip conference_room_train_lmdb.zip\n   python data.py export conference_room_train_lmdb --out_dir conference_room_train_images --flat\n   ```\n   I replaced _.webp_ from [this line](https://github.com/fyu/lsun/blob/master/data.py#L49) to _.jpg_\n\n3. To train on CelebA, I use [this file](https://github.com/carpedm20/DCGAN-tensorflow/blob/master/download.py) to download. Shout out to carpedm20.\n\n4. Now you are good to go, first time training on LSUN will center-crop all the images to 224x224 and store them in a new folder.\n\n## Train\nTrain on LSUN conference room with default settings:\n```bash\npython main.py --train\n```\nTrain on CelebA with default settings:\n```bash\npython main.py --train --dataset=CelebA\n```\nTrain from a previous checkpoint at epoch X:\n```bash\npython main.py --train --modelpath=ckpt/lsgan-LSUN\u003cCelebA\u003e-X\n```\nCheck out tunable hyper-parameters:\n```bash\npython main.py\n```\n\n## Some results\n\nEpoch 10:\n![ep-10](https://github.com/markdtw/least-squares-gan/blob/master/log/generated-ep-10.jpg)\n\nEpoch 25:\n![ep-25](https://github.com/markdtw/least-squares-gan/blob/master/log/generated-ep-25.jpg)\n\nEpoch 45:\n![ep-45](https://github.com/markdtw/least-squares-gan/blob/master/log/generated-ep-45.jpg)\n\nResults from epoch 45 is already nice and crispy.\n\nGenerator loss:\n![g-loss](https://github.com/markdtw/least-squares-gan/blob/master/log/gloss.png)\n\nDiscriminator loss:\n![d-loss](https://github.com/markdtw/least-squares-gan/blob/master/log/dloss.png)\n\n\n## Notes\n- The model will save 40 generated pictures in `log/` folder every epoch.\n- Initialization is important! Default initialization with `tf.xavier_initializer` will lead to either D or G's gradient vanishing problem, instead I use `tf.truncated_normal_initializer` which is identical to DCGAN original implementation to solve the problem.\n- Issues are more than welcome!\n\n\n## Resources\n- [The paper](https://arxiv.org/abs/1611.04076)\n- Highly based on [This repo](https://github.com/cameronfabbri/LSGANs-Tensorflow)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkdtw%2Fleast-squares-gan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkdtw%2Fleast-squares-gan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkdtw%2Fleast-squares-gan/lists"}