๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #490

Deployment Project

The final project โ€” taking one of the models built in this section and actually shipping it as a real, callable web service, closing the loop from "a model that works in a notebook" to "a model someone else can actually use."

Problem Statement

Take a trained model from any earlier project (the Image Classification project is a good default choice for its simplicity) and deploy it as a containerized REST API that accepts a real request and returns a real prediction โ€” directly applying the full Deployment category to a project you've already built.

Approach

This project combines model serialization, FastAPI serving, and Docker containerization into one complete, working deployment โ€” the same pattern covered individually in FastAPI Model Serving and Docker Deployment, now assembled end to end around a model you've personally trained.

Step-by-Step Build

# 1. Save the trained model's weights (from the Image Classification project)
torch.save(model.state_dict(), "model_weights.pt")
# main.py -- the FastAPI serving application
from fastapi import FastAPI, UploadFile
from PIL import Image
import torch
import torchvision.transforms as T
import io

app = FastAPI()

model = torchvision.models.resnet18(weights=None)
model.fc = torch.nn.Linear(model.fc.in_features, 10)
model.load_state_dict(torch.load("model_weights.pt", map_location="cpu"))
model.eval()

transform = T.Compose([
    T.Resize(224), T.ToTensor(),
    T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])
class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer',
               'dog', 'frog', 'horse', 'ship', 'truck']

@app.get("/health")
def health_check():
    return {"status": "healthy"}

@app.post("/predict")
async def predict(file: UploadFile):
    image_bytes = await file.read()
    image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
    x = transform(image).unsqueeze(0)

    with torch.no_grad():
        output = model(x)
        probs = torch.softmax(output, dim=1)
        confidence, predicted_idx = probs.max(dim=1)

    return {
        "prediction": class_names[predicted_idx.item()],
        "confidence": round(confidence.item(), 4)
    }
# Dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY model_weights.pt main.py .
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
# Build and run
# $ docker build -t image-classifier-api .
# $ docker run -p 8000:8000 image-classifier-api

# Test it with a real request
# $ curl -X POST "http://localhost:8000/predict" -F "file=@test_image.jpg"
# {"prediction": "dog", "confidence": 0.9421}

Expected Results

A running Docker container that accepts an uploaded image via HTTP POST and returns a JSON prediction with a confidence score, callable from any HTTP client (curl, a browser, another application) โ€” a genuinely complete, working service, not just a notebook cell.

Key Learnings & Extensions

  • This project makes tangible the gap between "my model works when I call it in Python" and "my model works as a real service" โ€” input validation, error handling, and a health check endpoint all matter here in ways that don't come up in a notebook.
  • Extension: Add proper error handling for malformed or non-image uploads, returning a clear 400 error rather than an unhandled exception, applying REST API Deployment's guidance.
  • Extension: Measure and report the API's actual latency under load, applying the profiling approach from Inference Latency.
  • Extension: Deploy the container to an actual cloud provider (following Cloud Deployment or AWS Deployment) so the service is reachable from outside your own machine โ€” the true final step of shipping a real, usable model.

Closing Note โ€” The Full Curriculum, Complete

This is the final note of the entire 39-category Deep Learning notes hub โ€” from linear algebra and calculus, through neural network fundamentals, CNNs, sequence models, Transformers, generative and modern LLM-era models, practical PyTorch and TensorFlow, the full project lifecycle and production deployment, research skills, interview preparation, hands-on practice problems, and now twelve complete end-to-end projects finishing with an actually deployed, working service. Every concept introduced early in this hub โ€” from the chain rule to attention to drift monitoring โ€” has now been applied at least once in a real, working build. Congratulations on reaching the end of the curriculum.

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

Deployment Project โ€“ FAQs

Quick answers about learning Deployment Project in Deep Learning.

This free note from CodingNow 2.0 explains Deployment Project in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Deployment Project, is 100% free with no signup required.
With focused practice, most students grasp Deployment Project in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now