{"id":21216728,"url":"https://github.com/mingtaoguo/sngan_projection_tensorflow","last_synced_at":"2025-07-10T11:32:30.852Z","repository":{"id":168646440,"uuid":"156538468","full_name":"MingtaoGuo/sngan_projection_TensorFlow","owner":"MingtaoGuo","description":"Simply implement the paper: cGANs with Projection Discriminator by TensorFlow","archived":false,"fork":false,"pushed_at":"2019-04-19T03:17:05.000Z","size":816,"stargazers_count":40,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-05T13:11:18.574Z","etag":null,"topics":["gan","sngan","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MingtaoGuo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2018-11-07T11:46:56.000Z","updated_at":"2022-11-16T11:17:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"d880cf23-8b56-4e87-b5f5-4fa8ed21a7a5","html_url":"https://github.com/MingtaoGuo/sngan_projection_TensorFlow","commit_stats":null,"previous_names":["mingtaoguo/sngan_projection_tensorflow"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MingtaoGuo/sngan_projection_TensorFlow","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MingtaoGuo%2Fsngan_projection_TensorFlow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MingtaoGuo%2Fsngan_projection_TensorFlow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MingtaoGuo%2Fsngan_projection_TensorFlow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MingtaoGuo%2Fsngan_projection_TensorFlow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MingtaoGuo","download_url":"https://codeload.github.com/MingtaoGuo/sngan_projection_TensorFlow/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MingtaoGuo%2Fsngan_projection_TensorFlow/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264573170,"owners_count":23630436,"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":["gan","sngan","tensorflow"],"created_at":"2024-11-20T21:55:24.494Z","updated_at":"2025-07-10T11:32:30.847Z","avatar_url":"https://github.com/MingtaoGuo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sngan_projection_TensorFlow\nSimply implementing the paper: cGANs with Projection Discriminator\n\n## Introduction\nSNGAN with projection discriminator implemented by TensorFlow. The paper [cGANs with Projection Discriminator](https://arxiv.org/pdf/1802.05637v1.pdf)\n\n![](https://github.com/MingtaoGuo/sngan_projection_TensorFlow/blob/master/IMAGES/projection.jpg)\n## Results\n### More results are under training ......\n### Generate cifar-10\n![](https://github.com/MingtaoGuo/sngan_projection_TensorFlow/blob/master/IMAGES/cifar.jpg)\n\nAs shown in below is trained about 10000 iterations with batch size of 64.\n\n![](https://github.com/MingtaoGuo/sngan_projection_TensorFlow/blob/master/IMAGES/generate.jpg)\n#### Consecutive category morphing with fixed z:\n|cat2human|cat2human|zi2zi|zi2zi|\n|-|-|-|-|\n|![](https://github.com/MingtaoGuo/sngan_projection_TensorFlow/blob/master/IMAGES/1.gif)|![](https://github.com/MingtaoGuo/sngan_projection_TensorFlow/blob/master/IMAGES/2.gif)|![](https://github.com/MingtaoGuo/sngan_projection_TensorFlow/blob/master/IMAGES/character.gif)|![](https://github.com/MingtaoGuo/sngan_projection_TensorFlow/blob/master/IMAGES/character1.gif)|\n\n#### What is conditional batch normalization?\nMore details about 'condition', please see this repository: [Conditional Instance Normalization for n style transfer](https://github.com/MingtaoGuo/Conditional-Instance-Norm-for-n-Style-Transfer)\n``` python\ndef conditional_batchnorm(x, train_phase, scope_bn, y=None, nums_class=10):\n    #Batch Normalization\n    #Ioffe S, Szegedy C. Batch normalization: accelerating deep network training by reducing internal covariate shift[J]. 2015:448-456.\n    with tf.variable_scope(scope_bn):\n        if y == None:\n            beta = tf.get_variable(name=scope_bn + 'beta', shape=[x.shape[-1]],\n                                   initializer=tf.constant_initializer([0.]), trainable=True)  # label_nums x C\n            gamma = tf.get_variable(name=scope_bn + 'gamma', shape=[x.shape[-1]],\n                                    initializer=tf.constant_initializer([1.]), trainable=True)  # label_nums x C\n        else:\n            beta = tf.get_variable(name=scope_bn + 'beta', shape=[nums_class, x.shape[-1]],\n                                   initializer=tf.constant_initializer([0.]), trainable=True)  # label_nums x C\n            gamma = tf.get_variable(name=scope_bn + 'gamma', shape=[nums_class, x.shape[-1]],\n                                    initializer=tf.constant_initializer([1.]), trainable=True)  # label_nums x C\n            beta, gamma = tf.nn.embedding_lookup(beta, y), tf.nn.embedding_lookup(gamma, y)\n            beta = tf.reshape(beta, [-1, 1, 1, x.shape[-1]])\n            gamma = tf.reshape(gamma, [-1, 1, 1, x.shape[-1]])\n        batch_mean, batch_var = tf.nn.moments(x, [0, 1, 2], name='moments', keep_dims=True)\n        ema = tf.train.ExponentialMovingAverage(decay=0.5)\n\n        def mean_var_with_update():\n            ema_apply_op = ema.apply([batch_mean, batch_var])\n            with tf.control_dependencies([ema_apply_op]):\n                return tf.identity(batch_mean), tf.identity(batch_var)\n\n        mean, var = tf.cond(train_phase, mean_var_with_update,\n                            lambda: (ema.average(batch_mean), ema.average(batch_var)))\n        normed = tf.nn.batch_normalization(x, mean, var, beta, gamma, 1e-3)\n    return normed\n```\n#### What is projection?\n``` python\ndef Inner_product(global_pooled, y):\n    #global_pooled: B x D,   embeded_y: B x Num_label\n    H = y.shape[-1]\n    W = global_pooled.shape[-1]\n    V = tf.get_variable(\"V\", [H, W], initializer=tf.truncated_normal_initializer(stddev=0.02))\n    V = spectral_normalization(\"embed\", V)\n    temp = tf.matmul(y, V)\n    temp = tf.reduce_sum(temp * global_pooled, axis=1)\n    return temp\n```\n## How to use\n1. Download the [ImageNet_64x64](https://patrykchrabaszcz.github.io/Imagenet32/) dataset. \n     *PS.* If necessary, you can contact me, E-mail: gmt798714378@hotmail.com, i will send a part of dataset to you :stuck_out_tongue_winking_eye:.  \n2. Put the imagenet dataset into the folder 'dataset'\n```\n├── dataset\n    ├── 1\n        ├── 0.jpg\n        ├── 1.jpg\n        ...\n    ├── 2\n        ├── 0.jpg\n        ├── 1.jpg\n        ...\n    ├── 3\n        ├── 0.jpg\n        ├── 1.jpg\n        ...\n    ...\n    ├── 1000\n        ├── 0.jpg\n        ├── 1.jpg\n        ...\n├── save_para\n├── save_img\n├── results\n├── main.py\n├── networks.py\n├── ops.py\n├── Train.py\n├── utils.py\n```\n3. Execute main.py\n## Requirements\n- python3.5\n- tensorflow1.4.0\n- numpy\n- scipy\n- pillow\n\n### Acknowledgement\n[Author's chainer code](https://github.com/pfnet-research/sngan_projection)  \n### Reference\n[1]. Miyato T, Koyama M. cGANs with Projection Discriminator[J]. 2018.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmingtaoguo%2Fsngan_projection_tensorflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmingtaoguo%2Fsngan_projection_tensorflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmingtaoguo%2Fsngan_projection_tensorflow/lists"}