0% found this document useful (0 votes)
92 views

Deep Learning Exp

deep learning

Uploaded by

keertisuthar2002
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

Deep Learning Exp

deep learning

Uploaded by

keertisuthar2002
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

EXPERIMENT 1: Build a deep neural network model start with linear

regression using:
A.) Single variable
B.) Multiple variables Program

A.) Single variable:

!pip install tensorflow


pip install tensorflow
import tensorflow a tf
import numpy a np
import tensorflow as tf
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
# Build a single-variable linear regression model
model_single = tf.keras.Sequential([
tf.keras.layers.Dense(1, input_shape=(1,))
])
model_single.compile(optimizer=’sgd’, loss=’mean_squared_error’)
# Generate some random data for demonstration
np.random.seed(42)
X_multi = 2 * np.random.rand(100, 2)
y_multi = 4 + 3 * X_multi[:, 0] + 1.5 * X_multi[:, 1] + np.random.randn(100, 1)
# Split the data into training and testing sets
X_train_multi, X_test_multi, y_train_multi, y_test_multi = train_test_split(X_multi, y_multi,
test_size=0.2, random_state=42)
# Standardize the data for better training performance
scaler_multi = StandardScaler()
X_train_multi_scaled = scaler_multi.fit_transform(X_train_multi)
X_test_multi_scaled = scaler_multi.transform(X_test_multi)
# Train the model
model_single.fit(X_train_single_scaled, y_train_single, epochs=50, verbose=0)
# Evaluate the model on the test set
single_var_loss = model_single.evaluate(X_test_single_scaled, y_test_single)

print(single variable linear regression model loss’, single_var_loss)


DEEP LEARNING & ITS APPLICATIONS LAB
OUTPUT –

B.) Multiple Variables


!pip install tensorflow
pip install tensorflow
import tensorflow a tf
import numpy a np
import tensorflow as tf
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
# Build a multiple-variable linear regression model
model_multi = tf.keras.Sequential([
tf.keras.layers.Dense(1, input_shape=(2,))
])
model_multi.compile(optimizer=’sgd’, loss=’mean_squared_error’)
# Generate some random data for demonstration
np.random.seed(42)
X_multi = 2 * np.random.rand(100, 2)
y_multi = 4 + 3 * X_multi[:, 0] + 1.5 * X_multi[:, 1] + np.random.randn(100, 1)
# Split the data into training and testing sets

X_train_multi, X_test_multi, y_train_multi, y_test_multi = train_test_split(X_multi, y_multi,


test_size=0.2, random_state=42)
# Standardize the data for better training performance
scaler_multi = StandardScaler()
X_train_multi_scaled = scaler_multi.fit_transform(X_train_multi)
X_test_multi_scaled = scaler_multi.transform(X_test_multi)
# Build a multiple-variable linear regression model
model_multi = tf.keras.Sequential([
tf.keras.layers.Dense(1, input_shape=(2,))
])

DEEP LEARNING & ITS APPLICATIONS LAB


model_multi.compile(optimizer=’sgd’, loss=’mean_squared_error’)
# Train the model
model_multi.fit(X_train_multi_scaled, y_train_multi, epochs=50, verbose=0)
# Evaluate the model on the test set
multi_var_loss = model_multi.evaluate(X_test_multi_scaled, y_test_multi)
print(“multiple variable linear regression model loss:”, multi_var_loss)

OUTPUT –

DEEP LEARNING & ITS APPLICATIONS LAB


