← All cases

case() // engineering · code migration

Porting a YOLO v4 object-tracking library from Python to C#

The compute modules of an object detection and tracking library translated from Python to C# with unit-test parity against the original: video processing went from 10–20 to 40–50 FPS.

// brief

challenge

Python has a huge community and libraries for everything, but they often run slower than equivalents in compiled C-like languages. Translating code between languages is still hard, GPT models included, because every language has its own syntax and semantics.

goal

Rewrite the compute modules of an object detection and tracking library built on a pre-trained YOLO v4 network from Python to strictly typed C#, and test the hypothesis that such a translation is feasible.

approach

Analyse the source, find C# equivalents of the Python libraries used (NumSharp for NumPy), implement the missing classes and methods, translate the modules and verify them with unit tests against the Python output.

// key results

×3

video processing speed

40–50 FPS

from 10–20

4 weeks

end to end

100%

modules unit-tested

// what we did

Scope of work

01

Translating the library from Python to C#

A niche library written in Python ran too slowly, and no C# equivalent existed.

  • One-week research phase: source code analysis, main data types and a work plan.
  • NumSharp adopted as the NumPy equivalent; missing matrix classes, conversions and a 2D norm function added.
  • Detection, tracking and metric modules (IoU, nearest-neighbour distance) translated.
  • Kalman filter and the linear assignment solver translated.
  • Test sets built from the Python output; unit tests compare the two implementations.
metricbeforeafterΔ
Programming languagePythonC#
Frames per second10–2040–50×3
Unit testsnoyes

// business value

  • The same library runs about three times faster in C# than in Python.
  • A unit-tested C# codebase that the client team can keep developing.
  • The translated detection modules are reusable in other C# ML projects.

// stack

  • Python
  • C#
  • NumPy
  • NumSharp
  • YOLO v4
  • Kalman filter
  • Unit testing
  • Waterfall

Got an X?

Start with the free discovery. In a week you'll know where your Z is.

Start discovery