SlideShare a Scribd company logo
Using the code below, I need help with creating code for the following:
1) Write Python code to plot the images from the first epoch. Take a screenshot of the images
from the first epoch.
2) Write Python code to plot the images from the last epoch. Take a screenshot of the images
from the last epoch.
#Step 1: Import the required Python libraries:
import numpy as np
import matplotlib.pyplot as plt
import keras
from keras.layers import Input, Dense, Reshape, Flatten, Dropout
from keras.layers import BatchNormalization, Activation, ZeroPadding2D
from keras.layers import LeakyReLU
from keras.layers.convolutional import UpSampling2D, Conv2D
from keras.models import Sequential, Model
from keras.optimizers import Adam,SGD
from keras.datasets import cifar10
#Step 2: Load the data.
#Loading the CIFAR10 data
(X, y), (_, _) = keras.datasets.cifar10.load_data()
#Selecting a single class of images
#The number was randomly chosen and any number
#between 1 and 10 can be chosen
X = X[y.flatten() == 8]
#Step 3: Define parameters to be used in later processes.
#Defining the Input shape
image_shape = (32, 32, 3)
latent_dimensions = 100
#Step 4: Define a utility function to build the generator.
def build_generator():
model = Sequential()
#Building the input layer
model.add(Dense(128 * 8 * 8, activation="relu",
input_dim=latent_dimensions))
model.add(Reshape((8, 8, 128)))
model.add(UpSampling2D())
model.add(Conv2D(128, kernel_size=3, padding="same"))
model.add(BatchNormalization(momentum=0.78))
model.add(Activation("relu"))
model.add(UpSampling2D())
model.add(Conv2D(64, kernel_size=3, padding="same"))
model.add(BatchNormalization(momentum=0.78))
model.add(Activation("relu"))
model.add(Conv2D(3, kernel_size=3, padding="same"))
model.add(Activation("tanh"))
#Generating the output image
noise = Input(shape=(latent_dimensions,))
image = model(noise)
return Model(noise, image)
#Step 5: Define a utility function to build the discriminator.
def build_discriminator():
#Building the convolutional layers
#to classify whether an image is real or fake
model = Sequential()
model.add(Conv2D(32, kernel_size=3, strides=2,
input_shape=image_shape, padding="same"))
model.add(LeakyReLU(alpha=0.2))
model.add(Dropout(0.25))
model.add(Conv2D(64, kernel_size=3, strides=2, padding="same"))
model.add(ZeroPadding2D(padding=((0,1),(0,1))))
model.add(BatchNormalization(momentum=0.82))
model.add(LeakyReLU(alpha=0.25))
model.add(Dropout(0.25))
model.add(Conv2D(128, kernel_size=3, strides=2, padding="same"))
model.add(BatchNormalization(momentum=0.82))
model.add(LeakyReLU(alpha=0.2))
model.add(Dropout(0.25))
model.add(Conv2D(256, kernel_size=3, strides=1, padding="same"))
model.add(BatchNormalization(momentum=0.8))
model.add(LeakyReLU(alpha=0.25))
model.add(Dropout(0.25))
#Building the output layer
model.add(Flatten())
model.add(Dense(1, activation='sigmoid'))
image = Input(shape=image_shape)
validity = model(image)
return Model(image, validity)
#Step 6: Define a utility function to display the generated images.
def display_images():
r, c = 4,4
noise = np.random.normal(0, 1, (r * c,latent_dimensions))
generated_images = generator.predict(noise)
#Scaling the generated images
generated_images = 0.5 * generated_images + 0.5
fig, axs = plt.subplots(r, c)
count = 0
for i in range(r):
for j in range(c):
axs[i,j].imshow(generated_images[count, :,:,])
axs[i,j].axis('off')
count += 1
plt.show()
plt.close()
#Step 7: Build the GAN.
# Building and compiling the discriminator
discriminator = build_discriminator()
discriminator.compile(loss='binary_crossentropy',
optimizer=Adam(0.0002,0.5),
metrics=['accuracy'])
#Making the discriminator untrainable
#so that the generator can learn from fixed gradient
discriminator.trainable = False
# Building the generator
generator = build_generator()
#Defining the input for the generator
#and generating the images
z = Input(shape=(latent_dimensions,))
image = generator(z)
#Checking the validity of the generated image
valid = discriminator(image)
#Defining the combined model of the generator and the discriminator
combined_network = Model(z, valid)
combined_network.compile(loss='binary_crossentropy',
optimizer=Adam(0.0002,0.5))
#Step 8: Train the network.
num_epochs=15000
batch_size=32
display_interval=2500
losses=[]
#Normalizing the input
X = (X / 127.5) - 1.
#Defining the Adversarial ground truths
valid = np.ones((batch_size, 1))
#Adding some noise
valid += 0.05 * np.random.random(valid.shape)
fake = np.zeros((batch_size, 1))
fake += 0.05 * np.random.random(fake.shape)
for epoch in range(num_epochs):
#Training the Discriminator
#Sampling a random half of images
index = np.random.randint(0, X.shape[0], batch_size)
images = X[index]
#Sampling noise and generating a batch of new images
noise = np.random.normal(0, 1, (batch_size, latent_dimensions))
generated_images = generator.predict(noise)
#Training the discriminator to detect more accurately
#whether a generated image is real or fake
discm_loss_real = discriminator.train_on_batch(images, valid)
discm_loss_fake = discriminator.train_on_batch(generated_images, fake)
discm_loss = 0.5 * np.add(discm_loss_real, discm_loss_fake)
#Training the generator
#Training the generator to generate images
#that pass the authenticity test
genr_loss = combined_network.train_on_batch(noise, valid)
#Tracking the progress
if epoch % display_interval == 0:
display_images()

