introduction to generative adversarial networks x_train x_train[y_train flatten(= selects frog images (class x_train x_train reshape(x_train shape[ ],(heightwidthchannels)astype('float ' iterations batch_size save_dir 'your_dirnormalizes data specifies where you want to save generated images start for step in range(iterations)random_latent_vectors np random normal(size=(batch_sizelatent_dim)decodes them to fake images generated_images generator predict(random_latent_vectorscombines them stop start batch_size with real images real_images x_train[startstopcombined_images np concatenate([generated_imagesreal_images]labels np concatenate([np ones((batch_size ))np zeros((batch_size ))]labels + np random random(labels shapetrains the discriminator assembles labels that say these are all real images(it' lie!samples random points in the latent space assembles labelsdiscriminating real from fake images d_loss discriminator train_on_batch(combined_imageslabelsrandom_latent_vectors np random normal(size=(batch_sizelatent_dim)samples random points in the latent space misleading_targets np zeros((batch_size )a_loss gan train_on_batch(random_latent_vectorsmisleading_targetsstart +batch_size if start len(x_trainbatch_sizestart if step = gan save_weights('gan 'prints metrics print('discriminator loss:'d_lossprint('adversarial loss:'a_lossadds random noise to the labels--an important tricktrains the generator (via the gan modelwhere the discriminator weights are frozenoccasionally saves and plots (every stepssaves model weights saves one generated image img image array_to_img(generated_images[ scale=falseimg save(os path join(save_dir'generated_frogstr(steppng')img image array_to_img(real_images[ scale=falseimg save(os path join(save_dir'real_frogstr(steppng')saves one real image for comparison licensed to