codes/Python/p04-advanced/1-conditional-DCGAN/conditional-DCGAN.py
def create_mb_for_D(mb_size):
    '''
    data generator to train Detector network

    Args:
        mb_size: number of samples of minibatch

    Returns:
        real_image, real_code, z (random state) and fake_code all have the same size determined by mb_size
    '''
    global real_img, real_code

    counter = 0
    while True:
        # create fake batch
        z, fake_img, fake_code = G_sampler(G_net, mb_size)

        # create real batch
        if counter + mb_size < train_set_len:
            yield real_img[counter:counter + mb_size].reshape((mb_size, 1, img_h, img_w)), real_code[counter:counter + mb_size], z, fake_code
            counter += mb_size
        else:
            # shuffle
            p = np.random.permutation(real_code.shape[0])
            real_img, real_code = real_img[p], real_code[p]
            counter = 0
            yield real_img[counter:counter + mb_size].reshape((mb_size, 1, img_h, img_w)), real_code[counter:counter + mb_size], z, fake_code

    data generator to train Detector network

    Args:
        mb_size: number of samples of minibatch

    Returns:
        real_image, real_code, z (random state) and fake_code all have the same size determined by mb_size
    
data generator to train Detector network
data generator to train Detector network
def create_mb_for_D(mb_size):
    global real_img, real_code
    counter = 0
    while True:
        z, fake_img, fake_code = G_sampler(G_net, mb_size)
        if counter + mb_size < train_set_len:
            yield real_img[counter:counter + mb_size].reshape((mb_size, 1, img_h, img_w)), real_code[counter:counter + mb_size], z, fake_code
            counter += mb_size
        else:
            p = np.random.permutation(real_code.shape[0])
            real_img, real_code = real_img[p], real_code[p]
            counter = 0
            yield real_img[counter:counter + mb_size].reshape((mb_size, 1, img_h, img_w)), real_code[counter:counter + mb_size], z, fake_code
def create_mb_for_D ( mb_size ) : global real_img , real_code counter = 0 while True : z , fake_img , fake_code = G_sampler ( G_net , mb_size ) if counter + mb_size < train_set_len : yield real_img [ counter : counter + mb_size ] . reshape ( ( mb_size , 1 , img_h , img_w ) ) , real_code [ counter : counter + mb_size ] , z , fake_code counter += mb_size else : p = np . random . permutation ( real_code . shape [ 0 ] ) real_img , real_code = real_img [ p ] , real_code [ p ] counter = 0 yield real_img [ counter : counter + mb_size ] . reshape ( ( mb_size , 1 , img_h , img_w ) ) , real_code [ counter : counter + mb_size ] , z , fake_code
data generator to train Detector network
data generator to train Detector network
'''
    data generator to train Detector network

    Args:
        mb_size: number of samples of minibatch

    Returns:
        real_image, real_code, z (random state) and fake_code all have the same size determined by mb_size
    ''' # create fake batch # create real batch # shuffle
real_image, real_code, z (random state) and fake_code all have the same size determined by mb_size
real_image real_code z ( random state ) and fake_code all have the same size determined by mb_size
mb_size
number of samples of minibatch
number of samples of minibatch