More Related Content

Similar to Using the code below- I need help with creating code for the following.pdf (20)

I have tried running this code below- and it is working- but the accur.pdf
I have tried running this code below- and it is working- but the accur.pdfI have tried running this code below- and it is working- but the accur.pdf
I have tried running this code below- and it is working- but the accur.pdf
GordonF2XPatersonh
 
Teach a neural network to read handwriting
Teach a neural network to read handwritingTeach a neural network to read handwriting
Teach a neural network to read handwriting
Vipul Kaushal
 
Tutorial: Image Generation and Image-to-Image Translation using GAN
Tutorial: Image Generation and Image-to-Image Translation using GANTutorial: Image Generation and Image-to-Image Translation using GAN
Tutorial: Image Generation and Image-to-Image Translation using GAN
Wuhyun Rico Shin
 
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Codemotion
 
CNN_INTRO.pptx
CNN_INTRO.pptxCNN_INTRO.pptx
CNN_INTRO.pptx
NiharikaThakur32
 
From Tensorflow Graph to Tensorflow Eager
From Tensorflow Graph to Tensorflow EagerFrom Tensorflow Graph to Tensorflow Eager
From Tensorflow Graph to Tensorflow Eager
Guy Hadash
 
Python program to build deep learning algorithm using a CNNs model to.docx
Python program to build deep learning algorithm using a CNNs model to.docxPython program to build deep learning algorithm using a CNNs model to.docx
Python program to build deep learning algorithm using a CNNs model to.docx
LukeQVdGrantg
 
AIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdfAIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdf
ssuserb4d806
 
Computer vision
Computer vision Computer vision
Computer vision
Dmitry Ryabokon
 
OpenPOWER Workshop in Silicon Valley
OpenPOWER Workshop in Silicon ValleyOpenPOWER Workshop in Silicon Valley
OpenPOWER Workshop in Silicon Valley
Ganesan Narayanasamy
 
Need help filling out the missing sections of this code- the sections.docx
Need help filling out the missing sections of this code- the sections.docxNeed help filling out the missing sections of this code- the sections.docx
Need help filling out the missing sections of this code- the sections.docx
lauracallander
 
Keras and TensorFlow
Keras and TensorFlowKeras and TensorFlow
Keras and TensorFlow
NopphawanTamkuan
 
GANs
GANsGANs
GANs
SyedMahmoodDataScien
 
Gans
GansGans
Gans
SyedMahmoodDataScien
 
TensorFlow and Keras: An Overview
TensorFlow and Keras: An OverviewTensorFlow and Keras: An Overview
TensorFlow and Keras: An Overview
Poo Kuan Hoong
 
