Deep Learning R18 Jntuh Lab Manual
Deep Learning R18 Jntuh Lab Manual
Deep Learning R18 Jntuh Lab Manual
That's it! You have set up the Spyder IDE environment and executed a
Python program. You can now continue writing and executing more complex
Python code within Spyder.
1
lOMoAR cPSD| 34023260
VIVA QUESTIONS:
➢ How can you install Spyder IDE on your computer, and what are the
benefits of using Spyder over a standard text editor for Python
programming?
➢ How do you execute a Python program in the Spyder IDE, and what
are the different ways to run the code?
2
lOMoAR cPSD| 34023260
4
lOMoAR cPSD| 34023260
# loss.backward()
# optimizer.step()
# running_loss += loss.item()
# print(f"Epoch {epoch+1}, Loss:
{running_loss/len(train_loader)}")
In these examples, we've created simple neural network architectures using
TensorFlow/Keras and PyTorch, but you can build more complex models
depending on your specific tasks and requirements.
VIVA QUESTIONS:
➢ How can you install Keras, TensorFlow, and PyTorch libraries on
your system, and what are the differences between these deep
learning frameworks?
5
lOMoAR cPSD| 34023260
6
lOMoAR cPSD| 34023260
To apply CNNs to these computer vision problems, you'll need labeled datasets
for training, and you'll build and train CNN architectures using popular deep
learning libraries like TensorFlow, Keras, or PyTorch. The specific architecture
and training process will vary depending on the problem at hand. It's also
common to use pre-trained CNN models (e.g., VGG, ResNet, MobileNet) and
fine-tune them on specific tasks if you have limited data.
Overall, CNNs have revolutionized computer vision and continue to advance
the state-of-the-art in a wide range of applications, bringing significant
improvements to the accuracy and robustness of computer vision systems.
VIVA QUESTIONS:
➢ What is the main advantage of using Convolutional Neural Networks
(CNNs) over traditional fully connected neural networks for computer
vision tasks?
➢ Explain the typical architecture of a Convolutional Neural Network used
for image classification, and what are the functions of different layers in
this architecture?
7
lOMoAR cPSD| 34023260
8
lOMoAR cPSD| 34023260
model = models.Sequential()
# Convolutional layers
model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
# Flatten the 3D output to 1D
model.add(layers.Flatten())
# Fully Connected layers
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(10, activation='softmax')) # 10 output classes (0-9
digits)
Step 4: Compile the model
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
Step 5: Train the model
model.fit(train_images, train_labels, epochs=5, batch_size=64,
validation_split=0.1)
Step 6: Evaluate the model on the test set
test_loss, test_accuracy = model.evaluate(test_images, test_labels)
print("Test accuracy:", test_accuracy)
Step 7: Make predictions on new data
predictions = model.predict(test_images[:5])
predicted_labels = np.argmax(predictions, axis=1)
print("Predicted labels:", predicted_labels)
print("True labels:", test_labels[:5])
9
lOMoAR cPSD| 34023260
This code will create a CNN model with three convolutional layers followed by
a fully connected layer. It will then train the model on the MNIST dataset and
evaluate its accuracy on the test set. Finally, it will make predictions on five test
images and display the predicted labels along with the true labels.
You can experiment with the number of layers, units, and other hyperparameters
to improve the model's performance. Additionally, you can use techniques like
data augmentation and dropout to further enhance the model's generalization
capabilities.
VIVA QUESTIONS:
➢ What is the MNIST dataset, and why is it commonly used for testing
image classification models?
➢ Describe the architecture of a CNN model with a fully connected
layer for image classification on the MNIST dataset.
10
lOMoAR cPSD| 34023260
Transformers:
Transformers introduced the attention mechanism, enabling more efficient and
parallelized processing of sequential data. They have revolutionized NLP by
capturing long-range dependencies effectively and have become the backbone
of modern language models.
Applications:
Machine Translation (e.g., Text generation Question-Answering
Google's Transformer- (e.g., OpenAI's GPT (e.g., Google's BERT-
based model "BERT" for series) based model "BERT" for
NMT) QA)
11
lOMoAR cPSD| 34023260
trained representations can be fine-tuned for a wide range of NLP tasks, making
it a versatile and powerful model.
Applications:
Text Named Entity Sentiment Question-
classification Recognition analysis Answering
(NER)
These deep learning models, along with their variants and combinations, have
driven significant advancements in the field of Natural Language Processing,
enabling the development of more sophisticated and context-aware language
models and applications. As research progresses, we can expect further
improvements and innovations in NLP, ultimately leading to more accurate and
human-like language processing systems.
VIVA QUESTIONS:
➢ What is the role of Word Embeddings in Natural Language
Processing, and how do they benefit deep learning models for NLP
tasks?
➢ How do Recurrent Neural Networks (RNNs) handle sequential data
in Natural Language Processing, and what are some of the challenges
they face?
13
lOMoAR cPSD| 34023260
14
lOMoAR cPSD| 34023260
epochs = 5
model.fit(train_data, train_labels, batch_size=batch_size, epochs=epochs,
validation_split=0.2)
Step 5: Evaluate the model on the test set.
test_loss, test_accuracy = model.evaluate(test_data, test_labels)
print("Test accuracy:", test_accuracy)
That's it! With these steps, you have built and trained a sentiment analysis
model on the IMDB dataset using RNN layers with LSTM/GRU units. The
model will learn to predict whether movie reviews are positive or negative
based on the given text. You can experiment with different hyperparameters,
such as the number of LSTM/GRU units, the embedding dimension, or the
number of epochs, to see how they affect the model's performance.
VIVA QUESTIONS:
15
lOMoAR cPSD| 34023260
16
lOMoAR cPSD| 34023260
VIVA QUESTIONS:
17
lOMoAR cPSD| 34023260
18
lOMoAR cPSD| 34023260
return model
def build_discriminator(img_shape):
model = Sequential()
model.add(Flatten(input_shape=img_shape))
model.add(Dense(512))
model.add(LeakyReLU(alpha=0.01))
model.add(Dense(256))
model.add(LeakyReLU(alpha=0.01))
model.add(Dense(1, activation='sigmoid'))
return model
19
lOMoAR cPSD| 34023260
real_images = X_train[idx]
noise = np.random.normal(0, 1, (half_batch, latent_dim))
generated_images = generator.predict(noise)
d_loss_real = discriminator.train_on_batch(real_images, np.ones((half_batch,
1)))
d_loss_fake = discriminator.train_on_batch(generated_images,
np.zeros((half_batch, 1)))
d_loss = 0.5 * np.add(d_loss_real, d_loss_fake)
# Train the generator
noise = np.random.normal(0, 1, (batch_size, latent_dim))
valid_labels = np.ones((batch_size, 1))
g_loss = gan.train_on_batch(noise, valid_labels)
VIVA QUESTIONS:
20