Git Product home page Git Product logo

manning_tf2_in_action's Introduction

This project is the code repository for TensorFlow in Action.

IMPORTANT: You will need to have Visual Studio installed. Make sure your installation has Windows SDK

Video Guides for Installation

Prerequisites (If you want GPU support)

  • Install the latest NVIDIA driver for your GPU from this page
  • Install CUDA 11.2 (TensorFlow 2.9.1)
  • Setup CuDNN (v8.2 for CUDA 11.2)
  • Make sure your $PATH variable contains the path to the bin folder of cuda (e.g. On Windows - C:\CUDA\v11.2\bin)
    • On UNIX - Set LD_LIBRARY_PATH to lib64 folder (e.g. /usr/local/cuda-11.2/lib64)

Creating a Virtual Environment (Anaconda) (Recommended)

  • Install Anaconda
  • Open up Anaconda Prompt
  • Setup a conda virtual environment with conda create -n manning.tf2 python=3.9
  • Activate the environment with conda activate manning.tf2
  • Install the required libraries using pip install -r requirements.txt

Creating a Virtual Environment (virtualenv)

  • Install Python 3.9 by following instructions on the webpage. Make sure it is added to the PATH variable.
  • To verify the installation of Python3.9, go to the command line terminal and type python and press enter. You should see a message similar to the following.
     Python 3.9.0 (...) [...] on ...
     Type "help", "copyright", "credits" or "license" for more information.
    
  • Type exit() to exit the Python interpreter.
  • Run pip3 install virtualenv to install Python virtual environment package
  • Go to where you would like the virtual env created (e.g. cd C:\Users\<user>\Documents\code\python_venvs) and type python -m venv manning.tf2. You should see a directory called manning.tf2 created in the directory you are in.
  • Now to activate the virtual environment, from the directory you were originally in (e.g. C:\Users\<user>\Documents\code\python_venvs),
    • On Windows - Run manning.tf2\Scripts\activate.bat
    • On UNIX - Run source manning.tf2\bin\activate
  • If successfully activated, you should see a (manning.tf2) in front of the normal prompt you get in the command line interface (CLI).
  • Now run pip install -r requirements.txt to install all the necessary packages

Tutorial on virtual environments: Here

Important notes

  • For some plotting capability provided in TensorFlow/Keras, you have installed a Python package called graphviz (Installation instructions). Make sure you add it to your $PATH variable.

Getting Jupyter Notebook server up

Now you are ready to run the Jupyter notebook server, allowing you to run the notebooks provided in the code repository.

  • Open up the command line terminal and activate the virtual environment manning.tf2 if you haven't already
  • Go in to the directory you downloaded code to using cd in the CLI (e.g. cd C:\Users\<user>\Documents\code\manning_tf2_in_action)
  • Run jupyter notebook in the CLI
  • This should open up the jupyter notebook server's landing page on your default browser
  • Now you can navigate the folder structure within that directory, open any notebook and run it.

manning_tf2_in_action's People

Contributors

thushv89 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

manning_tf2_in_action's Issues

Ch07 Minception `inception_resnet_a` function is wrong

This should not be there

out2_3 = Conv2D(n_filters[1][2], (1,1), strides=(1,1), activation=None, 
                        kernel_initializer=initializer, padding='same')(out2_2)
if bn:
    out2_3 = BatchNormalization()(out2_3)
out2_3 = Activation(activation)(out2_3)

and

out4_1 = Concatenate(axis=-1)([out1_1, out2_2, out3_4])

Then when putting the network together it should be,

inc_a = inception_resnet_a(stem_out, [(32,),(32,32), (32, 48, 64, 384),(384,)], initializer=init)

Files to be added/removed after renaming

Files to be removed

  • Ch05-Transformers/Untitled.ipynb
  • Ch08-Image-Segmentation-with-CNNs/ch08_utils.ipynb

Files to be added

  • Ch11-Ch12-Sequence-to-Sequence-Learning-with-TF2/attention.py -- is that needed?
  • Ch14-Ch15-TFX-for-MLOps-in-TF2/tfx/*

Final check (chapters 6, 7 , 8, 9, 10, 12) - Merge `dev` to `master`

Ch06/6.1 - Move Bonus: Metrics of the model section below training - say the model needs to be fit before calling this
Ch06 checked
Ch07/7.1 - Move Metrics that we'll be looking at under the training
Ch07 checked
Ch08/8.1 - Move/Delte first "Plot some train images and their predictions" section under Unet
Ch09 checked
Ch10 - Under Let's look at some word ID sequences, in the for loop rename ngrams to something else.
Ch10 checked
Commit Ch12 / 12.2 after running / 12.1 after running
Ch12 checked

Add tensorflow_addons to requirements.txt
Add tf-models-official to requirements.txt
After all checks copy util functions to separate chapter specific util

transformers library `return_dict` in graph mode issue

An error was thrown because the return_dict argument cannot be set in graph mode

import transformers
from transformers import TFDistilBertForQuestionAnswering

config = DistilBertConfig.from_pretrained("distilbert-base-uncased", return_dict=False)
model = TFDistilBertForQuestionAnswering.from_pretrained("distilbert-base-uncased", config=config)

input_ids = tf.keras.layers.Input([None,], dtype=tf.int32, name="input_ids")
attention_mask = tf.keras.layers.Input([None,], dtype=tf.int32, name="attention_mask")
out = model([input_ids, attention_mask])
model_v2 = tf.keras.models.Model([input_ids, attention_mask], outputs=(out.start_logits, out.end_logits))

loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
metric = tf.keras.metrics.SparseCategoricalAccuracy()
#model.distilbert.return_dict = False # if using Transformers >3.02, make sure outputs are tuples

optimizer = tf.keras.optimizers.Adam(learning_rate=5e-5)
model_v2.compile(optimizer=optimizer, loss=loss) # can also use any keras loss fn

model_v2.fit(train_dataset, epochs=3)

Ch09 fixes

  • Use random seed for everything in train/valid/test split
  • Use percentile 0.9 for sequence length analysis
  • Add no to stop words
  • Rename data to inputs (also the save name)

Ch05: Decoder Layer

In chapter 5's decoder layer you define dec_attn_heads but never actually use it in the call.

If I understand correctly the way to fix it is to:

  1. add input to compute_multihead_output (the multi-head list)
  2. adjust h1 and h2 accordingly.

Input of upsampling layer in ASPP

In code listing 8.11 in the Python notebook the upsampling layer is defined as:

outb_1_up = layers.UpSampling2D((24,24), interpolation='bilinear')(outb_1_avg)

From what I understand, the input to the upsampling layer here (outb_1_up) should be the output of the earlier convolution (outb_1_conv), not the output of the averaging layer (outb_1_avg).

Would be nice to confirm this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.