deep learning library coyoteの開発(CNN編)
deep learning library coyoteの開発(CNN編)deep learning library coyoteの開発(CNN編)
deep learning library coyoteの開発(CNN編)
Kotaro Tanahashi
 
Assignment 5.2.pdf
Assignment 5.2.pdfAssignment 5.2.pdf
Assignment 5.2.pdf
dash41
 
Designing a neural network architecture for image recognition
Designing a neural network architecture for image recognitionDesigning a neural network architecture for image recognition
Designing a neural network architecture for image recognition
ShandukaniVhulondo
 
[Japanese]Obake-GAN (Perturbative GAN): GAN with Perturbation Layers
[Japanese]Obake-GAN (Perturbative GAN): GAN with Perturbation Layers[Japanese]Obake-GAN (Perturbative GAN): GAN with Perturbation Layers
[Japanese]Obake-GAN (Perturbative GAN): GAN with Perturbation Layers
yumakishi
 
A Tour of Tensorflow's APIs
A Tour of Tensorflow's APIsA Tour of Tensorflow's APIs
A Tour of Tensorflow's APIs
Dean Wyatte
 
I have tried running this code below- and it is working- but the accur.pdf
I have tried running this code below- and it is working- but the accur.pdfI have tried running this code below- and it is working- but the accur.pdf
I have tried running this code below- and it is working- but the accur.pdf
GordonF2XPatersonh
 
Teach a neural network to read handwriting
Teach a neural network to read handwritingTeach a neural network to read handwriting
Teach a neural network to read handwriting
Vipul Kaushal
 
Tutorial: Image Generation and Image-to-Image Translation using GAN
Tutorial: Image Generation and Image-to-Image Translation using GANTutorial: Image Generation and Image-to-Image Translation using GAN
Tutorial: Image Generation and Image-to-Image Translation using GAN
Wuhyun Rico Shin
 
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Codemotion
 
From Tensorflow Graph to Tensorflow Eager
From Tensorflow Graph to Tensorflow EagerFrom Tensorflow Graph to Tensorflow Eager
From Tensorflow Graph to Tensorflow Eager
Guy Hadash
 
Python program to build deep learning algorithm using a CNNs model to.docx
Python program to build deep learning algorithm using a CNNs model to.docxPython program to build deep learning algorithm using a CNNs model to.docx
Python program to build deep learning algorithm using a CNNs model to.docx
LukeQVdGrantg
 
AIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdfAIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdf
ssuserb4d806
 
OpenPOWER Workshop in Silicon Valley
OpenPOWER Workshop in Silicon ValleyOpenPOWER Workshop in Silicon Valley
OpenPOWER Workshop in Silicon Valley
Ganesan Narayanasamy
 
Need help filling out the missing sections of this code- the sections.docx
Need help filling out the missing sections of this code- the sections.docxNeed help filling out the missing sections of this code- the sections.docx
Need help filling out the missing sections of this code- the sections.docx
lauracallander
 
TensorFlow and Keras: An Overview
TensorFlow and Keras: An OverviewTensorFlow and Keras: An Overview
TensorFlow and Keras: An Overview
Poo Kuan Hoong
 
deep learning library coyoteの開発(CNN編)
deep learning library coyoteの開発(CNN編)deep learning library coyoteの開発(CNN編)
deep learning library coyoteの開発(CNN編)
Kotaro Tanahashi
 
Assignment 5.2.pdf
Assignment 5.2.pdfAssignment 5.2.pdf
Assignment 5.2.pdf
dash41
 
Designing a neural network architecture for image recognition
Designing a neural network architecture for image recognitionDesigning a neural network architecture for image recognition
Designing a neural network architecture for image recognition
ShandukaniVhulondo
 
[Japanese]Obake-GAN (Perturbative GAN): GAN with Perturbation Layers
[Japanese]Obake-GAN (Perturbative GAN): GAN with Perturbation Layers[Japanese]Obake-GAN (Perturbative GAN): GAN with Perturbation Layers
[Japanese]Obake-GAN (Perturbative GAN): GAN with Perturbation Layers
yumakishi
 
