You are on page 1of 2

Resnet model Code Explanation

1. The code begins by importing the required libraries, including TensorFlow and the necessary
modules from keras.applications and keras.preprocessing.image.
2. In this step we completed the data pre-processing, data augmentation and image resizing
according to the model we are using.
3. Next, the pre-trained ResNet50 model is loaded using the ResNet50 function from
keras.applications. By setting weights='imagenet', we load the pre-trained weights trained on the
ImageNet dataset.
4. After loading the model, the final classification layer is modified to match the desired output
shape (None, 3). We add a global average pooling layer (GlobalAveragePooling2D) after the last
layer of the pre-trained model to reduce the spatial dimensions of the feature maps. Then, a
new Dense layer is added with 3 units and a softmax activation function to classify the images
into 3 classes.
5. The modified model is created using the Model class from keras.models. The input is set as the
input of the original model (base_model.input), and the output is set as the output of the newly
added layer (output).
6. The model is compiled using the compile method, specifying the optimizer, loss function, and
metrics for evaluation. In this case, the Adam optimizer, categorical cross-entropy loss, and
accuracy metric are used.
7. The model is trained using the fit method by passing the training dataset and the desired
number of epochs.
8. Finally, the model is evaluated on the complete dataset that is the test data as well as train data
using the model. Fit and later the performance of the model is compared and plotted.

GAN code implementation:


Initially we imported the necessary packages. The one unique package we are using is Conv2DTranspose
Transposed convolutional layers, sometimes referred to as deconvolution, are used when we need a
transform going in the opposite direction of a normal convolution.

Our generator is expecting image in n-dimension array form.

Next we created a class DCGAN with static method of build-generator and build_discriminator.

The build generator function takes the spatial dimensions, number of channels, dimension of random
generated vector and that of fully connected layer generated image. It has two set of layers in order of

FC -> RELU -> BN followed by image reshaping.We are using the stride (2,2) >1 to increase the spatial
resolution. We are using 3 channels to denote the RGB color cycle. For reshaping we need to keep in
mind that number of output nodes in the FC layer should be equal to the input shape.

The discriminator is simple network with 32 (5,5) filters followed by convolution layer. We are using only
single FC layer. All activation layers are Leaky RELU except the last one which is sigmoid function to
combine the probability whether the input is synthetic or real.
The data we are sending to our GAN is first imported , stored the addresses in the pandas dataframe,
shuffled and the corresponding to each address the image is stored in the array. Later this image is
resized.

The discriminator we build uses the Adam optimizer and binary cross entropy as the output is just a
probability of synthetic/ real image.

You might also like