codes/Python/p04-advanced/1-conditional-DCGAN/conditional-DCGAN.py
def visualize(epoch, batch_size=256, save_model=False):
    '''
    get samples from G network and save it to samples directory (exception will be occurred if samples directory not exists)

    Args:
        epoch: epoch number which we are currently at
        batch_size: number of images sampled from G
        save_model: whether save G and D model or not
    '''
    global G_net, D_real, G_tensorboard_writer

    # check if folder exist
    if not os.path.isdir('samples'):
        os.mkdir('samples')
    p = 'samples/epoch{:05d}'.format(epoch)
    if os.path.isdir(p):
        shutil.rmtree(p)
    os.mkdir(p)
    _, samples, codes = G_sampler(G_net, batch_size)
    for ind, i in enumerate(zip(samples, codes.toarray())):
        code = np.argmax(i[1])
        img = (i[0] + 1) * 127
        img = img.reshape((28, 28))
        cv2.imwrite('samples/epoch{:05d}/epoch{:05d}_ind{:03d}_code{}.jpg'.format(epoch, epoch, ind, code), img)

    if save_model:
        G_net.save(os.path.join(cwd, 'samples', 'epoch{:05d}', 'G_{:05d}.cntk').format(epoch, epoch))
        D_real.save_checkpoint(os.path.join(cwd, 'samples', 'epoch{:05d}', 'D_{:05d}.cntk').format(epoch, epoch))

    get samples from G network and save it to samples directory (exception will be occurred if samples directory not exists)

    Args:
        epoch: epoch number which we are currently at
        batch_size: number of images sampled from G
        save_model: whether save G and D model or not
    
get samples from G network and save it to samples directory (exception will be occurred if samples directory not exists)
get samples from G network and save it to samples directory ( exception will be occurred if samples directory not exists )
def visualize(epoch, batch_size=256, save_model=False):
    global G_net, D_real, G_tensorboard_writer
    if not os.path.isdir('samples'):
        os.mkdir('samples')
    p = 'samples/epoch{:05d}'.format(epoch)
    if os.path.isdir(p):
        shutil.rmtree(p)
    os.mkdir(p)
    _, samples, codes = G_sampler(G_net, batch_size)
    for ind, i in enumerate(zip(samples, codes.toarray())):
        code = np.argmax(i[1])
        img = (i[0] + 1) * 127
        img = img.reshape((28, 28))
        cv2.imwrite('samples/epoch{:05d}/epoch{:05d}_ind{:03d}_code{}.jpg'.format(epoch, epoch, ind, code), img)
    if save_model:
        G_net.save(os.path.join(cwd, 'samples', 'epoch{:05d}', 'G_{:05d}.cntk').format(epoch, epoch))
        D_real.save_checkpoint(os.path.join(cwd, 'samples', 'epoch{:05d}', 'D_{:05d}.cntk').format(epoch, epoch))
def visualize ( epoch , batch_size = 256 , save_model = False ) : global G_net , D_real , G_tensorboard_writer if not os . path . isdir ( 'samples' ) : os . mkdir ( 'samples' ) p = 'samples/epoch{:05d}' . format ( epoch ) if os . path . isdir ( p ) : shutil . rmtree ( p ) os . mkdir ( p ) _ , samples , codes = G_sampler ( G_net , batch_size ) for ind , i in enumerate ( zip ( samples , codes . toarray ( ) ) ) : code = np . argmax ( i [ 1 ] ) img = ( i [ 0 ] + 1 ) * 127 img = img . reshape ( ( 28 , 28 ) ) cv2 . imwrite ( 'samples/epoch{:05d}/epoch{:05d}_ind{:03d}_code{}.jpg' . format ( epoch , epoch , ind , code ) , img ) if save_model : G_net . save ( os . path . join ( cwd , 'samples' , 'epoch{:05d}' , 'G_{:05d}.cntk' ) . format ( epoch , epoch ) ) D_real . save_checkpoint ( os . path . join ( cwd , 'samples' , 'epoch{:05d}' , 'D_{:05d}.cntk' ) . format ( epoch , epoch ) )
get samples from G network and save it to samples directory (exception will be occurred if samples directory not exists)
get samples from G network and save it to samples directory ( exception will be occurred if samples directory not exists )
'''
    get samples from G network and save it to samples directory (exception will be occurred if samples directory not exists)

    Args:
        epoch: epoch number which we are currently at
        batch_size: number of images sampled from G
        save_model: whether save G and D model or not
    ''' # check if folder exist
epoch
epoch number which we are currently at
epoch number which we are currently at
batch_size
number of images sampled from G
number of images sampled from G
save_model
whether save G and D model or not
whether save G and D model or not