A Tour of Tensorflow's APIs
A Tour of Tensorflow's APIsA Tour of Tensorflow's APIs
A Tour of Tensorflow's APIs
Dean Wyatte
 

More from acteleshoppe (20)

Using your understanding of Hardy-Weinberg proportions- which of the f.pdf
Using your understanding of Hardy-Weinberg proportions- which of the f.pdfUsing your understanding of Hardy-Weinberg proportions- which of the f.pdf
Using your understanding of Hardy-Weinberg proportions- which of the f.pdf
acteleshoppe
 
Using visual studio 2022- a C# windows form application- and your Doub.pdf
Using visual studio 2022- a C# windows form application- and your Doub.pdfUsing visual studio 2022- a C# windows form application- and your Doub.pdf
Using visual studio 2022- a C# windows form application- and your Doub.pdf
acteleshoppe
 
Using the summary table above- match the sources of variation with the.pdf
Using the summary table above- match the sources of variation with the.pdfUsing the summary table above- match the sources of variation with the.pdf
Using the summary table above- match the sources of variation with the.pdf
acteleshoppe
 
Using PowerPoint draft an academic poster critically analysing and ill.pdf
Using PowerPoint draft an academic poster critically analysing and ill.pdfUsing PowerPoint draft an academic poster critically analysing and ill.pdf
Using PowerPoint draft an academic poster critically analysing and ill.pdf
acteleshoppe
 
Using the life cycle image above to help you define meiosis- haplece a.pdf
Using the life cycle image above to help you define meiosis- haplece a.pdfUsing the life cycle image above to help you define meiosis- haplece a.pdf
Using the life cycle image above to help you define meiosis- haplece a.pdf
acteleshoppe
 
Using the Influence tactic known as pressure usually Involves Multiple.pdf
Using the Influence tactic known as pressure usually Involves Multiple.pdfUsing the Influence tactic known as pressure usually Involves Multiple.pdf
Using the Influence tactic known as pressure usually Involves Multiple.pdf
acteleshoppe
 
Using the information below- please prepare the 2020 and 2021 Balance.pdf
Using the information below- please prepare the 2020 and 2021 Balance.pdfUsing the information below- please prepare the 2020 and 2021 Balance.pdf
Using the information below- please prepare the 2020 and 2021 Balance.pdf
acteleshoppe
 
Using the following national income accounting data- compute (a) GDP-.pdf
Using the following national income accounting data- compute (a) GDP-.pdfUsing the following national income accounting data- compute (a) GDP-.pdf
Using the following national income accounting data- compute (a) GDP-.pdf
acteleshoppe
 
Using the company Netflix- Based on your prior research- determine.pdf
Using the company Netflix-    Based on your prior research- determine.pdfUsing the company Netflix-    Based on your prior research- determine.pdf
Using the company Netflix- Based on your prior research- determine.pdf
acteleshoppe
 
Using the assigned class reading- -SOCIAL CONTROL THEORIES OF URBAN PO.pdf
Using the assigned class reading- -SOCIAL CONTROL THEORIES OF URBAN PO.pdfUsing the assigned class reading- -SOCIAL CONTROL THEORIES OF URBAN PO.pdf
Using the assigned class reading- -SOCIAL CONTROL THEORIES OF URBAN PO.pdf
acteleshoppe
 
Using the areas in Figure (the Empirical Rule)- find the areas between.pdf
Using the areas in Figure (the Empirical Rule)- find the areas between.pdfUsing the areas in Figure (the Empirical Rule)- find the areas between.pdf
Using the areas in Figure (the Empirical Rule)- find the areas between.pdf
acteleshoppe
 
Using sources from the Internet- identify some of the problems facing.pdf
Using sources from the Internet- identify some of the problems facing.pdfUsing sources from the Internet- identify some of the problems facing.pdf
Using sources from the Internet- identify some of the problems facing.pdf
acteleshoppe
 
Using Python- Prompt the user to enter a word and a single character-.pdf
Using Python- Prompt the user to enter a word and a single character-.pdfUsing Python- Prompt the user to enter a word and a single character-.pdf
Using Python- Prompt the user to enter a word and a single character-.pdf
acteleshoppe
 