EXPERIMENT 2: Write a program to convert
a) Speech to text
b) Text to speech
c) Video to frames
Program:
a) Speech to text
!pip install speechrecognition
!pip install pyaudio
!pip install pyttsx3
import speech_recognition as sr
import pyttsx3
# Initialize the recognizer
r = sr.Recognizer()
# Function to convert text to
# speech
def SpeakText(command):
# Initialize the engine
engine = pyttsx3.init()
engine.say(command)
engine.runAndWait()
while(1):
try:
with sr.Microphone() as source2:
r.adjust_for_ambient_noise(source2, duration=0.2)
audio2 = r.listen(source2)
MyText = r.recognize_google(audio2)
MyText = MyText.lower()
print("Did you say ",MyText)
SpeakText(MyText)
except sr.RequestError as e:
print("Could not request results; {0}".format(e))
except sr.UnknownValueError:
print("unknown error occurred")

DEEP LEARNING & ITS APPLICATIONS LAB


b) Text to speech
from gtts import gTTS
import os
def text_to_speech(text, language='en', filename='output.mp3'):
tts = gTTS(text=text, lang=language, slow=False)
tts.save(filename)
os.system("start " + filename)
# Example usage
text = "Hello, how are you today?"
text_to_speech(text)

OUTPUT –
Input: “Hello, how are you today”
Output: Voice saying Hello

DEEP LEARNING & ITS APPLICATIONS LAB


c) Video to frames
import cv2
import os
cam = cv2.VideoCapture("C:\\Users\\Siya\\Downloads\\big_buck_bunny_720p_1mb.mp4")
try:
if not os.path.exists('data'):
os.makedirs('data')
except OSError:
print ('Error: Creating directory of data')
currentframe = 0
while(True):
ret,frame = cam.read()
if ret:
name = './data/frame' + str(currentframe) + '.jpg'
print ('Creating...' + name)
cv2.imwrite(name, frame)
currentframe += 1
else:
break
# Release all space and windows once done
cam.release()
cv2.destroyAllWindows()

DEEP LEARNING & ITS APPLICATIONS LAB


EXPERIMENT 3: Build a feed forward neural network for prediction of logic gates.
Program:
import numpy as np
import tensorflow as tf
# Define the dataset for AND gate
X_and = np.array([[0, 0], [0, 1], [1, 0], [1, 1]], dtype=np.float32)
y_and = np.array([[0], [0], [0], [1]], dtype=np.float32)
# Define the dataset for OR gate
X_or = np.array([[0, 0], [0, 1], [1, 0], [1, 1]], dtype=np.float32)
y_or = np.array([[0], [1], [1], [1]], dtype=np.float32)
# Define the dataset for XOR gate
X_xor = np.array([[0, 0], [0, 1], [1, 0], [1, 1]], dtype=np.float32)
y_xor = np.array([[0], [1], [1], [0]], dtype=np.float32)
# Define the neural network architecture
model = tf.keras.Sequential([
tf.keras.layers.Dense(2, activation='relu', input_shape=(2,)),
tf.keras.layers.Dense(1, activation='sigmoid')
])
# Compile the model
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
# Train the model for AND gate
print("Training AND gate...")
model.fit(X_and, y_and, epochs=1000, verbose=0)
# Evaluate the model on AND gate
print("Evaluating AND gate...")
loss, accuracy = model.evaluate(X_and, y_and)
print(f"AND gate - Loss: {loss}, Accuracy: {accuracy}")
# Train the model for OR gate
print("\nTraining OR gate...")
model.fit(X_or, y_or, epochs=1000, verbose=0)
# Evaluate the model on OR gate
print("Evaluating OR gate...")
loss, accuracy = model.evaluate(X_or, y_or)
print(f"OR gate - Loss: {loss}, Accuracy: {accuracy}")
# Train the model for XOR gate

DEEP LEARNING & ITS APPLICATIONS LAB


print("\nTraining XOR gate...")
model.fit(X_xor, y_xor, epochs=1000, verbose=0)
# Evaluate the model on XOR gate
print("Evaluating XOR gate...")
loss, accuracy = model.evaluate(X_xor, y_xor)
print(f"XOR gate - Loss: {loss}, Accuracy: {accuracy}")

DEEP LEARNING & ITS APPLICATIONS LAB


