[MXNET-580] Add SN-GAN example#12419
Conversation
…to sn_gan_example
| _u = self.u.data(CTX) | ||
| _v = None | ||
|
|
||
| for _ in range(1): |
There was a problem hiding this comment.
This for loop is executed only once? Do we need a loop in that case?
There was a problem hiding this comment.
The original paper use for loop to calculate the result. I should make it as a hyperparameter
|
|
||
| self.params.setattr('u', _u) | ||
|
|
||
| return w / sigma |
There was a problem hiding this comment.
Is there a chance that sigma would be 0?
There was a problem hiding this comment.
The chance is quite small but I would deal with that
|
Thanks for your contributions @stu1130 |
|
@stu1130 thanks for your contribution, can you add a README.md in the folder of the sn_gan with reference to papers / sample output etc. |
|
Please execute pylint on these files using ci/other/pylintrc in incubator-mxnet folder and fix errors (if any). pylint --rcfile=ci/other/pylintrc --ignore-patterns="..so$$,..dll$$,..dylib$$" example/gluon/sn-gan/*.py |
| BETA = 0.5 # beta1 for adam | ||
| OUTPUT_DIR = './data' # output directory | ||
| MANUAL_SEED = random.randint(1, 10000) # manual seed | ||
| CTX = mx.gpu() # change to gpu if you have gpu |
There was a problem hiding this comment.
I think I should use argparse to let the user specify parameters. And default value would be cpu.
sandeep-krishnamurthy
left a comment
There was a problem hiding this comment.
Very nice work @stu1130 :-) Few minor comments, please address
@ThomasDelteil - Ping.
example/gluon/sn-gan/README.md
Outdated
| @@ -0,0 +1,38 @@ | |||
| # Spectral Normalization GAN | |||
|
|
|||
| This example implements [Spectral Normalization for Generative Adversarial Networks](https://openreview.net/pdf?id=B1QRgziT-) based on [CIFAR10](https://www.cs.toronto.edu/~kriz/cifar.html) dataset. | |||
There was a problem hiding this comment.
Please refer to arxiv - https://arxiv.org/abs/1802.05957
example/gluon/sn-gan/README.md
Outdated
| Example runs and the results: | ||
|
|
||
| ```python | ||
| python train.py --use-gpu --data-path=data/CIFAR10 |
There was a problem hiding this comment.
Write a note that user needs to download CIFAR10 dataset
example/gluon/sn-gan/model.py
Outdated
|
|
||
| def __init__(self, num_filter, kernel_size, | ||
| strides, padding, in_channels, | ||
| ctx, iterations=1): |
There was a problem hiding this comment.
set default ctx=mx.cpu()
example/gluon/sn-gan/model.py
Outdated
| g_net = gluon.nn.Sequential() | ||
| with g_net.name_scope(): | ||
|
|
||
| g_net.add(gluon.nn.Conv2DTranspose(512, 4, 1, 0, use_bias=False)) |
There was a problem hiding this comment.
It is always more clear for readers in these kind of examples to have named parameters for these layers.
ThomasDelteil
left a comment
There was a problem hiding this comment.
Solid contribution, thanks @stu1130
example/gluon/sn-gan/data.py
Outdated
|
|
||
|
|
||
| def get_training_data(batch_size): | ||
| """ hepler function to get dataloader""" |
example/gluon/sn-gan/model.py
Outdated
| def spectral_norm(self): | ||
| """ spectral normalization """ | ||
| w = self.params.get('weight').data(self.ctx) | ||
| w_mat = w |
There was a problem hiding this comment.
I don't think this is necessary, you can simply use w in your nd.reshape(w_mat..
example/gluon/sn-gan/model.py
Outdated
| self.u = self.params.get( | ||
| 'u', init=mx.init.Normal(), shape=(1, num_filter)) | ||
|
|
||
| def spectral_norm(self): |
There was a problem hiding this comment.
I would suggest using _spectral_norm(self) as it is a private function
example/gluon/sn-gan/train.py
Outdated
| parser.add_argument('--lr', type=float, default=0.0001, | ||
| help='learning rate. default is 0.0001.') | ||
| parser.add_argument('--lr-beta', type=float, default=0.5, | ||
| help='learning rate for the beta in margin based loss. default is 0.5s.') |
There was a problem hiding this comment.
0.5s ? what does s stand for here?
| @@ -0,0 +1,40 @@ | |||
| # Spectral Normalization GAN | |||
There was a problem hiding this comment.
Please update https://github.com/apache/incubator-mxnet/tree/master/example#deep-learning-examples-in-the-mxnet-project-repository with your example, thanks!
| ## Learned Spectral Normalization | ||
|
|
||
|  | ||
|
|
There was a problem hiding this comment.
Could you add a few samples of the generated images? It always makes it more appealing for people looking to try new models. Thanks!
There was a problem hiding this comment.
I am running the model with Xavier initializer and will update the image if it's better
stu1130
left a comment
There was a problem hiding this comment.
Thanks @ThomasDelteil
| ## Learned Spectral Normalization | ||
|
|
||
|  | ||
|
|
There was a problem hiding this comment.
I am running the model with Xavier initializer and will update the image if it's better
example/gluon/sn_gan/model.py
Outdated
| """ spectral normalization """ | ||
| w = self.params.get('weight').data(self.ctx) | ||
| # the w preserve the original weight value to be used in line 75 | ||
| w_mat = w |
There was a problem hiding this comment.
w is needed to be used for calculation later in the line 75
There was a problem hiding this comment.
assignment does not create a copy, reshape creates a copy. you can use:
w_mat = nd.reshape(w, [w.shape[0], -1])
example/gluon/sn_gan/README.md
Outdated
| --epochs EPOCHS number of training epochs. default is 100. | ||
| --lr LR learning rate. default is 0.0001. | ||
| --lr-beta LR_BETA learning rate for the beta in margin based loss. | ||
| default is 0.5s. |
There was a problem hiding this comment.
nit: the s is also here still
sandeep-krishnamurthy
left a comment
There was a problem hiding this comment.
Thanks, a very useful contribution.
This reverts commit 46a5cee.
* Revert "Removing the re-size for validation data, which breaking the validation accuracy of CIFAR training (#12362)" This reverts commit ceabcaa. * Revert "[MXNET-580] Add SN-GAN example (#12419)" This reverts commit 46a5cee. * Revert "Remove regression checks for website links (#12507)" This reverts commit 619bc3e. * Revert "Revert "Fix flaky test: test_mkldnn.test_activation #12377 (#12418)" (#12516)" This reverts commit 7ea0533. * Revert "further bump up tolerance for sparse dot (#12527)" This reverts commit 90599e1. * Revert "Fix broken URLs (#12508)" This reverts commit 3d83c89. * Revert "Temporarily disable flaky tests (#12520)" This reverts commit 35ca13c. * Revert "Add support for more req patterns for bilinear sampler backward (#12386)" This reverts commit 4ee866f. * Revert "Change the way NDArrayIter handle the last batch (#12285)" This reverts commit 597a637.
* update sn-gan example * fix naming * add more comments * fix naming and refine comments * make power iteration as one hyperparameter * deal with divided by zero problem * replace 0.00000001 with EPSILON * refactor the example * add README * address the feedback * refine the composing * fix the typo, delete the redundant piece of code and update the result image * update folder name to align with others * update image name * add the variable back * remove the redundant piece of code and fix typo
* Revert "Removing the re-size for validation data, which breaking the validation accuracy of CIFAR training (apache#12362)" This reverts commit ceabcaa. * Revert "[MXNET-580] Add SN-GAN example (apache#12419)" This reverts commit 46a5cee. * Revert "Remove regression checks for website links (apache#12507)" This reverts commit 619bc3e. * Revert "Revert "Fix flaky test: test_mkldnn.test_activation apache#12377 (apache#12418)" (apache#12516)" This reverts commit 7ea0533. * Revert "further bump up tolerance for sparse dot (apache#12527)" This reverts commit 90599e1. * Revert "Fix broken URLs (apache#12508)" This reverts commit 3d83c89. * Revert "Temporarily disable flaky tests (apache#12520)" This reverts commit 35ca13c. * Revert "Add support for more req patterns for bilinear sampler backward (apache#12386)" This reverts commit 4ee866f. * Revert "Change the way NDArrayIter handle the last batch (apache#12285)" This reverts commit 597a637.
Description
Add Spectral Normalization GAN example
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.
Changes
Spectral Normalization GAN example
Comments
N/A