Machine Learning Zero to Hero (Google I/O'19)
What is Machine Learning?
Introduction to Machine Learning
- Laurence Moroney introduces the concept of machine learning, highlighting its perception as a "magic wand" in tech discussions.
- He questions what machine learning truly entails, especially from a coder's perspective, and engages the audience by asking how many are coders.
Example Scenario: Rock, Paper, Scissors
- Moroney presents a scenario where coding an application for rock, paper, scissors would require complex image recognition code.
- He emphasizes the challenges of differentiating between hand shapes and sizes using traditional programming methods.
Transition to Machine Learning
- The discussion shifts to how machine learning simplifies these tasks by inferring rules from data rather than requiring explicit coding of rules.
- Moroney explains that instead of writing if-then statements for every possible input (like images), one can provide labeled examples for the model to learn from.
Understanding Neural Networks
Training Phase and Model Creation
- The training phase involves creating a model (neural network) that learns patterns from provided data inputs.
- Predictions are generated based on trained models; terminology such as "training" and "inference" is introduced as distinct from traditional programming terms.
Code Structure Overview
- A simple piece of code for creating a neural network is presented, focusing on input size and output categories (rock, paper, scissors).
- Inputs consist of image dimensions while outputs represent classifications; understanding these components is crucial in neural networks.
Deep Dive into Neural Network Functions
Internal Variables and Parameters
- Internal variables within functions are referred to as parameters in machine learning parlance; this distinction can be confusing for programmers.
Model Compilation Process
- The
model.compilefunction sets up loss and optimizer parameters essential for measuring performance during training iterations.
Convolutions: Enhancing Image Processing
Introduction to Convolutions
- Convolutions improve image processing by applying filters that enhance specific features while reducing noise in images.
Pooling Techniques
- Pooling reduces data size by selecting maximum values within defined pixel groups (e.g., 2x2), which speeds up training without losing vital information.
Training Results and Accuracy
Demonstration Outcomes
- After training with convolutions over multiple epochs, accuracy improves significantly—from 33% initially to approximately 97%.
Visualizing Performance
- A plot illustrates accuracy progression over time alongside testing results against separate datasets.
Practical Application: Using PyCharm
Debugging Neural Networks
- Moroney discusses using PyCharm for step-by-step debugging of neural network code to ensure proper functionality during development.
Introduction to TensorFlow Tools
Overview of TensorFlow's Capabilities
- Karmel introduces the session, emphasizing the transition from understanding models to implementing them in production.
- Acknowledges that many attendees may feel overwhelmed by new concepts but reassures them there is no test at the end.
- Highlights the importance of adapting tools for various data types beyond image classification, such as categorical and text-based data.
Data Transformation with Feature Columns
- Discusses how TensorFlow allows transformation of different data types before feeding them into machine learning models.
- Introduces feature columns as a key tool for configuring transformations on incoming data, particularly for categorical variables like user IDs.
- Explains embedding transformations that can be learned during model training, ensuring models interpret categorical data correctly.
Building Models with Keras
Utilizing Keras Layers
- Describes various layers available in Keras, including convolutional and pooling layers tailored for specific use cases.
- Emphasizes the flexibility of Keras in allowing users to subclass layers for custom functionality not provided out-of-the-box.
Custom Layer Implementation
- Provides an example of a Poincare normalization layer contributed by a community member, showcasing how to create custom layers using TensorFlow add-ons.
- Encourages users to explore subclassing options across metrics, losses, and optimizers within Keras.
Monitoring Model Training
Introduction to TensorBoard
- Introduces TensorBoard as a visualization tool essential for tracking model training progress in real-time.
- Highlights features like accuracy and loss tracking over epochs and step-by-step monitoring during training sessions.
Performance Profiling
- Discusses how easy it is to integrate TensorBoard into Keras with minimal code changes while providing performance profiling capabilities.
- Mentions that one tab in TensorBoard helps identify performance bottlenecks during model training.
Scaling Model Training
Parallelization Strategies
- Illustrates the time-consuming nature of training popular models like ResNet-50 on single GPUs versus leveraging parallelization strategies offered by TensorFlow 2.0.
Mirrored Strategy Implementation
- Explains how adding mirrored strategy allows distribution of model training across multiple GPUs with just a few lines of code.
Benefits of Distributed Training
- Details how input data is processed in parallel across devices, significantly speeding up model training times without altering existing code structures.
Productionizing Machine Learning Models
Serialization with Saved Models
- Stresses that deploying machine learning models involves more than just training; serialization into saved models is crucial for integration into production environments.
Deployment Options
- Outlines various deployment libraries such as TensorFlow Serving (for web requests), TensorFlow Lite (for mobile), and mentions their respective uses briefly.
Conclusion: Next Steps with TensorFlow
Resources for Further Learning
- Encourages attendees to explore additional resources available at google.dev and TensorFlow.org for tutorials and open-source contributions.