EXPERIMENT 4: Write a program for character recognition using:
A) CNN
B) RNN

Program:
A) CNN
import tensorflow as tf
from tensorflow.keras.datasets import mnist
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense
# Load and preprocess the MNIST dataset
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
# Reshape the input data to 4D tensor (batch_size, height, width, channels)
x_train = x_train.reshape(x_train.shape[0], 28, 28, 1)
x_test = x_test.reshape(x_test.shape[0], 28, 28, 1)
# Define the CNN model
model = Sequential([
Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)),
MaxPooling2D((2, 2)),
Conv2D(64, (3, 3), activation='relu'),
MaxPooling2D((2, 2)),
Conv2D(64, (3, 3), activation='relu'),
Flatten(),
Dense(64, activation='relu'),
Dense(10, activation='softmax')
])
# Compile the model
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
# Train the model
model.fit(x_train, y_train, epochs=5, batch_size=64, validation_data=(x_test, y_test))
# Evaluate the model
test_loss, test_acc = model.evaluate(x_test, y_test)

DEEP LEARNING & ITS APPLICATIONS LAB


print(f'Test accuracy: {test_acc}')

b) RNN
import numpy as np
import tensorflow as tf
from tensorflow.keras.datasets import mnist
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import SimpleRNN, Dense
# Load and preprocess the MNIST dataset
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train = x_train.astype('float32') / 255.0
x_test = x_test.astype('float32') / 255.0
# Define the RNN model
model = Sequential([
SimpleRNN(128, input_shape=(x_train.shape[1:]), activation='relu', return_sequences=True),
SimpleRNN(128, activation='relu'),
Dense(10, activation='softmax')
])
# Compile the model
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
# Train the model
model.fit(x_train, y_train, epochs=5, batch_size=64, validation_data=(x_test, y_test))
# Evaluate the model
test_loss, test_acc = model.evaluate(x_test, y_test)
DEEP LEARNING & ITS APPLICATIONS LAB
print(f'Test accuracy: {test_acc}')

DEEP LEARNING & ITS APPLICATIONS LAB


EXPERIMENT 5: Write a program to predict a caption for a single image using
A) LSTM
B) CNN

Program:
A) LSTM
import numpy as np
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Input, Dense, Embedding, LSTM, Dropout,
TimeDistributed, concatenate
from tensorflow.keras.applications import InceptionV3
from tensorflow.keras.applications.inception_v3 import preprocess_input
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.preprocessing import image
from tensorflow.keras.preprocessing import image as keras_image
import os
# Placeholder function for loading data, replace with your actual data loading code
def load_your_data_function():
image_dir = 'D:\LSTM\images' # Update with the path to your image directory
captions_file = 'D:\LSTM\captions.txt' # Update with the path to your captions file
with open(captions_file, 'r') as file:
captions = file.readlines()
captions = [caption.strip() for caption in captions]
image_paths = [os.path.join(image_dir, filename) for filename in os.listdir(image_dir)]
return image_paths, captions
image_paths, captions = load_your_data_function()
tokenizer = Tokenizer()
tokenizer.fit_on_texts(captions)
vocab_size = len(tokenizer.word_index) + 1

DEEP LEARNING & ITS APPLICATIONS LAB