Using putty with Bash shell- I am trying to complete the following-.pdf
Using putty with Bash shell-  I am trying to complete the following-.pdfUsing putty with Bash shell-  I am trying to complete the following-.pdf
Using putty with Bash shell- I am trying to complete the following-.pdf
acteleshoppe
 
Using linux - For each environment variable below- state whether it is.pdf
Using linux - For each environment variable below- state whether it is.pdfUsing linux - For each environment variable below- state whether it is.pdf
Using linux - For each environment variable below- state whether it is.pdf
acteleshoppe
 
Using Java and the parboiled Java library Write a BNF grammar for the.pdf
Using Java and the parboiled Java library Write a BNF grammar for the.pdfUsing Java and the parboiled Java library Write a BNF grammar for the.pdf
Using Java and the parboiled Java library Write a BNF grammar for the.pdf
acteleshoppe
 
using basic python P4-16 Factoring of integers- Write a program that a.pdf
using basic python P4-16 Factoring of integers- Write a program that a.pdfusing basic python P4-16 Factoring of integers- Write a program that a.pdf
using basic python P4-16 Factoring of integers- Write a program that a.pdf
acteleshoppe
 
using C# language- a WPF application will be made with the application.pdf
using C# language- a WPF application will be made with the application.pdfusing C# language- a WPF application will be made with the application.pdf
using C# language- a WPF application will be made with the application.pdf
acteleshoppe
 
Using a waterfall framework is suitable for a project involving which.pdf
Using a waterfall framework is suitable for a project involving which.pdfUsing a waterfall framework is suitable for a project involving which.pdf
Using a waterfall framework is suitable for a project involving which.pdf
acteleshoppe
 
Using an electronic version of Figure 13 (attached here)- 1- Illustrat.pdf
Using an electronic version of Figure 13 (attached here)- 1- Illustrat.pdfUsing an electronic version of Figure 13 (attached here)- 1- Illustrat.pdf
Using an electronic version of Figure 13 (attached here)- 1- Illustrat.pdf
acteleshoppe
 
Using your understanding of Hardy-Weinberg proportions- which of the f.pdf
Using your understanding of Hardy-Weinberg proportions- which of the f.pdfUsing your understanding of Hardy-Weinberg proportions- which of the f.pdf
Using your understanding of Hardy-Weinberg proportions- which of the f.pdf
acteleshoppe
 
Using visual studio 2022- a C# windows form application- and your Doub.pdf
Using visual studio 2022- a C# windows form application- and your Doub.pdfUsing visual studio 2022- a C# windows form application- and your Doub.pdf
Using visual studio 2022- a C# windows form application- and your Doub.pdf
acteleshoppe
 
Using the summary table above- match the sources of variation with the.pdf
Using the summary table above- match the sources of variation with the.pdfUsing the summary table above- match the sources of variation with the.pdf
Using the summary table above- match the sources of variation with the.pdf
acteleshoppe
 
Using PowerPoint draft an academic poster critically analysing and ill.pdf
Using PowerPoint draft an academic poster critically analysing and ill.pdfUsing PowerPoint draft an academic poster critically analysing and ill.pdf
Using PowerPoint draft an academic poster critically analysing and ill.pdf
acteleshoppe
 
Using the life cycle image above to help you define meiosis- haplece a.pdf
Using the life cycle image above to help you define meiosis- haplece a.pdfUsing the life cycle image above to help you define meiosis- haplece a.pdf
Using the life cycle image above to help you define meiosis- haplece a.pdf
acteleshoppe
 
Using the Influence tactic known as pressure usually Involves Multiple.pdf
Using the Influence tactic known as pressure usually Involves Multiple.pdfUsing the Influence tactic known as pressure usually Involves Multiple.pdf
Using the Influence tactic known as pressure usually Involves Multiple.pdf
acteleshoppe
 
Using the information below- please prepare the 2020 and 2021 Balance.pdf
Using the information below- please prepare the 2020 and 2021 Balance.pdfUsing the information below- please prepare the 2020 and 2021 Balance.pdf
Using the information below- please prepare the 2020 and 2021 Balance.pdf
acteleshoppe
 
Using the following national income accounting data- compute (a) GDP-.pdf
Using the following national income accounting data- compute (a) GDP-.pdfUsing the following national income accounting data- compute (a) GDP-.pdf
Using the following national income accounting data- compute (a) GDP-.pdf
acteleshoppe
 
