Slide 1

Slide 1 text

Understanding Neural Networks with Keras and TensorFlow Cloud Mbarara

Slide 2

Slide 2 text

What is TensorFlow? It's an open-source deep learning framework that offers a vast array of tools, libraries, and resources to create and implement machine learning and deep learning models. TensorFlow is and maintained developed by the Google Brain team import tensorflow as tf

Slide 3

Slide 3 text

What is Keras? It's a Python-based, open-source neural network API designed to simplify the process of building, training, and deploying deep learning models. Keras was developed by François Chollet in 2015 import keras // from tensorflow import keras

Slide 4

Slide 4 text

What are Neural Networks? They are computational models inspired by the human brain's interconnected neurons, utilized in machine learning to process and learn from data, making them capable of complex pattern recognition and decision-making. Neural network layers can have a state (i.e have weights) or be stateless.

Slide 5

Slide 5 text

Input Layer The input layer is where data is fed into the neural network. Each node (or neuron) in this layer represents a feature of the input data. Hidden Layers Between the input and output layers, we have one or more hidden layers. Each layer consists of neurons that apply weighted sums and activation functions to their inputs. A typical neural network in practice can have hundreds of hidden layers. Neurons Each neuron takes the weighted sum of its inputs (from the previous layer) plus a bias term.

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Activation Functions - Rectified Linear Unit (ReLU) - Tanh - Sigmoid - Softmax Optimizers - RMSProp - Adam

Slide 9

Slide 9 text

Let me explain it in code… Cloud Mbarara  The Innovation Village @TheVillageUG Following  Institute for Nonprofit News @INN  INNA @inna_ro  Mo Rocca @MoRocca  Innersloth  @InnerslothDevs  Inna Afinogenova @inafinogenova  Inner City Press @innercitypress

Slide 10

Slide 10 text


 from tensorflow.keras.datasets import mnist
 from tensorflow import keras
 from tensorflow.keras import layers
 
 (train_images,train_labels),(test_images,test_labels) = mnist.load_data()


Slide 11

Slide 11 text

Then we visualize the data Cloud Mbarara

Slide 12

Slide 12 text

from matplotlib import pyplot as plt
 from matplotlib import image as mpimg
 
 plt.title("Sample Image")
 plt.xlabel("X pixel scaling")
 plt.ylabel("Y pixels scaling")
 
 sample_image = test_images[0]
 plt.imshow(sample_image,cmap=plt.cm.binary)
 plt.show()


Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Build the neural network with 2 layers… Cloud Mbarara

Slide 15

Slide 15 text

model = keras.Sequential([
 layers.Dense(512, activation ="relu"), layers.Dense(10, activation="softmax")
 ])
 
 
 


Slide 16

Slide 16 text

Compile the model… Cloud Mbarara

Slide 17

Slide 17 text

model.compile(
 optimizer ="rmsprop",
 loss = "sparse_categorical_crossentropy",
 metrics=["accuracy"]
 )
 
 


Slide 18

Slide 18 text

Reshape the data and fit the model… Cloud Mbarara

Slide 19

Slide 19 text

train_images = train_images.reshape((60000,28*28))
 train_images = train_images.astype("float32")/255
 test_images = test_images.reshape((10000,28*28))
 test_images = test_images.astype("float32")/255
 
 model.fit(
 train_images,train_labels, 
 epochs=10, 
 batch_size=128
 )


Slide 20

Slide 20 text

Evaluate the model… Cloud Mbarara

Slide 21

Slide 21 text

test_loss, test_acc = model.evaluate(
 test_images, test_labels
 )
 
 print(f"Test Accuracy is: {test_acc}")


Slide 22

Slide 22 text

Perform an inference to make predictions… Cloud Mbarara

Slide 23

Slide 23 text

image_test = mpimg.imread("test_image.png")
 plt.imshow(image_test)
 
 from mnst_image_format_converter import imageprepare
 image_test = imageprepare("test_image.png")
 plt.imshow(image_test, cmap=plt.cm.binary )


Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Make predictions… Cloud Mbarara

Slide 26

Slide 26 text

import numpy as np
 imgNumpyData = np.array(image_test)
 
 type(imgNumpyData)
 imgNumpyData.shape
 imgNumpyData = imgNumpyData.reshape((1,784))
 imgNumpyData = imgNumpyData.astype("float32")/255
 
 prediction_test = model.predict(imgNumpyData)


Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Let’s see this in play… Cloud Mbarara

Slide 29

Slide 29 text

Cloud Mbarara Thank you! Any questions? Wesley Kambale @weskambale kambale.dev