•
9 min read

Swift on Jetson, seven months later

Table of Contents

In April I wrote about running Swift on a Jetson. It was a proof of concept then. I kept working on it; now it's running 24/7 on a Jetson Orin Nano 8 GB, watching my motorcycle parked on the street.

There’s an iPhone app now too, where I review alerts, play clips and edit detection zones, which have some shared code across the Jetson (Linux) and the iPhone.

The basic arrangement is mostly the same: NVIDIA’s DeepStream stack decodes the video, runs inference and tracks objects. A C shim passes detection metadata to Swift. Swift manages the pipeline and checks whether the detections are usable. A separate Go service decides when to send an alert - this is part of dwellfsm a project I'll write about another time; the gist is it is a state machine to track interactions and emit events; removing the noise from frame to frame detections.

Most of the work since April has been dealing with failures.

Detect the right thing

My motorcycle usually sits under a black tarp. I wanted to be able to detect when the tarp is removed and the stock YOLO didn't have the ability to detect when it's covered / uncovered, and to be fair it is not too good at detecting a motorcycle at that angle. The covered motorcycle was detected as bins, bags, shadows, but not a covered motorcycle.

I fine-tuned YOLO26n to distinguish covered and uncovered motorcycles. Trained on a DGX Spark. Since I didn't want to do all the labeling myself - there were a lot of frames - I used a VLM on the Spark to filter those look-alikes, then spot checked / reviewed the labels in CVAT.

Training data set was small, whatever I could capture for both states and cover weather and lighting conditions. For this use, the result is good enough; for example, I didn't have enough data for rain and for fogged up window. Also the angles of the sunlight morning/evening had samples with a giant shadow that looks a lot like a motorcycle.

Driveway camera view with the covered motorcycle parked on the street, boxed by the fine-tuned detector as covered_motorcycle.

The same slice of the frame twice, side by side: the motorcycle under its tarp on the left, and uncovered on the right.

Nothing about the Swift integration needed to change. DeepStream runs the trained TensorRT engine, and Swift receives class IDs and boxes as before. The zone and presence checks now use the two motorcycle classes.

(Btw, The trained model isn’t included in the public repo.)

Camera is not fixed

The camera is indoors and isn’t screwed in place. It can move (my kids and cleaners knock it over all the time). The detection zones are polygons I draw over the image; I only do alerting and event description for what happens in the zones, since I don't want to alert on motorcycles that ride by on the street. So if the camera moves, the detector can keep finding perfectly reasonable matches while checking them against zones that are now in the wrong place - so no alerts.

For that I added a scene checker in Swift. Every five minutes it gets a small grayscale image from the pipeline and looks for a few landmarks saved when I drew the zones. It uses their positions to estimate how much the view has shifted, rotated or changed scale.

The camera view with the detection zones drawn as colored polygons and the five scene-check landmarks marked L1 to L5.

The 320×180 grayscale image the scene checker gets, enlarged so the pixels show, with each landmark's 16×16 template and its search window drawn on it.

For a small shift, it adjusts the detection coordinates back to the original view. For a larger change, it pauses zone-based alerts. If it can’t find enough landmarks - like when it's too dark, or the window fogs up, it marks the scene as uncertain rather than assuming the camera moved.

This has already caught several camera shifts and corrected them without me redrawing the zones, so the whole thing stayed pretty autonomous.

I wrote the checker directly in Swift because the input is tiny and it only runs every five minutes. It doesn’t need a GPU or OpenCV. The matching and state transitions can be tested without a camera or GStreamer, which makes them much easier to work on than the video pipeline itself.

I also added a replay tool that sends a recorded MP4 through the real inference path. Being able to replay something that went wrong is useful when the alternative is waiting for it to happen outside again.

Event descriptions

In April, the vision-language model was a verifier. It looked at a few frames and returned labels like “motorcycle covered” or “bin in the pickup zone.” It also called my covered motorcycle a bin - hence why I removed the bin detection for now and updated the model.

I have a separate service now that runs after an alert has fired and writes a short description of the event. The alert goes out first; it doesn't wait for the model. Since we have the clip, it's fine if we wait a few seconds for a description. Back in April the wait was in the tens of seconds.

The early descriptions weren't too accurate especially when it comes to the full unfolding of the event. When the bike left, the model made up an explanation for why it was gone, not describing what actually happened. Getting the smaller model down to about five seconds didn't fix that: it described five different events as the same generic walk-by.

The bigger improvement came from changing both the input and the model. Instead of full frames, I now send eight crops of the zone around the bike, spread across the event as a single video. Also thanks to TensorRT Edge-LLM, I moved from Qwen3.5-0.8B to the 4B model, quantized to INT4.

On my small test set of 39 cases, that setup got 38 right, with no walk-by mistaken for direct contact with the bike. That's a useful result for my camera and the events I've collected, not sure how well it would do in a different environment. On live alerts I've seen the descriptions be accurate (spot checked, see screenshot in the next section). I ask for one of three answers: none, ambiguous or direct. If the model is unsure, it gets another look with 16 frames.

Generating the descriptions now takes about 4.8 seconds now, compared to about 20 seconds for the verifier at the end of April. I'm really happy with this because it's on top of having a bigger model. The full wait for a description is still around 34 seconds at the median. Extracting frames from recordings was costing the detector frames, so the service waits until nobody is in front of the camera before doing that work. Most of the delay is now waiting and preparing the input.

New iOS App

I started the iOS app in August as a labeling tool. Correcting the system felt like operating an engineering dashboard, and I wanted to review an alert in a few taps, ideally in under ten seconds.

I also wanted a way to record events it missed. False alarms are easy to find in the inbox. Missed events don't appear there at all.

It grew into a SwiftUI app with three tabs: Events, Live and Zones. I can open an event, watch the clip, read the description, see why the alert fired and leave a quick review. Reviews are saved on the phone first and synced later, so a bad connection doesn't lose them.

Screenshot of the WatchfulEyeLabeler iPhone app.Screenshot of the WatchfulEyeLabeler iPhone app.Screenshot of the WatchfulEyeLabeler iPhone app.Screenshot of the WatchfulEyeLabeler iPhone app.

Live view lets me watch the camera with detection boxes over the video. I switched it from HLS to native WebRTC because the boxes were running ahead of the picture. Each video frame is now matched to the detector metadata for that frame.

In Zones, I can redraw the polygons with my finger and send them to the detector. This is where having both ends in Swift helped: the zone models and validation live in one small package, compiled by the iOS app and the Linux detector. If I change the format, both ends use the same types.

There are still some unfinished bits. The reviews don't feed training or evaluation yet, and tapping a notification still opens the web dashboard rather than the app. But reviewing an event is already much less work.

Seven months later

The Jetson is still running the detector, but there's a lot more around it now: a model that recognizes the covered bike, checks for camera movement, event descriptions and an app where I can review what happened.

Swift has been useful for the detector's application logic, and sharing the zone types with the phone is a nice bonus. Most of the work, though, has been figuring out what this particular camera needs to see and how to make its mistakes easy to review.

Next I want to shorten the wait for descriptions and put those reviews to use.

Repo: github.com/mihai-chiorean/deepstream-swift-detector. The April version is tagged april-2026.