sequences = tokenizer.texts_to_sequences(captions)
max_len = max(len(seq) for seq in sequences)
padded_sequences = pad_sequences(sequences, maxlen=max_len, padding='post')
image_input = Input(shape=(299, 299, 3))
inception_model = InceptionV3(include_top=False, weights='imagenet',
input_tensor=image_input, pooling='avg')
for layer in inception_model.layers:
layer.trainable = False
image_features = inception_model.output
caption_input = Input(shape=(max_len,))
embedding_layer = Embedding(vocab_size, 256, input_length=max_len)(caption_input)
lstm_layer = LSTM(256)(embedding_layer)
merged = concatenate([image_features, lstm_layer])
dense_layer = Dense(256, activation='relu')(merged)
dropout_layer = Dropout(0.5)(dense_layer)
output_layer = Dense(vocab_size, activation='softmax')(dropout_layer)
model = Model(inputs=[image_input, caption_input], outputs=output_layer)
model.compile(loss='categorical_crossentropy', optimizer=Adam(learning_rate=0.001),
metrics=['accuracy'])
# Example: Load an image for prediction
# Replace 'your_image_path.jpg' with the actual path to your c
img_path = r'D:\flower.jpg'
img = image.load_img(img_path, target_size=(299, 299))
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array = preprocess_input(img_array)
# Example: Tokenize and pad the input caption sequence
# Replace 'your_input_caption' with the actual caption you want to predict
input_caption = tokenizer.texts_to_sequences(['flower'])
input_caption = pad_sequences(input_caption, maxlen=max_len, padding='post')
predictions = model.predict([img_array, input_caption])
predicted_word_index = np.argmax(predictions)
predicted_word = tokenizer.index_word.get(predicted_word_index, 'Unknown')
print(f'Predicted word: {predicted_word}')

DEEP LEARNING & ITS APPLICATIONS LAB


b) CNN
import numpy as np
from tensorflow import keras
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Input, Dense, Embedding, Flatten, Dropout, Conv2D
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.preprocessing import image as keras_image
import os
# Placeholder function for loading data, replace with your actual data loading code
def load_your_data_function():
image_dir = 'D:\LSTM\images' # Update with the path to your image directory
captions_file = 'D:\LSTM\captions.txt' # Update with the path to your captions file
with open(captions_file, 'r') as file:
captions = file.readlines()
captions = [caption.strip() for caption in captions]
image_paths = [os.path.join(image_dir, filename) for filename in os.listdir(image_dir)]
return image_paths, captions
image_paths, captions = load_your_data_function()
tokenizer = Tokenizer()

DEEP LEARNING & ITS APPLICATIONS LAB


tokenizer.fit_on_texts(captions)
vocab_size = len(tokenizer.word_index) + 1
sequences = tokenizer.texts_to_sequences(captions)
max_len = max(len(seq) for seq in sequences)
padded_sequences = pad_sequences(sequences, maxlen=max_len, padding='post')
image_input = Input(shape=(128, 128, 3)) # Smaller image size
convolutional_layer = Conv2D(16, (3, 3), activation='relu')(image_input) # Further reduced
number of filters
flatten_layer = Flatten()(convolutional_layer)
dense_layer = Dense(8, activation='relu')(flatten_layer) # Further reduced number of units
dropout_layer = Dropout(0.5)(dense_layer)
output_layer = Dense(vocab_size, activation='softmax')(dropout_layer)
model = Model(inputs=image_input, outputs=output_layer)
model.compile(loss='categorical_crossentropy', optimizer=Adam(learning_rate=0.001),
metrics=['accuracy'])
# Example: Load an image for prediction
# Replace 'your_image_path.jpg' with the actual path to your image
img_path = r'D:\LSTM\images\laptop.jpeg'
img = keras_image.load_img(img_path, target_size=(128, 128)) # Adjusted image size
img_array = keras_image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
# Example: Make a prediction
predictions = model.predict(img_array)
predicted_word_index = np.argmax(predictions)
predicted_word = tokenizer.index_word.get(predicted_word_index, 'Unknown')
print(f'Predicted word: {predicted_word}')

DEEP LEARNING & ITS APPLICATIONS LAB


DEEP LEARNING & ITS APPLICATIONS LAB
EXPERIMENT 6: Write a program to develop:
A.) Auto encoder using MNIST handwritten digits
B.)GAN for generating MNIST handwritten digits