Using the company Netflix- Based on your prior research- determine.pdf
Using the company Netflix-    Based on your prior research- determine.pdfUsing the company Netflix-    Based on your prior research- determine.pdf
Using the company Netflix- Based on your prior research- determine.pdf
acteleshoppe
 
Using the assigned class reading- -SOCIAL CONTROL THEORIES OF URBAN PO.pdf
Using the assigned class reading- -SOCIAL CONTROL THEORIES OF URBAN PO.pdfUsing the assigned class reading- -SOCIAL CONTROL THEORIES OF URBAN PO.pdf
Using the assigned class reading- -SOCIAL CONTROL THEORIES OF URBAN PO.pdf
acteleshoppe
 
Using the areas in Figure (the Empirical Rule)- find the areas between.pdf
Using the areas in Figure (the Empirical Rule)- find the areas between.pdfUsing the areas in Figure (the Empirical Rule)- find the areas between.pdf
Using the areas in Figure (the Empirical Rule)- find the areas between.pdf
acteleshoppe
 
Using sources from the Internet- identify some of the problems facing.pdf
Using sources from the Internet- identify some of the problems facing.pdfUsing sources from the Internet- identify some of the problems facing.pdf
Using sources from the Internet- identify some of the problems facing.pdf
acteleshoppe
 
Using Python- Prompt the user to enter a word and a single character-.pdf
Using Python- Prompt the user to enter a word and a single character-.pdfUsing Python- Prompt the user to enter a word and a single character-.pdf
Using Python- Prompt the user to enter a word and a single character-.pdf
acteleshoppe
 
Using putty with Bash shell- I am trying to complete the following-.pdf
Using putty with Bash shell-  I am trying to complete the following-.pdfUsing putty with Bash shell-  I am trying to complete the following-.pdf
Using putty with Bash shell- I am trying to complete the following-.pdf
acteleshoppe
 
Using linux - For each environment variable below- state whether it is.pdf
Using linux - For each environment variable below- state whether it is.pdfUsing linux - For each environment variable below- state whether it is.pdf
Using linux - For each environment variable below- state whether it is.pdf
acteleshoppe
 
Using Java and the parboiled Java library Write a BNF grammar for the.pdf
Using Java and the parboiled Java library Write a BNF grammar for the.pdfUsing Java and the parboiled Java library Write a BNF grammar for the.pdf
Using Java and the parboiled Java library Write a BNF grammar for the.pdf
acteleshoppe
 
using basic python P4-16 Factoring of integers- Write a program that a.pdf
using basic python P4-16 Factoring of integers- Write a program that a.pdfusing basic python P4-16 Factoring of integers- Write a program that a.pdf
using basic python P4-16 Factoring of integers- Write a program that a.pdf
acteleshoppe
 
using C# language- a WPF application will be made with the application.pdf
using C# language- a WPF application will be made with the application.pdfusing C# language- a WPF application will be made with the application.pdf
using C# language- a WPF application will be made with the application.pdf
acteleshoppe
 
Using a waterfall framework is suitable for a project involving which.pdf
Using a waterfall framework is suitable for a project involving which.pdfUsing a waterfall framework is suitable for a project involving which.pdf
Using a waterfall framework is suitable for a project involving which.pdf
acteleshoppe
 
Using an electronic version of Figure 13 (attached here)- 1- Illustrat.pdf
Using an electronic version of Figure 13 (attached here)- 1- Illustrat.pdfUsing an electronic version of Figure 13 (attached here)- 1- Illustrat.pdf
Using an electronic version of Figure 13 (attached here)- 1- Illustrat.pdf
acteleshoppe
 

Recently uploaded (20)

HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGYHUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
DHARMENDRA SAHU
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
Sritoma Majumder
 
Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...
EduSkills OECD
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
Freckle Project April 2025 Survey and report May 2025.pptx
Freckle Project April 2025 Survey and report May 2025.pptxFreckle Project April 2025 Survey and report May 2025.pptx
Freckle Project April 2025 Survey and report May 2025.pptx
EveryLibrary
 
