JulienBeaulieu
  • Introduction
  • Sciences
    • Math
      • Probability
        • Bayes Rule
        • Binomial distribution
        • Conditional Probability
      • Statistics
        • Descriptive Statistics
        • Inferential Statistics
          • Normal Distributions
          • Sampling Distributions
          • Confidence Intervals
          • Hypothesis Testing
          • AB Testing
        • Simple Linear Regression
        • Multiple Linear Regression
          • Statistical learning course
          • Model Assumptions And How To Address Each
        • Logistic Regression
      • Calculus
        • The big picture of Calculus
          • Derivatives
          • 2nd derivatives
          • The exponential e^x
        • Calculus
        • Gradient
      • Linear Algebra
        • Matrices
          • Matrix Multiplication
          • Inverses and Transpose and permutations
        • Vector Space and subspaces
        • Orthogonality
          • Orthogonal Sets
          • Projections
          • Least Squares
        • Gaussian Elimination
    • Programming
      • Command Line
      • Git & GitHub
      • Latex
      • Linear Algebra
        • Element-wise operations, Multiplication Transpose
      • Encodings and Character Sets
      • Uncategorized
      • Navigating Your Working Directory and File I/O
      • Python
        • Problem Solving
        • Strings
        • Lists & Dictionaries
        • Storing Data
        • HTTP Requests
      • SQL
        • Basic Statements
        • Entity Relationship Diagram
      • Jupyter Notebooks
      • Data Analysis
        • Data Visualization
          • Data Viz Cheat Sheet
          • Explanatory Analysis
          • Univariate Exploration of Data
            • Bar Chart
            • Pie Charts
            • Histograms
            • Kernel Density Estimation
            • Figures, Axes, and Subplots
            • Choosing a Plot for Discrete Data
            • Scales and Transformations (Log)
          • Bivariate Exploration of Data
            • Scatterplots
            • Overplotting, Transparency, and Jitter
            • Heatmaps
            • Violin & Box Plots
            • Categorical Variable Analysis
            • Faceting
            • Line Plots
            • Adapted Bar Charts
            • Q-Q, Swarm, Rug, Strip, Stacked, and Rigeline Plots
          • Multivariate Exploration of Data
            • Non-Positional Encodings for Third Variables
            • Color Palettes
            • Faceting for Multivariate Data
            • Plot and Correlation Matrices
            • Other Adaptations of Bivariate PLots
            • Feature Engineering for Data Viz
        • Python - Cheat Sheet
    • Machine Learning
      • Courses
        • Practical Deep learning for coders
          • Convolutional Neural Networks
            • Image Restauration
            • U-net
          • Lesson 1
          • Lesson 2
          • Lesson 3
          • Lesson 4 NLP, Collaborative filtering, Embeddings
          • Lesson 5 - Backprop, Accelerated SGD
          • Tabular data
        • Fast.ai - Intro to ML
          • Neural Nets
          • Business Applications
          • Class 1 & 2 - Random Forests
          • Lessons 3 & 4
      • Unsupervised Learning
        • Dimensionality Reduction
          • Independant Component Analysis
          • Random Projection
          • Principal Component Analysis
        • K-Means
        • Hierarchical Clustering
        • DBSCAN
        • Gaussian Mixture Model Clustering
        • Cluster Validation
      • Preprocessing
      • Machine Learning Overview
        • Confusion Matrix
      • Linear Regression
        • Feature Scaling and Normalization
        • Regularization
        • Polynomial Regression
        • Error functions
      • Decision Trees
      • Support Vector Machines
      • Training and Tuning
      • Model Evaluation Metrics
      • NLP
      • Neural Networks
        • Perceptron Algorithm
        • Multilayer Perceptron
        • Neural Network Architecture
        • Gradient Descent
        • Backpropagation
        • Training Neural Networks
  • Business
    • Analytics
      • KPIs for a Website
  • Books
    • Statistics
      • Practice Statistics for Data Science
        • Exploring Binary and Categorical Data
        • Data and Sampling Distributions
        • Statistical Experiments and Significance Testing
        • Regression and Prediction
        • Classification
        • Correlation
    • Pragmatic Thinking and Learning
      • Untitled
    • A Mind For Numbers: How to Excel at Math and Science
      • Focused and diffuse mode
      • Procrastination
      • Working memory and long term memory
        • Chunking
      • Importance of sleeping
      • Q&A with Terrence Sejnowski
      • Illusions of competence
      • Seeing the bigger picture
        • The value of a Library of Chunks
        • Overlearning
