sandeep-krishnamurthy commented on a change in pull request #12790: Extending 
the DCGAN example implemented by gluon API to provide a more straight-forward 
evaluation on the generated image
URL: https://github.com/apache/incubator-mxnet/pull/12790#discussion_r225283574
 
 

 ##########
 File path: example/gluon/DCgan/dcgan.py
 ##########
 @@ -0,0 +1,317 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import matplotlib as mpl
+mpl.use('Agg')
+from matplotlib import pyplot as plt
+
+import argparse
+import mxnet as mx
+from mxnet import gluon
+from mxnet.gluon import nn
+from mxnet import autograd
+import numpy as np
+import logging
+from datetime import datetime
+import os
+import time
+
+from inception_score import get_inception_score
+
+def fill_buf(buf, i, img, shape):
+    n = buf.shape[0]//shape[1]
+    m = buf.shape[1]//shape[0]
+
+    sx = (i%m)*shape[0]
+    sy = (i//m)*shape[1]
+    buf[sy:sy+shape[1], sx:sx+shape[0], :] = img
+    return None
+
+def visual(title, X, name):
+    assert len(X.shape) == 4
+    X = X.transpose((0, 2, 3, 1))
+    X = np.clip((X - np.min(X))*(255.0/(np.max(X) - np.min(X))), 0, 
255).astype(np.uint8)
+    n = np.ceil(np.sqrt(X.shape[0]))
+    buff = np.zeros((int(n*X.shape[1]), int(n*X.shape[2]), int(X.shape[3])), 
dtype=np.uint8)
+    for i, img in enumerate(X):
+        fill_buf(buff, i, img, X.shape[1:3])
+    buff = buff[:,:,::-1]
+    plt.imshow(buff)
+    plt.title(title)
+    plt.savefig(name)
+
+
+parser = argparse.ArgumentParser()
+parser = argparse.ArgumentParser(description='Train a DCgan model for image 
generation '
+                                             'and then use inception_score to 
metric the result.')
+parser.add_argument('--dataset', type=str, default='cifar10', help='dataset to 
use. options are cifar10 and mnist.')
+parser.add_argument('--batch-size', type=int, default=64, help='input batch 
size')
+parser.add_argument('--nz', type=int, default=100, help='size of the latent z 
vector')
+parser.add_argument('--ngf', type=int, default=64, help='the channel of each 
generator filter layer.')
+parser.add_argument('--ndf', type=int, default=64, help='the channel of each 
descriminator filter layer.')
+parser.add_argument('--nepoch', type=int, default=25, help='number of epochs 
to train for')
+parser.add_argument('--lr', type=float, default=0.0002, help='learning rate, 
default=0.0002')
+parser.add_argument('--beta1', type=float, default=0.5, help='beta1 for adam. 
default=0.5')
+parser.add_argument('--cuda', action='store_true', help='enables cuda')
+parser.add_argument('--ngpu', type=int, default=1, help='number of GPUs to 
use')
+parser.add_argument('--netG', default='', help="path to netG (to continue 
training)")
+parser.add_argument('--netD', default='', help="path to netD (to continue 
training)")
+parser.add_argument('--outf', default='./results', help='folder to output 
images and model checkpoints')
+parser.add_argument('--check-point', default=True, help="save results at each 
epoch or not")
+parser.add_argument('--inception_score', type=bool, default=True, help='To 
record the inception_score, default is True.')
+
+opt = parser.parse_args()
+print(opt)
+
+logging.basicConfig(level=logging.DEBUG)
+ngpu = int(opt.ngpu)
+nz = int(opt.nz)
+ngf = int(opt.ngf)
+ndf = int(opt.ndf)
+nc = 3
+if opt.cuda:
+    ctx = mx.gpu(0)
 
 Review comment:
   not using ngpu?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to