Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Understanding Neural Networks with Keras and Te...

Understanding Neural Networks with Keras and TensorFlow

The session was about understanding how neural networks are built and how you can use TensorFlow and Keras to build one.

Wesley Kambale

November 25, 2023
Tweet

More Decks by Wesley Kambale

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. 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.
  4. 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.
  5. Activation Functions - Rectified Linear Unit (ReLU) - Tanh -

    Sigmoid - Softmax Optimizers - RMSProp - Adam
  6. 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
  7. 
 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()

  8. 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()

  9. 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
 )

  10. 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)