Program:
A) Auto encoder using MNIST handwritten digits
import matplotlib.pyplot as plt
import numpy as np
import pandas as np
import tensorflow as tf
from sklearn.metrics import accuracy_score, precision_score, recall_score
from sklearn.model_selection import train_test_split
from tensorflow.keras import layers, losses
from tensorflow.keras.datasets import mnist
from tensorflow.keras.models import Model
(x_train, _), (x_test, _) = mnist.load_data()
x_train, x_val = x_train[:-10000], x_train[-10000:]
x_train = x_train.astype('float32')/255
x_test = x_test.astype('float32')/255
x_val = x_val.astype('float32')/255
print(x_train.shape)
print(x_test.shape)
print(x_val.shape)
# n = 10
# plt.figure(figsize=(20,4))
# for i in range(n):
# # display original
# ax = plt.subplot(2,n,i+1)
# plt.imshow(x_test[i])
# plt.title("original")
# plt.gray()
# ax.get_xaxis().set_visible(False)
# ax.get_yaxis().set_visible(False)
latent_dim = 64

DEEP LEARNING & ITS APPLICATIONS LAB


class Autoencoder(Model):
def _init_(self, latent_dim):
super(Autoencoder, self)._init_()
self.latent_dim = latent_dim
self.encoder = tf.keras.Sequential([
layers.Flatten(),
layers.Dense(latent_dim, activation = 'relu'),
])
self.decoder = tf.keras.Sequential([
layers.Dense(784, activation='sigmoid'),
layers.Reshape((28,28))
])
def call(self, x):
encoded = self.encoder(x)
decoded = self.decoder(encoded)
return decoded
autoencoder = Autoencoder(latent_dim)
autoencoder.compile(optimizer='Adam', loss=losses.MeanSquaredError())
autoencoder.fit(x_train, x_train, epochs=10, shuffle=True, validation_data=(x_val, x_val))
print(autoencoder.encoder.summary())
print(autoencoder.decoder.summary())
encoded_imgs = autoencoder.encoder(x_test).numpy()
decoded_imgs = autoencoder.decoder(encoded_imgs).numpy()
n = 10
plt.figure(figsize=(20,4))
for i in range(n):
# display original
ax = plt.subplot(2,n,i+1)
plt.imshow(x_test[i])
plt.title("original")
plt.gray()
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
# display reconstruction
ax = plt.subplot(2,n,i+1+n)

DEEP LEARNING & ITS APPLICATIONS LAB


plt.imshow(decoded_imgs[i])
plt.title("reconstructed")
plt.gray()
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)

b) GAN for generating MNIST handwritten digits


import tensorflow as tf
import glob
import imageio
import matplotlib.pyplot as plt
import numpy as np
import os
import PIL
from tensorflow.keras import layers
import time
from tqdm import tqdm
from IPython import display
(train_images, train_labels), (_, _) = tf.keras.datasets.mnist.load_data()
train_images = train_images.reshape(train_images.shape[0], 28, 28, 1).astype('float32')
train_images = (train_images -127.5)/127.5 # Normalize in (-1,1)
len(train_images)
Buffer_size = 60000
Batch_size = 256
# Batch and shuffle the data
DEEP LEARNING & ITS APPLICATIONS LAB
train_dataset = tf.data.Dataset.from_tensor_slices(train_images)
train_dataset = train_dataset.shuffle(Buffer_size)
train_dataset = train_dataset.batch(Batch_size)
def make_generator_model():
model = tf.keras.Sequential()
model.add(layers.Dense(7*7*256, use_bias=False, input_shape=(100,)))
model.add(layers.BatchNormalization())
model.add(layers.LeakyReLU())
model.add(layers.Reshape((7,7,256)))
assert model.output_shape == (None,7,7,256) # None is the batch size
model.add(layers.Conv2DTranspose(128,(5,5), strides=(1,1), padding='same', use_bias=False))
assert model.output_shape == (None,7,7,128)
model.add(layers.BatchNormalization())
model.add(layers.LeakyReLU())
model.add(layers.Conv2DTranspose(64,(5,5), strides=(2,2), padding='same', use_bias=False))
assert model.output_shape == (None,14,14,64)
model.add(layers.BatchNormalization())
model.add(layers.LeakyReLU())
model.add(layers.Conv2DTranspose(1,(5,5), strides=(2,2), padding='same', use_bias=False,
activation='tanh'))
assert model.output_shape == (None,28,28,1)
return model
generator = make_generator_model()
noise = tf.random.normal([1,100])
generated_image = generator(noise, training=False)
plt.imshow(generated_image[0,:,:,0], cmap='gray')
generator.summary()
def make_discriminator_model():
model = tf.keras.Sequential()
model.add(layers.Conv2D(64,(5,5), strides=(2,2), padding='same', input_shape=[28,28,1]))
model.add(layers.LeakyReLU())
model.add(layers.Dropout(0.3))
model.add(layers.Conv2D(128,(5,5), strides=(2,2), padding='same'))
model.add(layers.LeakyReLU())
model.add(layers.Dropout(0.3))

