I first tested learned models in the cloud, scoring clips after the device had uploaded them. The held-out DSP results from Part 2 supplied a baseline, and the labelling design in Part 3 supported the comparison. I wanted to know both whether a model improved detection and whether it fitted the existing service.
Comparing image and audio representations
A siren is recognisable on a spectrogram as a diagonal sweep with parallel harmonic stripes. The harmonic-sum score in Part 2 looks for that structure algebraically. Another approach is to render each clip as a mel-spectrogram and classify the resulting image with a vision model.
ResNet-18 or EfficientNet-B0 with ImageNet pretraining would be convenient starting points, but audio pretraining offered a more direct connection to the task. YAMNet was trained on Google's AudioSet, whose classes include Siren, Emergency vehicle, Ambulance (siren), Police car (siren) and Fire engine (siren). That gave it prior exposure to the target sounds, unlike an ImageNet backbone's natural-image training.
YAMNet also supplied a zero-shot baseline through its own siren-class posteriors, requiring no training on this corpus. With only a few dozen labelled positives available then, that was worth comparing with the trained heads.
I compared three candidates using the same folds, labels and evaluator:
| Candidate | Backbone | Trained? |
|---|---|---|
| ImageNet CNN | ResNet-18 / EfficientNet-B0 on mel image | Head only |
| AudioSet embedding | YAMNet, frozen | Head only |
| AudioSet zero-shot | YAMNet siren-class posteriors | No training |
The fold design, and a bug the evaluator refused to hide
One siren pass can trigger several near-duplicate captures. A random clip-level split risks placing the same physical event in both training and test data, inflating scores even if the ranking still looks plausible. I grouped folds by day and capped the comparison at three folds. There were only nine labelled days, with between 1 and 27 positives per day, leaving too few positives for a useful five-fold test.
The evaluation code now refuses two folds because that configuration broke the nested validation procedure. The same DSP baseline scored 0.921 F1 at three folds and 0.480 at two. With two outer folds, the training side contained only one fold, leaving the inner loop no genuinely held-out data for choosing a threshold. It selected the threshold from effectively all-zero scores. The lower number reflected a broken evaluation path rather than a worse detector.
The container budget, decided before the bake-off ran
The model would have to share the lightweight Cloud Run container that handles device uploads. I had already removed scipy to keep that service small and responsive. Adding an audio or vision runtime would increase dependencies, and slow cold starts could cause upload timeouts.
Before scoring candidates, I fixed two limits: dependencies at or under 246 MB, approximately three times the shim's measured 82.1 MB baseline, and latency at or under 500 ms per clip. Dependency size was checked for each candidate during the comparison. Candidates that failed that gate did not need a latency measurement to rule them out.
Higher F1, but over the dependency budget
The shared evaluator scored all four candidates, including DSP, on the frozen day-grouped folds:
| Candidate | F1 mean ± sd | Deps (MB) | ms/clip | In budget? |
|---|---|---|---|---|
| dsp_v3 | 0.871 ± 0.033 | 82 | 2 | yes |
| yamnet_zeroshot | 0.934 ± 0.030 | 2084 | — | no |
| yamnet_embed | 0.965 ± 0.014 | 2230 | — | no |
| melimage (ResNet) | 0.959 ± 0.014 | 5005 | 73 | no |
All three model candidates beat DSP on F1, scoring 0.93 to 0.97 against 0.87. The ResNet result supported using spectrogram images for this task, while the YAMNet variants also performed well. However, their dependencies were 8 to 20 times the 246 MB cap. I did not measure latency for the two YAMNet variants because they had already failed the dependency gate.
DSP remained the cloud choice because it fitted the service, despite its lower F1. The model candidates showed a measured detection advantage, but none met the deployment requirements set for this container.
Include the service constraints in the comparison
Checking deployment cost alongside detection performance avoided choosing a model that would then require a different hosting arrangement. These results ruled out the tested candidates for this service; they did not rule out a smaller model or a different deployment design.
One caveat, stated plainly
Each candidate uses its own architecture, so this comparison measures the practical package offered by each option. It does not isolate the cost of quantisation or platform while holding a model fixed.
What's next
For this version, no learned model shipped in the cloud tier. A smaller or more efficient embedding could reopen the decision. Part 5 instead tries inference on the device, where the constraints are flash measured in kilobytes and execution time on a microcontroller.