AR3201 WORLD ARCHITECTURE AND URBANISM EARLY CIVILISATIONS TO RENAISSANCE QUE...
AR3201 WORLD ARCHITECTURE AND URBANISM EARLY CIVILISATIONS TO RENAISSANCE QUE...AR3201 WORLD ARCHITECTURE AND URBANISM EARLY CIVILISATIONS TO RENAISSANCE QUE...
AR3201 WORLD ARCHITECTURE AND URBANISM EARLY CIVILISATIONS TO RENAISSANCE QUE...
Mani Sasidharan
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
A Brief Introduction About Jack Lutkus
A Brief Introduction About  Jack  LutkusA Brief Introduction About  Jack  Lutkus
A Brief Introduction About Jack Lutkus
Jack Lutkus
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Pragya Champion's Chalice 2025 Set , General Quiz
Pragya Champion's Chalice 2025 Set , General QuizPragya Champion's Chalice 2025 Set , General Quiz
Pragya Champion's Chalice 2025 Set , General Quiz
Pragya - UEM Kolkata Quiz Club
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptxRai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Fatman Book HD Pdf by aayush songare.pdf
Fatman Book  HD Pdf by aayush songare.pdfFatman Book  HD Pdf by aayush songare.pdf
Fatman Book HD Pdf by aayush songare.pdf
Aayush Songare
 
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGYHUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
DHARMENDRA SAHU
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
Sritoma Majumder
 
Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...
EduSkills OECD
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
Freckle Project April 2025 Survey and report May 2025.pptx
Freckle Project April 2025 Survey and report May 2025.pptxFreckle Project April 2025 Survey and report May 2025.pptx
Freckle Project April 2025 Survey and report May 2025.pptx
EveryLibrary
 
AR3201 WORLD ARCHITECTURE AND URBANISM EARLY CIVILISATIONS TO RENAISSANCE QUE...
AR3201 WORLD ARCHITECTURE AND URBANISM EARLY CIVILISATIONS TO RENAISSANCE QUE...AR3201 WORLD ARCHITECTURE AND URBANISM EARLY CIVILISATIONS TO RENAISSANCE QUE...
AR3201 WORLD ARCHITECTURE AND URBANISM EARLY CIVILISATIONS TO RENAISSANCE QUE...
Mani Sasidharan
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
A Brief Introduction About Jack Lutkus
A Brief Introduction About  Jack  LutkusA Brief Introduction About  Jack  Lutkus
A Brief Introduction About Jack Lutkus
Jack Lutkus
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Fatman Book HD Pdf by aayush songare.pdf
Fatman Book  HD Pdf by aayush songare.pdfFatman Book  HD Pdf by aayush songare.pdf
Fatman Book HD Pdf by aayush songare.pdf
Aayush Songare
 
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 

