Back to previous page

Personal project

ConveyorEdge AI, Counting Nuts on a Conveyor with a Jetson Nano

Python · PyTorch · OpenCV · ONNX Runtime · TensorRT 5 and 8.2 · NVIDIA Jetson Nano · YOLOX · Kalman filter · FastAPI · Docker · Trivy · GitHub Actions · Bicep · Azure Container Apps · Claude API · December 2026

A conveyor that carries small parts needs a count, and a camera can supply it if software finds each part and follows it from frame to frame. ConveyorEdge AI detects, tracks, and counts nuts on a conveyor belt seen from above, and it is built to run on a Jetson Nano, a small NVIDIA board with an old software stack. I first measured it with TensorRT 5 on JetPack 4.2, and again with TensorRT 8.2 on JetPack 4.6.1 after I reflashed the board. The detector is a small convolutional network in the style of FOMO. It predicts a heatmap of nut centres and a sub-cell offset for each peak. A Kalman filter with Hungarian assignment links the detections into tracks, and a line counter adds one to the count when a track crosses a counting line. Around that core I built a synthetic data generator, an annotation tool, benchmark code, and the deployment files. I compared the pipeline on the Jetson Nano, on the CPU and the RTX 4050 GPU of a laptop, and on a cloud service in Azure.

The full project video (v5, December 2026). Its real-video numbers come from the 450 human-checked frames of one 15-second clip. Its Jetson Nano timings come from TensorRT 8.2 (TensorRT 5 where the video says so), median of 3 repetitions, on a 64-frame loop of a dense part of the same video with about 62 nuts per frame. Laptop timings are not Jetson timings. Real footage from piyushdubey490. (n.d.). Video Factory Conveyor [Dataset]. Kaggle. https://www.kaggle.com/datasets/piyushdubey490/video-factory-conveyor. Edge Impulse material, reused with credit: Edge Impulse. (2023). Training Models with Synthetic Data: End to End Conveyor Belt Counting Walkthrough with Edge Impulse [Video]. YouTube. https://www.youtube.com/watch?v=5IdWzaJNkk0. Edge Impulse public project 187740, https://studio.edgeimpulse.com/public/187740/latest. Edge Impulse, conveyor-counting-data-synthesis-demo (BSD-3-Clause-Clear), https://github.com/edgeimpulse/conveyor-counting-data-synthesis-demo. Music: original, synthesized for this video.

FOMO (Faster Objects, More Objects) is a detector for small devices that Edge Impulse announced in 2022. It drops the regression of bounding boxes. A MobileNetV2 trunk, truncated at an intermediate layer, gives an output grid at 1/8 of the input resolution, so a 96 by 96 input gives a 12 by 12 grid. A small head classifies every cell as an object class or as background. FOMO is trained with the centroids of the objects instead of boxes, and its custom loss weights the object cells 100 times more than the many background cells. A detection is a cell with a high score, which makes it much cheaper than a box detector. It assumes that the objects have a similar size, that they are spread over the grid and that no two centroids fall in the same cell. The facts in this section come from the Edge Impulse announcement, a company blog post that was not peer reviewed, and from the Edge Impulse documentation.

I call my detector CentroidNet. It keeps the central idea of FOMO, a small CNN that outputs a centroid heatmap with one value per grid cell and no boxes. Most of the rest differs, as the two drawings and the list below show. CentroidNet is a plain CNN trained from scratch, with only convolution, ReLU and max-pool layers, because TensorRT 5 has no importer for several other operators. I train it with a Gaussian peak at the cell of each nut as the target and the penalty-reduced focal loss from CenterNet, and the decoder applies the 3 by 3 non-maximum suppression from the same paper. It adds a sub-cell offset for each cell, so a detection is not tied to the cell centre, and the stride (4, 8 or 16), the width and the depth are settings. CentroidNet is inspired by FOMO and is a different model. I did not train or evaluate FOMO itself, so no result on this page is a FOMO result.

