Deep Learning for Coders with fastai and PyTorch: My Journey Through Chapters 1–3

Krupa SawantKrupa Sawant
4 min read

A structured summary of Part 1 (Chapters 1–3) from “Deep Learning for Coders with fastai and PyTorch” by Jeremy Howard & Sylvain Gugger— what I learned and why it matters!

🌟 Breaking the Barriers: Deep Learning Is for Everyone

The biggest myth about deep learning? That it’s only for PhDs or big companies.
Here’s what you actually DON’T need:

  • Advanced math (high school math is enough)

  • Massive datasets (amazing results with just 50 images)

  • Supercomputers (free GPUs work great)

  • A PhD (passion > degrees)

Deep learning uses neural networks with multiple layers to automatically learn patterns in data.

🧠 What Is a Neural Network?

A neural network is a flexible mathematical function made up of weights. Thanks to the Universal Approximation Theorem, in theory a neural network can model any problem to any accuracy, as long as it has enough layers and data.

Key properties:

  • Highly flexible – can learn many types of problems

  • Automatically improves using Stochastic Gradient Descent (SGD)

  • One method works for vision, text, audio, and more

🤖 What Is Machine Learning?

Arthur Samuel defined machine learning as programming computers to learn from experience instead of explicit instructions.
The key is: give the computer data and a way to evaluate itself, and it improves automatically.

Traditional programming:

Inputs → Program → Results

Machine learning:

Inputs + Weights → Model → Results → Compare → Update Weights

And once trained:

New Input → Trained Model → Predictions

Modern terms:

  • Architecture = program structure

  • Parameters = weights

  • Loss = performance measure optimized during training

  • Metrics = human-readable performance measure

Building My First Model: Image Classifier

This exercise inspired me to apply the same approach to build my own “Windows vs Doors” classifier.
I collected a small dataset, fine‑tuned a pretrained model, deployed it as a web app with Gradio, and hosted it on Hugging Face Spaces.
👉 Read the full article here

Steps

  1. Import libraries – fastai simplifies everything

  2. Download dataset – Oxford-IIIT Pet Dataset (7,349 labeled images)

  3. Label images – extract “cat” or “dog” from filenames

  4. Create DataLoaders – split into training & validation

  5. Build CNN Learner – use a pretrained ResNet

  6. Fine-tune – adapt to our dataset

  7. Evaluate – < 2% error, in minutes!

🔍 Understanding What We Just Built

  • At first, our model feels like magic: a few lines of code and it can tell cats from dogs. In reality, it’s a Convolutional Neural Network (CNN)—a model that mimics how the visual cortex works. Early layers detect edges and textures; deeper layers combine them into complex shapes like ears or faces.

    We didn’t start from scratch. Instead, we used a pretrained ResNet model, which had already learned visual patterns from 1.3M ImageNet images. Through transfer learning, we reused this knowledge and added a new “head” layer for our task.

    The fine-tuning process:

    1. Train only the new head.

    2. Gradually adjust earlier layers.

    3. Evaluate on a validation set (20% unseen data) to ensure generalization.

What looks like magic is a structured process: reuse past knowledge, adapt it, and validate.

🌍 Beyond Image Classification (Quick Glimpse)

Deep learning also powers:

  • Object detection, image segmentation

  • Text understanding, summarization, translation

  • Fraud detection, recommendation systems, even audio analysis

🧠 Chapter 2: Going Deeper Into How It Works

Chapter 1 felt like magic—few lines of code and a near-perfect classifier. Chapter 2 slows things down and explains the mechanics behind that magic.


Preparing Data the Right Way

Fastai automates key steps:

  • Download & split datasets (e.g., Oxford Pets) into training and validation sets with RandomSplitter.

  • Resize all images to a fixed size for efficient computation.

  • Augment data (flips, rotations, crops) to make models robust even with small datasets.

DataLoaders and the Training Loop

DataLoaders batches and shuffles data automatically. The model learns in a loop:
predict → calculate loss → adjust weights → repeat for many epochs.

Core Concepts Reinforced

  • Transfer learning & fine‑tuning: Start from a pretrained model and adapt.

  • Classification vs regression: Predict categories vs continuous values.

  • Overfitting: When the model memorizes instead of generalizing.

⚖Chapter 3 – Data Ethics

This chapter covers why ethics is central to AI.

Types of Issues:

  1. Bias

    • Example: A hiring algorithm trained on biased data may discriminate against women.
  2. Feedback Loops

    • Example: Predictive policing systems that focus on certain neighborhoods end up sending more police there, reinforcing bias.
  3. Disinformation

    • Example: Algorithms recommending extreme content based on engagement metrics.

What Can We Do?

  • Diverse data: Avoid one-sided training sets

  • Transparency: Show how models make predictions

  • Policy changes: Actively review and adjust outcomes

  • Human oversight: Models should assist, not decide alone

✨ Final Thoughts

These first three chapters turned deep learning from “magic” into a clear process: good data, pretrained models, fine‑tuning, and validation.
I even applied these steps to build my own Windows‑vs‑Doors classifier and deploy it online.

In the next article, we’ll explore Part 2 of the book—diving deeper into larger datasets, performance tricks, and what’s really happening inside the models.

0
Subscribe to my newsletter

Read articles from Krupa Sawant directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Krupa Sawant
Krupa Sawant