def main():
    """Entry point to dcgan"""
    print("|------- new changes!!!!!!!!!")
    # to get the dataset and net configuration
    train_data, val_data = get_dataset(dataset)
    netG = get_netG()
    netD = get_netD()
    loss, trainerG, trainerD = get_configurations(netG, netD)

    # set labels
    real_label = mx.nd.ones((opt.batch_size,), ctx=ctx)
    fake_label = mx.nd.zeros((opt.batch_size,), ctx=ctx)

    metric = mx.metric.Accuracy()
    print('Training... ')
    stamp = datetime.now().strftime('%Y_%m_%d-%H_%M')

    iter = 0

    # to metric the network
    loss_d = []
    loss_g = []
    inception_score = []

    for epoch in range(opt.nepoch):
        tic = time.time()
        btic = time.time()
        for data, _ in train_data:
            ############################
            # (1) Update D network: maximize log(D(x)) + log(1 - D(G(z)))
            ###########################
            # train with real_t
            data = data.as_in_context(ctx)
            noise = mx.nd.random.normal(0, 1, shape=(opt.batch_size, nz, 1, 1), ctx=ctx)

            with autograd.record():
                output = netD(data)
                # reshape output from (opt.batch_size, 2, 1, 1) to (opt.batch_size, 2)
                output = output.reshape((opt.batch_size, 2))
                errD_real = loss(output, real_label)

            metric.update([real_label, ], [output, ])

            with autograd.record():
                fake = netG(noise)
                output = netD(fake.detach())
                output = output.reshape((opt.batch_size, 2))
                errD_fake = loss(output, fake_label)
                errD = errD_real + errD_fake

            errD.backward()
            metric.update([fake_label,], [output,])

            trainerD.step(opt.batch_size)

            ############################
            # (2) Update G network: maximize log(D(G(z)))
            ###########################
            with autograd.record():
                output = netD(fake)
                output = output.reshape((-1, 2))
                errG = loss(output, real_label)

            errG.backward()

            trainerG.step(opt.batch_size)

            name, acc = metric.get()
            logging.info('discriminator loss = %f, generator loss = %f, binary training acc = %f at iter %d epoch %d'
                         , mx.nd.mean(errD).asscalar(), mx.nd.mean(errG).asscalar(), acc, iter, epoch)
            if iter % niter == 0:
                visual('gout', fake.asnumpy(), name=os.path.join(outf, 'fake_img_iter_%d.png' % iter))
                visual('data', data.asnumpy(), name=os.path.join(outf, 'real_img_iter_%d.png' % iter))
                # record the metric data
                loss_d.append(errD)
                loss_g.append(errG)
                if opt.inception_score:
                    score, _ = get_inception_score(fake)
                    inception_score.append(score)

            iter = iter + 1
            btic = time.time()

        name, acc = metric.get()
        metric.reset()
        logging.info('\nbinary training acc at epoch %d: %s=%f', epoch, name, acc)
        logging.info('time: %f', time.time() - tic)

        # save check_point
        if check_point:
            netG.save_parameters(os.path.join(outf, 'generator_epoch_%d.params' %epoch))
            netD.save_parameters(os.path.join(outf, 'discriminator_epoch_%d.params' % epoch))

    # save parameter
    netG.save_parameters(os.path.join(outf, 'generator.params'))
    netD.save_parameters(os.path.join(outf, 'discriminator.params'))

    # visualization the inception_score as a picture
    if opt.inception_score:
        ins_save(inception_score)
Entry point to dcgan