The original FOMO (first drawing) and CentroidNet (second drawing), drawn with the same frame and the same layout. Magenta blocks exist only in FOMO, teal blocks only in CentroidNet, and the grey feature map at 1/8 of the input is the same in both. In the outputs, FOMO marks the cell of each nut as a class, and CentroidNet draws a Gaussian heatmap with a sub-cell offset arrow at each peak. The FOMO drawing is generic, because the sources do not publish the channel counts of its truncated trunk. The CentroidNet drawing is the model cn_w025_d1_s8_i640_o1, which has stride 8. The frame is an illustrative schematic and not real data.

This is how the two models differ, row by row.

  • Feature extractor. FOMO uses a MobileNetV2 trunk truncated at an intermediate layer. CentroidNet uses a plain stack of 3 by 3 convolutions with BatchNorm and ReLU and max-pool layers, with random initialisation.
  • Output grid. FOMO outputs 1/8 of the input by default. CentroidNet outputs 1/s of the input, with s equal to 4, 8 or 16 according to the number of stages.
  • Values per cell. FOMO gives class probabilities, a class or background. CentroidNet gives one heatmap logit and two sub-cell offsets.
  • Training labels. FOMO uses object centroids with a class per cell. CentroidNet uses a Gaussian peak at the cell of each nut and offset targets.
  • Loss. FOMO uses a custom loss that keeps the locality of the last layer and weights the object cells 100 times. CentroidNet uses the penalty-reduced focal loss plus an L1 loss on the offsets.
  • Position of a detection. In FOMO it is the cell. In CentroidNet it is the cell centre plus the offset.
  • Post-processing. FOMO applies a threshold to the cell scores. CentroidNet applies a sigmoid, a 3 by 3 local-maximum suppression, a threshold, the offsets and the resize, in numpy outside the network graph.

The nut video suits this kind of output. The nuts are about 18 px across and look the same size, because the camera is fixed and looks down on the belt, and counting needs one point for each nut. The hard case is two nuts that touch. Their centres are about 18 px apart, which is 4.5 cells at an effective stride of 4 px, 2.25 cells at 8 px and about 1.1 cells at 16 px. The 3 by 3 suppression keeps two peaks only when their cells are at least 2 apart in a row or a column, so at 16 px a touching pair tends to merge into one detection. On the synthetic test split the F1 is between 0.857 and 0.865 at an effective stride of 16 px, against 0.993 to 0.995 at 8 px, and the loss is in recall.

The first drawing shows the premises of FOMO as situations. Green panels on the left are where it works best and red panels on the right fall outside the premises. The last red panel is a structural limit, because a cell holds one prediction. The second drawing is the same scene on grids with an effective stride of 4, 8 and 16 px, drawn to scale with nuts 18 px across. Green squares are the cells that hold a nut centre, and the red box marks the touching pair that falls into adjacent cells at 16 px. Both drawings are illustrative schematics and not data.

I trained on synthetic images only. The generator cuts three photographs of one nut into sprites and pastes them at random positions, rotations and sizes on empty belt backgrounds, with soft shadows, motion blur and noise. The label of each nut is the centre of its hole. It is carried through the same transform as the sprite, so it is exact by construction. The backgrounds are medians of frames of a real conveyor video, and I kept the first 450 frames of that video out of everything that touches training, so they can serve as a real test. There are 2,000 training, 400 validation and 400 test images of 640 by 352 pixels, and each split has its own backgrounds. The generator is an OpenCV port of an Edge Impulse notebook, with a mask for each sprite and an exact overlap test.

Sixteen synthetic training images of a blue conveyor belt with scattered nuts of different sizes and rotations, each marked at its centre, with one image showing an empty belt
Sixteen synthetic training images with the labelled centres marked (green for a nut with a visible hole, orange for a nut lying on its side). The backgrounds are medians of frames of the video cited here. piyushdubey490. (n.d.). Video Factory Conveyor [Dataset]. Kaggle. https://www.kaggle.com/datasets/piyushdubey490/video-factory-conveyor