DEEP LEARNING & ITS APPLICATIONS LAB


model.add(layers.Flatten())
model.add(layers.Dense(1,activation='sigmoid'))
return model
discriminator = make_discriminator_model()
decision = discriminator(generated_image)
print(decision)
discriminator.summary()
cross_entropy = tf.keras.losses.BinaryCrossentropy(from_logits=True)
def discriminator_loss(real_output, fake_output):
real_loss = cross_entropy(tf.ones_like(real_output), real_output)
fake_loss = cross_entropy(tf.zeros_like(fake_output), fake_output)
total_loss = real_loss + fake_loss
return total_loss
def generator_loss(fake_output):
return cross_entropy(tf.ones_like(fake_output), fake_output)
generator_optimizer = tf.keras.optimizers.Adam(1e-4)
discriminator_optimizer = tf.keras.optimizers.Adam(1e-4)
checkpoint_dir = './training_checkpoints'
checkpoint_prefix = os.path.join(checkpoint_dir, "ckpt")
checkpoint = tf.train.Checkpoint(generator_optimizer=generator_optimizer,
discriminator_optimizer=discriminator_optimizer,
generator=generator,
discriminator=discriminator)
EPOCHS = 50
noise_dim = 100
num_examples_to_generate = 16
# You will reuse this seed overtime (so it's easier)
# to visualize progress in the animated GIF)
seed = tf.random.normal([num_examples_to_generate, noise_dim])
# Notice the use of tf.function
# This annotation causes the function to be "compiled".
@tf.function
def train_step(images):
noise = tf.random.normal([Batch_size, noise_dim])
with tf.GradientTape() as gen_tape, tf.GradientTape() as disc_tape:

DEEP LEARNING & ITS APPLICATIONS LAB


generated_images = generator(noise, training=True)
real_output = discriminator(images, training=True)
fake_output = discriminator(generated_images, training=True)
gen_loss = generator_loss(fake_output)
disc_loss = discriminator_loss(real_output, fake_output)
gradients_of_generator = gen_tape.gradient(gen_loss, generator.trainable_variables)
gradients_of_discriminator = disc_tape.gradient(disc_loss, discriminator.trainable_variables)
generator_optimizer.apply_gradients(zip(gradients_of_generator,
generator.trainable_variables))
discriminator_optimizer.apply_gradients(zip(gradients_of_discriminator,
discriminator.trainable_variables))
def train(dataset, epochs):
for epoch in range(epochs):
start = time.time()
for image_batch in dataset:
train_step(image_batch)
# Produce images for the GIF as you go
display.clear_output(wait=True)
generate_and_save_images(generator,
epoch + 1,
seed)
# Save the model every 15 epochs
if (epoch + 1) % 15 == 0:
checkpoint.save(file_prefix = checkpoint_prefix)
print ('Time for epoch {} is {} sec'.format(epoch + 1, time.time()-start))
# Generate after the final epoch
display.clear_output(wait=True)
generate_and_save_images(generator,
epochs,
seed)
def generate_and_save_images(model, epoch, test_input):
# Notice training is set to False.
# This is so all layers run in inference mode (batchnorm).
predictions = model(test_input, training=False)
fig = plt.figure(figsize=(4, 4))

