'How to feed a non-fixed noise to GAN network?

I have created a GAN network for image generation, as we know that output of GAN network is related on the size of noise that we feed it with. so for some GAN's sometimes it's better to change the fixed noise input to non-fixed noise to get the desired output.

I tried here not to explicitly feed the size of the noise to the generator, and my code worked during the training phase but in the inference time the model still wants the noise to be in same size of the noise it have been feed with during the training phase. I'm wondering how the generator code could be changed so the model can accept a non-fixed noise?

the generator network

D1 = np.random.rand(160)

def build_generator():


    generator = Sequential()
    
    generator.add(InputLayer(input_shape=(len(D1))))
    generator.add(Flatten()) 
    generator.add(Dense(128 * 16 * 16))
    generator.add(Reshape((16, 16, 128)))
    .....
    .....
    generator.summary()
    
    noise = Input(shape=(len(D1)))
    fake_image = generator(noise)
    return Model(inputs=noise, outputs=fake_image)

the combined model:

generator = build_generator()

z = Input(shape=(len(D1)))
img = generator(z)

# The discriminator takes generated images as input and determines their validity.
valid = discriminator(img)

combined = Model(inputs=z, outputs=valid)
combined.compile(loss='binary_crossentropy', optimizer=optimizer)

the training function

def train(epochs, batch_size, save_interval):
    
    # Adversarial ground truths
    valid = np.ones((batch_size, 1))
    fake = np.zeros((batch_size, 1))
    
    save_dir =  '/home/ubuntech/Gall'
    # create new folder if not exist
    if not os.path.exists(save_dir):
        os.makedirs(save_dir)
    
    for epoch in range(epochs):
        
        ## Train Discriminator network
        
        # Selects a random half of images
        idx = np.random.randint(0, X_train.shape[0], batch_size)
        imgs = X_train[idx]

        noise = np.full((batch_size,len(D1)), D1)
        gen_imgs = generator.predict(noise)
        .......
        .......

unfortunately there's no much literature about this topic(non-static or non-fixed noise).



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source