Instead of one network I trained a family of 29 CentroidNets. They are plain convolutional networks with a centre-heatmap head and an offset head, from about 1.6 thousand to 294 thousand parameters. The sweep varies the width, the depth (1 or 2 convolutions per stage), the output stride (4, 8 or 16) and the input size (640 by 352 or half of it), and it includes an ablation without the offset head. I kept the graph to convolution, ReLU and max pooling, with BatchNorm folded into the convolutions, so that TensorRT 5 can parse it. As baselines I added YOLOX nano and tiny, which start from COCO weights and are fine-tuned on the same synthetic images, and a classical OpenCV detector.

I benchmarked every model on a laptop (an RTX 4050 GPU and a Core i9 CPU, through PyTorch, ONNX Runtime, and TensorRT) and on the Jetson Nano (TensorRT 5 on JetPack 4.2, in FP32 and FP16). Each configuration runs three times in separate processes, interleaved so that slow drift of the machine does not favour one of them, and I report the median of the runs with the P50, P95, and P99 latency of each stage: preprocessing, copies, inference, decoding, and tracking. The timed loop is frames 900 to 963 of the video, a dense stretch with about 62 nuts per frame. On the laptop, TensorRT in FP16 was the fastest backend, with inference between 0.04 and 0.8 ms across the models. For the smallest network a whole frame took 4.9 ms on the laptop GPU, of which the network was 0.04 ms, and 9.4 ms with ONNX Runtime on the laptop CPU. After I reflashed the Jetson to JetPack 4.6.1, all 62 engines (31 models in FP32 and FP16) built with TensorRT 8.2. In the nine pairs that both versions timed with the same tool, trtexec, the GPU time with TensorRT 8.2 was about 15 % shorter in the median, with the whole software stack changed and not only TensorRT. I compared the models on Pareto fronts of accuracy against latency. The detection and tracking metrics (F1, IDF1, MOTA) are implemented in the project and checked against the motmetrics library in the tests.

Inference time per frame of the smallest network on the laptop on a log scale, one row per backend: PyTorch CPU, ONNX Runtime CPU, PyTorch CUDA in FP32 and FP16, ONNX Runtime CUDA, and TensorRT in FP32 and FP16, with the CPU rows in blue and the GPU rows in orange and the GPU rows far to the left
Inference time per frame of the smallest network (cn_w025_d1_s4_i320_o1) on the laptop, one row per backend, on a log scale. The dot is the median, the bar spans P25 to P75, the line P5 to P99 and the cross marks the maximum. The labels give the median and the P99 in ms. Blue is CPU and orange is GPU.

On the Jetson Nano the pipeline was much slower than its parts suggested, so I went looking for the reason in logged data. With TensorRT 5, a frame of the smallest network took 113 ms at the median. The network itself, run back to back, needed 2.4 ms of that, and the original tracker, written in Python, took 86 ms. These timings come from the dense loop with about 62 nuts per frame. With 16 nuts per frame, which is typical of the annotated clip, the same tracker took about 11 ms when I timed it alone on the Jetson CPU. Every run records the GPU clock (read from sysfs every 100 ms), the power mode, and the time of each stage, and the logs show two bottlenecks. The first is GPU frequency scaling (DVFS). The GPU clock drops toward its 76.8 MHz floor while the CPU decodes and tracks, and the next inference starts at a low clock. Across 62 configurations, inference inside the pipeline was 1.2 to 10.2 times slower than the same engine run back to back, and 3.6 times slower in the median. The second is the tracker, which runs on the Jetson's Cortex-A57 cores. In those 62 configurations it took a median of about 63 % of the time per frame (31 to 98 ms). I have not tested jetson_clocks, which pins the clock at its maximum, so I do not claim that the frequency scaling is fixed. On this board the bottleneck was the code around the model, not the model.