Powered by GitBook
On this page
  • DataLoader and dataset in pytorch and databunch in fastai
  • Transforms and data augmentation
  • Satellite dataset
  • Transfer learn your own model
  • Image segmentation - classify every pixel
  • Fit one cycle

Was this helpful?

  1. Sciences
  2. Machine Learning
  3. Courses
  4. Practical Deep learning for coders

Lesson 3

PreviousLesson 2NextLesson 4 NLP, Collaborative filtering, Embeddings

Last updated 5 years ago

Was this helpful?

DataLoader and dataset in pytorch and databunch in fastai

Pytorch has this class dataset

It does nothing yet.

It defines 2 things: __getitem__ (=your object and be indexed with [0]), and __len__ (you can do len(object) = gives the len).

The starting point for our data is: getitem, and how big is the dataset. It's not enough on its own to train a model. We need to be able to get minibatches. This is done using a dataloader.

It takes a dataset and its constructor (it can get items now) it's going to get items at random and create a minibatch for whatever size you ask for and pop it on the gpu and put it into our model.

These 2 aren't enough to create a model yet, we need a validation set as well. In fast ai we use a DataBunch for this: it binds together a train_dl (train dataloader) and a valid_dl.

Now this is an object that you can send this off to a learner and start fitting.

Transforms and data augmentation

By defaut they will flip randomly each image, but only horizontally. For dog and cat dataset it makes sense but for satellite imagery you'd want to flip.

Wrap: If you look from above or below, the object changes shape so you'd want to include this. But for satellite images you wouldn't need this.

Satellite dataset

Pretty much the same thing as before except for passing multiple labels at the beginning,etc.

Something else that's different are the metrics - Here we're getting accuracy and fbeta. (this is because kaggle's evaluation - fscore (f2 for this dataset)

We need to change the threshold.

data.c : gives you the number of classes you have. For this dataset we have 17.

Question: in production what can you do with misclassified images? Can you use them to improve the model?

Yes - it's up to you to get the feedback from the user and know it's wrong. Then you can log it.

Then create a dataset with all the misclassified instances - which are particularily interesting so we can fit at a higher learning rate. You pass in the correct classifications.

Transfer learn your own model

INitially we created a model with image size = 128. Why? We wanted to experiment quickly. Also, we now have a model that's pretty good at recognizing images of 128*128.

If we want one that's good at 256, then we can start with the model that was trained on 128*128 and use that = transfer learning.

You loose the overfitting because we're learning on a new data set. We'll use the same learning but use a new learner that's 256*256.

You use the same learner so we start with a pretrained model. Then we replace our databunch with the new one - learn.data = data

Freeze again - new lr_find(), get lr's, fit()

Then usual steps - unfreeze, fit, etc.

Image segmentation - classify every pixel

Classification problem for every single pixel, and for every single image. You need a datasert where someone already labeled the dataset like this:

Common in self driving cars, or radiographic, the metal lesion / weakness dataset on kaggle.

For segmentation we don't just use an convolutional NN. We also use something called U-net. To create a segmentation model we should use a unet - Fastai library has it. learner.create_unet(...)

Fit one cycle

Makes the learning rate start low, goes up and down again. Why is that a good idea? Getting the right learning rate is important because it zooms to the best spot very quickly, instead of taking a lot of time or diverging.

As we get closer to the final spot, we really want our lr to decrease because we're getting close to the right spot. What happens is uusually have a loss function surface like this:

We want an lr that is high enough to go over the bumps, but when we're close to the right answer we take smaller and smaller steps.

This is how the lr varies with fit one cycle. The idea of decreasing the lr at the end is not new, it's call aneiling (sp?). But increasing it at the start is new.

Actually the loss surface looks more like this:

Kinda flat where the best solution is. So if you find a solution in one of the whole, it's not great. With a small lr you can't really reach the flat part.

It helps the model explore all the loss surface. It also means we can train our model more quickly.

Here with plot_losses the training and validation error goes slightly up, then back down. When that happens you know you've found a really good lr. If you don't have this graph you can try increasing the lr very slightly.

Momentum and fit one cycle

Momentum levels are on the right graph.

Dataset: CAMVID