Using the code below- I need help with creating code for the following.pdf

  • 1. Using the code below, I need help with creating code for the following: 1) Write Python code to plot the images from the first epoch. Take a screenshot of the images from the first epoch. 2) Write Python code to plot the images from the last epoch. Take a screenshot of the images from the last epoch. #Step 1: Import the required Python libraries: import numpy as np import matplotlib.pyplot as plt import keras from keras.layers import Input, Dense, Reshape, Flatten, Dropout from keras.layers import BatchNormalization, Activation, ZeroPadding2D from keras.layers import LeakyReLU from keras.layers.convolutional import UpSampling2D, Conv2D from keras.models import Sequential, Model from keras.optimizers import Adam,SGD from keras.datasets import cifar10 #Step 2: Load the data. #Loading the CIFAR10 data (X, y), (_, _) = keras.datasets.cifar10.load_data() #Selecting a single class of images #The number was randomly chosen and any number #between 1 and 10 can be chosen X = X[y.flatten() == 8] #Step 3: Define parameters to be used in later processes.
  • 2. #Defining the Input shape image_shape = (32, 32, 3) latent_dimensions = 100 #Step 4: Define a utility function to build the generator. def build_generator(): model = Sequential() #Building the input layer model.add(Dense(128 * 8 * 8, activation="relu", input_dim=latent_dimensions)) model.add(Reshape((8, 8, 128))) model.add(UpSampling2D()) model.add(Conv2D(128, kernel_size=3, padding="same")) model.add(BatchNormalization(momentum=0.78)) model.add(Activation("relu")) model.add(UpSampling2D()) model.add(Conv2D(64, kernel_size=3, padding="same")) model.add(BatchNormalization(momentum=0.78)) model.add(Activation("relu")) model.add(Conv2D(3, kernel_size=3, padding="same")) model.add(Activation("tanh")) #Generating the output image noise = Input(shape=(latent_dimensions,)) image = model(noise)
  • 3. return Model(noise, image) #Step 5: Define a utility function to build the discriminator. def build_discriminator(): #Building the convolutional layers #to classify whether an image is real or fake model = Sequential() model.add(Conv2D(32, kernel_size=3, strides=2, input_shape=image_shape, padding="same")) model.add(LeakyReLU(alpha=0.2)) model.add(Dropout(0.25)) model.add(Conv2D(64, kernel_size=3, strides=2, padding="same")) model.add(ZeroPadding2D(padding=((0,1),(0,1)))) model.add(BatchNormalization(momentum=0.82)) model.add(LeakyReLU(alpha=0.25)) model.add(Dropout(0.25)) model.add(Conv2D(128, kernel_size=3, strides=2, padding="same")) model.add(BatchNormalization(momentum=0.82)) model.add(LeakyReLU(alpha=0.2)) model.add(Dropout(0.25)) model.add(Conv2D(256, kernel_size=3, strides=1, padding="same")) model.add(BatchNormalization(momentum=0.8)) model.add(LeakyReLU(alpha=0.25)) model.add(Dropout(0.25))
  • 4. #Building the output layer model.add(Flatten()) model.add(Dense(1, activation='sigmoid')) image = Input(shape=image_shape) validity = model(image) return Model(image, validity) #Step 6: Define a utility function to display the generated images. def display_images(): r, c = 4,4 noise = np.random.normal(0, 1, (r * c,latent_dimensions)) generated_images = generator.predict(noise) #Scaling the generated images generated_images = 0.5 * generated_images + 0.5 fig, axs = plt.subplots(r, c) count = 0 for i in range(r): for j in range(c): axs[i,j].imshow(generated_images[count, :,:,]) axs[i,j].axis('off') count += 1 plt.show() plt.close() #Step 7: Build the GAN.
  • 5. # Building and compiling the discriminator discriminator = build_discriminator() discriminator.compile(loss='binary_crossentropy', optimizer=Adam(0.0002,0.5), metrics=['accuracy']) #Making the discriminator untrainable #so that the generator can learn from fixed gradient discriminator.trainable = False # Building the generator generator = build_generator() #Defining the input for the generator #and generating the images z = Input(shape=(latent_dimensions,)) image = generator(z) #Checking the validity of the generated image valid = discriminator(image) #Defining the combined model of the generator and the discriminator combined_network = Model(z, valid) combined_network.compile(loss='binary_crossentropy', optimizer=Adam(0.0002,0.5)) #Step 8: Train the network. num_epochs=15000 batch_size=32
  • 6. display_interval=2500 losses=[] #Normalizing the input X = (X / 127.5) - 1. #Defining the Adversarial ground truths valid = np.ones((batch_size, 1)) #Adding some noise valid += 0.05 * np.random.random(valid.shape) fake = np.zeros((batch_size, 1)) fake += 0.05 * np.random.random(fake.shape) for epoch in range(num_epochs): #Training the Discriminator #Sampling a random half of images index = np.random.randint(0, X.shape[0], batch_size) images = X[index] #Sampling noise and generating a batch of new images noise = np.random.normal(0, 1, (batch_size, latent_dimensions)) generated_images = generator.predict(noise) #Training the discriminator to detect more accurately #whether a generated image is real or fake discm_loss_real = discriminator.train_on_batch(images, valid) discm_loss_fake = discriminator.train_on_batch(generated_images, fake) discm_loss = 0.5 * np.add(discm_loss_real, discm_loss_fake)
  • 7. #Training the generator #Training the generator to generate images #that pass the authenticity test genr_loss = combined_network.train_on_batch(noise, valid) #Tracking the progress if epoch % display_interval == 0: display_images()