I rewrote the tracker twice, both times with the same algorithm and identical outputs. The first version builds the distance table in one numpy expression, splits the assignment into small groups of nearby tracks and detections, and caches the Kalman matrices. Timed alone on the Jetson CPU at 65 detections per frame, its median fell from 92 to 13 ms. Inside the full pipeline, re-measured with TensorRT 8.2, the tracker stage went from 86 to 15 ms. The rest of the software changed at the same time, so I credit the tracker only with its own stage. The second version changes how the tracks are stored. The first version still kept one Python object per track, with its own position, velocity, and covariance (an array of structures, AoS); the second keeps one array per quantity for all the tracks (a structure of arrays, SoA), so the Kalman steps take the same few numpy calls per frame whatever the number of tracks. I measured it on the Jetson with TensorRT 8.2, together with smaller changes to the preprocessing, the copies, and the decoding, in 120 runs (4 models, 10 variants, 3 repetitions). All 120 gave the same detections, tracks, and counts as the baseline. The tracker stage fell from 15 to 16 ms to about 3 ms for three of the four models and to 3.9 ms for the fourth. The stage runs only on the CPU, so this number does not depend on the GPU clock. With all the changes and no overlap of CPU and GPU work, a frame went from 31.9 to 14.1 ms for the second-smallest CentroidNet, from 50.9 to 36.9 ms for the largest, and from 59.7 to 36.0 ms for YOLOX nano. For the smallest it went from 30.0 to 17.3 ms, with the GPU at 154 MHz; in one baseline run the GPU sat at 77 MHz and the frame took 41.5 ms. Part of the gain of the two small models is DVFS again, because with less CPU work between inferences the GPU clock stays higher. Overlapping CPU and GPU work brings the two small models to 6.3 ms per frame, but that is the period of the loop and not the time from a frame to its answer, so I do not report it as latency.

To see how far the synthetic training transfers, I scored all the models on real video. I checked the nut positions by hand in 450 frames (about 15 seconds) of one conveyor video: 7,519 positions of 52 nuts, with 32 crossings of the counting line. I did it in a small local annotation page that I built instead of using CVAT. To keep the networks under test out of the ground truth, a classical detector pre-annotated the positions, and I reviewed every frame. When I added a point by hand, a tracker only proposed which of my own nut IDs it belonged to, other models could only flag a place to look, and no model's position or ID was ever copied. In a leave-one-out check on frames 0 to 122 the tracker proposed the right ID for 1,933 of 1,933 points. The ground truth is still biased toward the classical detector.

The F1 values in this paragraph were computed on the laptop (PyTorch, FP32). The highest F1 is 0.995 (95 % interval 0.993 to 0.997), from cn_w100_d1_s8_i640_o1, and the intervals of the top models overlap, so I do not rank them. 22 of the 31 networks score above the classical detector, although the ground truth favours it. In the paired tests between the six models that existed before any ground truth, no difference is significant after Holm correction. The model cn_w025_d1_s4_i320_o1, with about 1.6 thousand parameters, reaches an F1 of 0.989 (0.985 to 0.992) at 2.4 ms of steady-state inference on the Jetson with TensorRT 5 (the engine run back to back, without the clock drop above), and it is on the Pareto front of F1 against Jetson inference time. It also counts all 32 nuts. The model with the best F1 needs 12.8 ms. In an exploratory test, with models chosen after the results, the best model is 0.006 F1 ahead of the smallest one, and that gap is significant. On the Jetson with TensorRT 8.2, the FP16 and FP32 engines of 12 CentroidNets gave the same line count as the laptop in 24 of 24 prediction files, with an F1 within 0.0002 of the laptop's. Across 31 models, the median F1 on real frames is 0.009 lower than on the synthetic test split. All of this comes from one short clip, so it shows that the synthetic training transfers to this conveyor, not to conveyors in general.

