Book Image

The TensorFlow Workshop

By : Matthew Moocarme, Abhranshu Bagchi, Anthony So, Anthony Maddalone
Book Image

The TensorFlow Workshop

By: Matthew Moocarme, Abhranshu Bagchi, Anthony So, Anthony Maddalone

Overview of this book

Getting to grips with tensors, deep learning, and neural networks can be intimidating and confusing for anyone, no matter their experience level. The breadth of information out there, often written at a very high level and aimed at advanced practitioners, can make getting started even more challenging. If this sounds familiar to you, The TensorFlow Workshop is here to help. Combining clear explanations, realistic examples, and plenty of hands-on practice, it’ll quickly get you up and running. You’ll start off with the basics – learning how to load data into TensorFlow, perform tensor operations, and utilize common optimizers and activation functions. As you progress, you’ll experiment with different TensorFlow development tools, including TensorBoard, TensorFlow Hub, and Google Colab, before moving on to solve regression and classification problems with sequential models. Building on this solid foundation, you’ll learn how to tune models and work with different types of neural network, getting hands-on with real-world deep learning applications such as text encoding, temperature forecasting, image augmentation, and audio processing. By the end of this deep learning book, you’ll have the skills, knowledge, and confidence to tackle your own ambitious deep learning projects with TensorFlow.
Table of Contents (13 chapters)
Preface

10. Custom TensorFlow Components

Activity 10.01: Building a Model with Custom Layers and a Custom Loss Function

Solution:

To get started, open a new Colab or Jupyter Notebook. If you are using Google Colab, you will need to download the dataset into your Google Drive first:

  1. Open a new Jupyter notebook or Google Colab notebook.
  2. If you are using Google Colab, you can upload your dataset locally with the following code. Otherwise, go to step 4. Click on Choose Files to navigate to the CSV file and click Open. Save the file as uploaded. Then, go to the folder where you saved the dataset:
    from google.colab import files
    uploaded = files.upload()
  3. Unzip the dataset in the current folder:
    !unzip \*.zip
  4. Create a variable, directory, that contains the path to the dataset:
    directory = "/content/gdrive/My Drive/Datasets/pneumonia-or-healthy/"
  5. Import all the required libraries:
    import numpy as np
    import pandas as pd
    import pathlib...