Tuesday, May 25, 2021

Generator for DCGAN

 Following is the code for generator for MNIST DCGAN 


import tensorflow as tf 
from tensorflow import keras 
from keras import layers 
import matplotlib.pyplot as plt 



img_height = 40 
img_width  = 80 

model = keras.models.Sequential()

model.add(layers.Dense(img_height/4 * img_width /4 * 256 , use_bias = False
                       input_shape = (100,)))
model.add(layers.BatchNormalization())
model.add(layers.LeakyReLU())

model.add(layers.Reshape(( int(img_height/4) , int(img_width/4) , 256)))


model.add(layers.Conv2DTranspose(128 , 5, strides = 1 , padding = "same" , 
                                 use_bias = False))
model.add(layers.BatchNormalization())
model.add(layers.LeakyReLU())


model.add(layers.Conv2DTranspose(645, strides = 2 , use_bias = False
                                 padding = "same"))
model.add(layers.BatchNormalization())
model.add(layers.LeakyReLU())


model.add(layers.Conv2DTranspose(15, strides = 2 , use_bias = False , 
                                 padding = "same"))


noise = tf.random.normal([1,100])
gen_image = model(noise , training = False)

plt.imshow(gen_image[0, :, :, 0])


No comments:

Post a Comment

 using Microsoft.AspNetCore.Mvc; using System.Xml.Linq; using System.Xml.XPath; //<table class="common-table medium js-table js-stre...