DEEP LEARNING & ITS APPLICATIONS LAB


for i in range(predictions.shape[0]):
plt.subplot(4, 4, i+1)
plt.imshow(predictions[i, :, :, 0] * 127.5 + 127.5, cmap='gray')
plt.axis('off')
plt.savefig('image_at_epoch_{:04d}.png'.format(epoch))
plt.show()
train(train_dataset, EPOCHS)
checkpoint.restore(tf.train.latest_checkpoint(checkpoint_dir))

DEEP LEARNING & ITS APPLICATIONS LAB


DEPARTMENT OF ARTIFICIAL INTELLIGENCE & DATA
SCIENCE

8AID4-21: Deep Learning & Its Applications Lab


Questions:

1) What is a deep neural network?


2) How does linear regression differ from a deep neural network?
3) How do you implement linear regression using a single variable?
4) What is the purpose of a cost function in linear regression?
5) How do you extend linear regression to multiple variables?
6) What is the difference between simple linear regression and multiple linear regression?
7) Why is feature scaling important in linear regression?
8) What activation functions are commonly used in deep neural networks?
9) How do you initialize weights in a deep neural network?
10) What libraries can be used in Python to convert speech to text?
11) Describe the process of converting speech into text using a pre-trained model.
12) What challenges arise in converting speech to text?
13) How can text be converted into speech in Python?
14) What is the role of the Text-to-Speech (TTS) engine?
15) How can you ensure the quality of speech synthesized from text?
16) Describe how to extract frames from a video using OpenCV.
17) Why would you need to convert video into frames in computer vision tasks?
18) What are common applications of video-to-frame conversion?
19) How can frame rate affect the outcome of video-to-frame conversion?
20) What is a feed-forward neural network?
21) How does a feed-forward neural network process input data?
22) Explain the process of predicting logic gate outputs using a neural network.
23) What are the different types of logic gates you can predict using a neural network?
24) How do you set up the input layer for predicting logic gates?
25) What loss function is appropriate for binary classification tasks like logic gate prediction?
26) How does the choice of activation function impact the prediction of logic gates?
27) What is overfitting, and how can it be prevented in a neural network model?
DEEP LEARNING & ITS APPLICATIONS LAB
28) Explain the significance of hidden layers in a neural network.
29) How do you evaluate the performance of a neural network in predicting logic gates?
30) What is a Convolutional Neural Network (CNN)?
31) How do CNNs differ from traditional neural networks?
32) Describe the architecture of a CNN used for character recognition.
33) What are the roles of convolutional layers and pooling layers in a CNN?
34) Why is ReLU commonly used as an activation function in CNNs?
35) What is an RNN, and how does it handle sequential data?
36) How can an RNN be adapted for character recognition tasks?
37) What are the key differences between CNNs and RNNs in processing images?
38) Explain the role of the softmax layer in character recognition.
39) How can data augmentation improve the performance of character recognition models?
40) What is an LSTM, and how is it used in image captioning?
41) How do CNNs contribute to image captioning models?
42) Describe the process of generating captions for an image using LSTM.
43) How is the CNN-LSTM architecture structured for image captioning tasks?
44) What challenges are involved in training an image captioning model?
45) What is the importance of the embedding layer in image captioning?
46) How does attention mechanism enhance image captioning performance?
47) What datasets are commonly used for training image captioning models?
48) Explain the concept of teacher forcing in training LSTM models.
49) How do you evaluate the quality of generated captions in image captioning tasks?
50) What is an RNN, and how does it handle sequential data?

DEEP LEARNING & ITS APPLICATIONS LAB

You might also like