Month 3 Box - AI Deep Dive

Lesson 2: Exploring the AI HAT+ and Its Capabilities

Exploring the AI HAT+ and Its Capabilities

This is where the AI HAT+ earns its keep. You will run real object detection on sample images and video, entirely on the Pi with no cloud, using two industry libraries: YOLO for a fast, easy interface and TensorFlow Lite for a more hands-on approach you will later use to train your own model. Along the way you will learn virtual environments, which keep each project's dependencies clean. The camera comes next lesson; today is about seeing the AI work on saved media.

Why run AI locally

When you talk to a cloud service, your request travels to a company's servers, is processed on massive GPU farms, and the answer comes back. Running on the edge means the AI runs right on your Pi instead. The AI HAT+ provides about 13 TOPS, enough for object detection, image classification, and pose recognition in real time without any cloud. The advantages are concrete: no internet dependency, so it works in the woods or at sea; strong privacy, because no data leaves the device; and lower latency, which matters for cameras, voice assistants, and robotics. Be realistic, though: a local model on 13 TOPS is more limited than a multi-billion-dollar cloud model, but it can still do genuinely useful work.

Virtual environments keep projects clean

Different projects often need different, sometimes conflicting, versions of the same library. A virtual environment is a private, isolated space for one project: you create it, activate it, and any library you install goes only there, not system-wide. This prevents one project's dependencies from breaking another's. In this month you will create a virtual environment per project, activate it, then install and run inside it. It is a professional habit that saves enormous frustration.

Pre-trained models and how detection works

You will not train anything today; you will use pre-trained models, ready-made networks that already know how to recognize common objects. You feed one an image and it returns a list of detections, each with a label (bus, person, car) and a confidence score, plus a box showing where it saw the object. A confidence of 94 percent for bus means the model is quite sure. A threshold lets you ignore weak guesses, for example only accepting detections above 50 percent.

YOLO versus TensorFlow Lite

You run the same task two ways. YOLO (you will use version 11) is a very simple, highly optimized interface that is excellent on edge devices; a couple of commands and you have accurate detections. TensorFlow Lite is the lightweight version of TensorFlow, a library heavily used in academia and industry; it involves more Python code but gives you deeper control, and it is what you will use later to train your own model. Seeing both shows the trade-off between an easy turnkey tool and a flexible, professional framework.

Video is just a sequence of images

Detecting objects in a video is the same as detecting them in an image, repeated. A video is a stream of frames, so a 10-second clip at 30 frames per second is about 300 images. The program loops over the frames, runs detection on each, and writes the annotated frames back out as a new video. This is why performance, frames per second, matters so much on the edge: the faster each frame is processed, the closer to real time you get. Sometimes a model that is 70 percent accurate but twice as fast is the better choice on limited hardware.

Working through it

Install the dependencies. Run the provided setup script (from craftingtable.com/downloads) to install the AI libraries automatically. If a script is not executable, mark it executable first, then run it.

Create and activate a virtual environment. Make a per-project virtual environment and activate it so installs stay local. You will see the environment's name appear in your terminal prompt when it is active.

Run YOLO on a sample image. Run the YOLO detection on the provided sample; it downloads a test image, detects objects, and saves the annotated result under runs/detect/predict with labels and confidence scores.

Run YOLO on your own image or a video. Point the detector at a custom image or a video clip. For video it loops over every frame and writes an annotated output video.

Repeat with TensorFlow Lite. Install its dependencies, activate its environment, and run the TFLite object detection with MobileNet on the same media, passing arguments like the model, input, and confidence threshold. Compare its output and speed to YOLO's.

Confirm the accelerator is active. Use htop or the system monitor to verify the AI accelerator is actually being used; if it is not active, you lose the performance the HAT+ provides.

Set up a virtual environment