Left, a close-up of frame 900 of the real conveyor video showing about 30 silver hexagonal nuts on a blue belt, some touching or stacked. Right, the same crop with a green circle and a red cross on each nut the smallest network detected, 25 in total
A crop of frame 900 of the real video, raw on the left and with the detections of the smallest network (cn_w025_d1_s4_i320_o1) on the right. It returns 25 detections where the three larger CentroidNets I compared return 29 each, and it misses some stacked and tilted nuts. Frame 900 is outside the 450 annotated frames, so this is a visual check only. piyushdubey490. (n.d.). Video Factory Conveyor [Dataset]. Kaggle. https://www.kaggle.com/datasets/piyushdubey490/video-factory-conveyor

The real video has one blue belt, and the training backgrounds came from it. To test other colours, I recoloured or textured the belt in the same 450 frames, nine sets in all. I also trained eight architectures again on the same synthetic nut layouts with recoloured and textured belts (15 % original, 25 % blue shades, 25 % green or red, and 35 % textures). On the red version of the clip, the mean F1 of the eight rose from 0.433 to 0.985 with the first training seed. With three training seeds per side, the augmented models stayed between 0.974 and 0.994 on red in all 24 runs, while the originals spanned 0.000 to 0.913, so the result does not rest on a lucky seed. On the unmodified video the effect is small and depends on the architecture and the seed. The mean F1 went from 0.989 to 0.991 with the first seed, and over three seeds the change was positive every time for four architectures and negative every time for one. Red and green belts were part of the augmented training, and every recoloured set is the same footage, so this shows robustness to the belt colour on this conveyor and nothing about other conveyors.

As a reference that needs no training, I sent the same 450 frames to three Claude models (Opus, Sonnet, and Haiku 5.5) through the batch API, with a fixed prompt that asks for the nut centres. Opus reached an F1 of 0.9958 (0.9937 to 0.9976), statistically level with the best CentroidNet, and the three models together cost 2.39 USD for the 450 frames. It is a detection-only result: Claude answers one frame at a time without identities, so tracking and counting do not apply, and it runs in the cloud, not on the edge device.

The inference service (FastAPI with ONNX Runtime) runs in a CPU Docker image that I built, ran, and scanned. Trivy reports no critical findings, and on the laptop the container adds about 0.4 ms (9 %) to the median request time of the native service. GitHub Actions workflows run the linter, the tests, and a check that the edge code still runs on the Jetson's Python 3.6. The infrastructure is written in Bicep, and the deployment workflow is written for an OIDC login from GitHub Actions with no stored secret, a login I have not set up yet, so I deployed from my laptop with the Azure CLI. I used it to deploy the service on Azure Container Apps for one measurement session, with a 640 px CentroidNet on ONNX Runtime and half a CPU core, and I deleted the whole resource group afterwards. Over a home Wi-Fi network, a 33 KB JPEG sent to the service took 73.5 ms end to end at the median from the laptop and 80.5 ms from the Jetson, over three repetitions each. About 86 % of that time was the network, and the server needed 10 to 11 ms. On the board itself, detection with the same model took about 40 ms with TensorRT 5 (a sum of stage medians), so for detection alone the Jetson was about twice as fast as the round trip to Azure from this network.

These are the limits I know about.

  • The real-video results come from 450 frames (about 15 seconds) of one video. A classical detector pre-annotated the ground truth, which favours it in any comparison with the networks.
  • Only 32 nuts cross the counting line in those frames, so the counting results come from one short clip.
  • The Jetson timings come from a 64-frame loop of a dense stretch of the video, with about 62 nuts per frame and the GPU clock left to its default scaling. The two small models landed in different clock states from run to run, so their end-to-end times are one sample of a spread.
  • I have not tested jetson_clocks, so I have not shown that removing the frequency scaling removes the slowdown.
  • I did not measure the time from a frame to its answer with CPU and GPU work overlapped. The Azure figures come from one session over one home Wi-Fi network.
  • The other belt colours are recoloured copies of the same clip, not other conveyors.
  • The generator uses three photographs of one nut and never renders stacked nuts. In a visual check on real frames, stacked and tilted nuts are where the smaller networks miss detections.
  • Coding agents helped build the project under my direction, as the logbook records.