CP3501/CP5701 Deep Learning
Part 1: Machine Learning & Deep Learning Fundamentals
Part 2: Deploying Your Models to Production
Information Technology | College of Science and Engineering
James Cook University
Part 1: Machine Learning & Deep Learning Fundamentals
Part 2: Deploying Your Models to Production
Information Technology | College of Science and Engineering
James Cook University
Humans write explicit rules:
if temperature > 30: "Hot"
Algorithm discovers rules from examples:
Learns patterns automatically
Predicting continuous numbers
Predicting categories/classes
| Aspect | Traditional ML | Deep Learning |
|---|---|---|
| Feature Engineering | Manual - humans decide what features matter (e.g., "ear shape", "fur texture") |
Automatic - learns features from raw data |
| Data Requirements | Works with smaller datasets (hundreds to thousands) |
Needs large datasets (thousands to millions) |
| Computation | Can run on regular CPU | Usually needs GPU for training |
| Interpretability | Easier to understand why it made a decision | Often a "black box" |
| Performance | Good for structured/tabular data | Excels at images, text, audio |
| Examples | Decision Trees, Random Forest, SVM | Convolutional Neural Networks (CNNs), Transformers |
learn.fine_tune()
learn.export('model.pkl') # Creates this file
import gradio as gr
from fastai.vision.all import *
learn = load_learner('model.pkl')
def classify_image(img):
pred, idx, probs = learn.predict(img)
return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))}
demo = gr.Interface(
fn=classify_image,
inputs=gr.Image(),
outputs=gr.Label()
)
demo.launch()
fastai gradio
learn.fine_tune(3)
learn.export('model.pkl') # Download this file
model.pklapp.py (copy code from slide 13)requirements.txtHugging Face automatically installs libraries and starts your app
import gradio as gr # 1. Import web interface library from fastai.vision.all import * # 2. Import FastAI learn = load_learner('model.pkl') # 3. Load your trained model def classify_image(img): # 4. Define what happens when user uploads pred, idx, probs = learn.predict(img) # - Get prediction from model return { # - Return results as dictionary learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs)) } demo = gr.Interface( # 5. Create the web interface fn=classify_image, # - Which function to call inputs=gr.Image(), # - Input: image upload box outputs=gr.Label(), # - Output: labels with percentages title="My Image Classifier", # - Customize title description="Upload a photo to classify it" ) demo.launch() # 6. Start the web server
learn.export('model.pkl') do?| Error Message | What It Means | How to Fix |
|---|---|---|
FileNotFoundError: model.pkl |
App can't find your model file | Check that model.pkl is in the same directory as app.py |
ModuleNotFoundError: No module named 'fastai' |
FastAI library not installed | Add fastai to requirements.txt |
Application startup failed |
Syntax error in app.py | Check for typos, missing colons, incorrect indentation |
Model was trained with different FastAI version |
Version mismatch | Specify version in requirements.txt: fastai==2.7.14 |
| Image not displaying predictions | Return format issue | Make sure classify_image() returns a dictionary |
demo = gr.Interface(
fn=classify_image,
inputs=gr.Image(),
outputs=gr.Label(num_top_classes=3), # Show top 3 predictions
# Customization options:
title="🐱🐶 Pet Classifier",
description="Upload a photo of a cat or dog to see predictions",
article="Built with FastAI and Gradio. Model trained on Oxford-IIIT Pets dataset.",
examples=[ # Sample images users can try
"example_cat.jpg",
"example_dog.jpg"
],
theme="default", # Try: "default", "huggingface", "grass"
allow_flagging="never" # Disable flagging button
)
--- title: Pet Classifier emoji: 🐱 colorFrom: blue colorTo: purple sdk: gradio sdk_version: 4.0.0 app_file: app.py --- # Pet Classifier This model classifies images of cats and dogs...
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE cd YOUR_SPACE
cp /path/to/model.pkl . # Create app.py and requirements.txt
git add model.pkl app.py requirements.txt git commit -m "Initial deployment" git push
Run learn.export('model.pkl') in your notebook and download the file
Go to huggingface.co and sign up (free)
Spaces → Create new Space → Choose Gradio
Upload test images, add title/description, create README
gradio.app/docsdocs.fast.aihuggingface.co/docs/hub/spaceslearn.export('model.pkl')
We'll dive deeper into what's happening inside neural networks:
- How are images represented as numbers?
- What exactly are tensors?
- How does backpropagation work mathematically?
- Understanding loss functions and optimizers