🚀 Building a Real-Time Object Classification API: From Local Debugging to Deployment Hurdles

Written by:

Hey everyone! Junaid here, and I’m excited to share an update on my latest project: a Real-Time Multi-Class Object Classification API. This project is a deep dive into building an end-to-end Computer Vision (CV) pipeline, focusing on the engineering required to serve custom-trained models efficiently.

What is This Project All About?

At its core, this project uses AI (specifically, YOLOv8 models) to analyze live video feeds or images. The primary goal was to create a robust system that can handle two levels of object detection simultaneously:

  1. Primary Detection: Identifying main objects in a frame (e.g., people, vehicles, furniture).
  2. Secondary Classification: Checking if a specific, smaller object is present in relation to the primary object.

The system is designed to process this information instantly, log a “Missing Class Tag” event if the required secondary object is absent, and capture a snapshot. The end result is a real-time feed that showcases the inference speed and the system’s ability to flag complex scenarios.

The Brains Behind the Operation: Python, Flask, and YOLOv8

I built this project using a powerful, yet lightweight, tech stack:

  • Python: The backbone of the entire application.
  • Flask: A lightweight web framework, perfect for creating the API endpoint and the minimalist web dashboard interface.
  • YOLOv8 (You Only Look Once): This is where the CV magic happens. I’m using two YOLOv8 models:
    • One for general primary object detection (yolov8n.pt).
    • A separate, custom-trained model for classifying the niche, secondary object class (custom\_class.pt). This dual-model approach was a great learning exercise in pipeline orchestration.
  • OpenCV: For handling the video and image processing tasks.
  • Requests: To programmatically manage the dependency chain, specifically for downloading the custom model if it’s not present locally.

Overcoming Initial Hurdles: The “ImportError” Saga

Every developer knows the thrill (and occasional pain!) of debugging. One of my biggest initial challenges was an annoying ImportError that kept crashing my application locally. It looked something like: cannot import name 'InferencePipeline' from partially initialized module 'ml_model'.

This meant my ml_model.py file, which contains all the AI logic, wasn’t fully ready when app.py tried to call its main class. After some digging, it turned out to be related to how the model weights were being loaded, especially the custom_class.pt file, before the main application logic initialized.

I implemented more robust loading logic, including automatic downloading of custom_class.pt using the requests library if it wasn’t found locally. This also meant making sure requests was properly installed in my Python virtual environment.

The good news? I’ve conquered that ImportError! My local Flask application is now fully functional, serving the dashboard and ready to process images. You can see it running happily on http://127.0.0.1:5000 on my machine!

The Deployment Dream: Heroku and The Unexpected Roadblock

With the local app running smoothly, the next logical step was deployment. I chose Heroku because it’s a fantastic cloud platform for quickly getting Python applications online.

The plan was simple: set up the Heroku CLI, create an app, and push my code.

  • The Heroku CLI installed perfectly after a few initial hiccups (related to system PATH variables – another common developer rite of passage!). I can confirm the CLI is working as expected.
  • I also made sure all my latest code, including the fixed model loading and the updated requirements.txt (which tells Heroku what Python packages to install), is safely pushed to my GitHub repository: https://github.com/Junaid1991-maker/YOLOv8-Flask-Deployment-Demo.

However, I’ve hit an unexpected roadblock with Heroku itself. To create an application on Heroku, they require account verification by adding payment information. Even for the free tier, this step is mandatory to prevent abuse of their services.

Unfortunately, my current debit cards are either expired or experiencing activation issues with my bank. This means I’m currently unable to complete Heroku’s verification process.

What’s Next? Patience and a Bank Visit!

While the deployment is temporarily on hold, my focus now shifts to resolving the card issue with my bank. Once I have a valid, active card, I’ll be back to complete the Heroku verification and get this Real-Time Classification API live for everyone to see!

Stay tuned for more updates on the deployment and live demo!


Discover more from Junaid Iqbal | Agentic AI Engineer

Subscribe to get the latest posts sent to your email.

Leave a comment