Flagship project · Computer vision

Railway Vision

How I built a pantograph and overhead-line detector, from the first plan in December 2025 to two trained models in June 2026, including the detours that didn't make it.

0frames labelled and reviewed
0labelled boxes
0Indian routes
0shapes reviewed in CVAT

The goal

Measure height from a detection

A camera in the cab looks up at the pantograph and the overhead line. If a model finds the pantograph, masts, arms and contact points reliably, the height of those elements can be measured from the detection.

Why plain boxes

For that measurement the top edge of a box has to stay parallel to the bottom of the frame. I tried rotated boxes, then dropped them: they cost much more labelling effort and gave nothing back for the measurement.

The timeline

Reconstructed from file dates, version history and training logs. Click any screenshot to enlarge it.

Nov 2025 to Jul 2026 at a glance

From a proof of concept to two trained detectors.

Nov – Dec 2025

Proof of concept and a big plan

I used a public Roboflow contact-point dataset to check that contact points could be detected in video at all. None of those images are in my dataset.

The first plan was ambitious: a custom attention network with depth input, and a stack of measurements on top. It was the starting point, not the destination.

Synthetic depth capture in Isaac Sim
Synthetic stereo-depth scene in Isaac Sim, 1280 x 720.
Dec 2025 – Apr 2026

Depth exploration

I tried stereo and monocular depth (a ZED 2i camera, Isaac Sim synthetic scenes, Depth Anything) to see whether annotation and measurement could be automated. A real-time detection and measurement system was built and run on trains in Lucknow; the code isn't published, but here is where it ran.

The depth work didn't end up in the final labelling method, but it taught me what the camera could and couldn't resolve.

ZED depth viewer showing live depth and a point cloud
ZED 2i live depth and point cloud (camera view blurred for privacy).
TensorRT benchmark result of about 55 frames per second
A TensorRT engine for one of the models: about 55 FPS, 18 ms per frame.
May 2026

Measuring wire height with depth

With the ZED mounted in Lucknow, I compared two ways of getting depth: the camera's own, and Fast-FoundationStereo, with a detector finding the wires in each frame. The overlay shows each tracked wire segment, its height from both sources, and the gaps where wires cross.

A detection with a depth reading, pantograph at 0.93 confidence, is the end of that chain.

Wire height overlay comparing ZED depth with Fast-FoundationStereo
Wire height from ZED depth vs Fast-FoundationStereo, with crossover gaps.
Pantograph detected at 0.93 with a depth reading
Pantograph 0.93, contact point 0.35, depth 3.85 m.
May 2026

The rotated-box detour

I tried oriented boxes, including a depth-assisted script that proposed rotated pantograph boxes, which I calibrated against my own corrections. It matched my edits well, but I decided rotation wasn't needed and went back to plain boxes.

Knowing when to drop an idea saved weeks of labelling.

Rotated box candidates over a pantograph in CVAT
Rotated-box candidates in CVAT: the approach I dropped.
May – Jun 2026

The labelling campaign

A cheaper method won: a small pretrained detector pre-annotates, tracking carries boxes between frames, and I review every frame by hand in CVAT. 31 tasks covered all 23,551 frames from five routes.

Footage came from four of the five routes in this folder of raw videos, and the model-assisted tools sped up each pass without replacing the review.

Folder of raw source videos by route
Raw source videos, by route.
CVAT automatic annotation dialog mapping model labels
Model-assisted pre-annotation in CVAT.
10 – 23 Jun 2026

Training, and the NaN scare

I built the YOLO dataset on 10 June and the RF-DETR set on 12 June from the same labels, then trained. The first YOLO epochs went to NaN loss; Ultralytics logged "recovering from last.pt" and I resumed the run. At about 57 minutes an epoch, 200 epochs took roughly 8 days.

RF-DETR Large trained on a rented H100 in about 19 hours, finishing 30 June.

YOLO training log with NaN loss warnings and recovery
YOLO26x early epochs: NaN losses and automatic recovery.
In the field

Where it ran

The system was built for a moving train, so every recording has a place as well as a picture.

0of line in this logged run
0GPS fixes
Gonda ↔ Bahraichthe stretch shown
  1. Record togetherA field recorder captures camera video, depth and a GPS log in one session, with a manifest that keeps them in step.
  2. Match to the mastsA GPS file of mast positions lets an alert say where it happened: the alert table records the mast name and latitude.
  3. Measure and flagDetections feed measurements checked by category, with alert tabs for stagger, height, setting distance, gradient and double contact. That is why box geometry matters so much.
The operator screen with settings, a live video panel and alert tabs
The operator view, from a test session at a depot (GPS not connected in this capture, about 5 FPS): detector threshold, train and pantograph heights, mast direction, per-measurement corrections and the alert tabs.
A logged run on the Gonda–Bahraich line, replayed from its GPS fixes. The glowing marker travels the logged route; it is an illustration, not live data. Hold Ctrl and scroll to zoom.
In the field

Built to ride a train

A detector only matters if the cameras stay put on a moving locomotive, so I built the mount too. Open a chapter to follow it.

  1. The problem

    The detector runs on a webcam, but I was also testing a ZED 2i stereo camera as its possible replacement. Both had to see the same line from the same place, so they needed to sit side by side on the locomotive and stay put.

    ZED 2i mounting and connection (datasheet)
    Thread mount1/4"-20 UNC
    Bottom2x M3 threads
    Back4x M3 threads
    Other mounts4x M2 thread mounts
    ConnectorUSB 3.0 Type-C, dual locking screws
    PowerUSB 5 V, 380 mA
    Test fit: the ZED 2i beside the webcam, taped to a bench.
    Test fit: the ZED 2i beside the webcam, taped to a bench.
  2. The design

    I modelled the bracket in CAD: a base plate with hinge blocks, and a cradle that holds the camera body on a hinge so its angle can be adjusted. The red sketches mark what to change on each revision.

    Printed trial parts and CAD views of the hinged cradle, with my notes sketched on them.
    Printed trial parts and CAD views of the hinged cradle, with my notes sketched on them.
    The hinge-block part in the slicer.
    The hinge-block part in the slicer.
  3. The prints

    Every revision was printed and tried against the camera before the next one. These are the first prints: hinge blocks on a base plate.

    Two black 3D-printed hinge parts.
    Two black 3D-printed hinge parts.
  4. The tool shop

    The metal parts, screws and a threaded rod, were made at a tool shop in Lucknow. My dad came along to help with the hardware side, and the owner of the shop did the turning.

    The tool shop in Lucknow where the parts were turned, with my dad and the shop owner.
    The tool shop in Lucknow where the parts were turned, with my dad and the shop owner.
    The turned rod with its nuts.
    The turned rod with its nuts.
  5. The fit

    Back at the bench, the machined screws went into the ZED's mounting holes.

    Machined screws in the ZED's mounting holes, with its USB-C port beside them.
    Machined screws in the ZED's mounting holes, with its USB-C port beside them.
    The top plate and its threaded socket, with one of the people who helped make the mount.
    The top plate and its threaded socket, with one of the people who helped make the mount.

Watch it work

More recordings of the models and the depth experiments. Videos load from YouTube when you press play.

Data work Model tests and depth experiments

Testing RF-DETR

An early test of the trained RF-DETR model on video.

Testing RF-DETR, take two

A second test run of the RF-DETR model.

Depth on thin wires

Measuring wire-to-camera distance with the ZED, with CREStereo running in place of the ZED's own NEURAL PLUS mode to see if the depth map holds steadier on thin wires.

All the models at once

The wire model and the four-class detector running together. Wires were segmented with SAM3 to train a model that segments any wire it sees. ZED depth is poor on thin wires, so wherever triangulation gets a good distance at any point along a wire, that height is assigned to the whole wire.

Tree canopy clearance

A separate project: segmenting tree canopy and measuring how close it comes to the pantograph cluster, since it has to stay a set distance from the line.

Data work

By the numbers

Live charts drawn from the real label files and training logs. Hover or tap a bar for exact values.

Frames per route

Train and validation: 23,551 in all.

  • Purple is train: the frames the model learns from.
  • Blue is validation: frames held back to check it.
  • Each bar is one source. ZED is the stereo camera, filmed in Lucknow.
65.6%of all frames come from two routes, Ahmedabad and Lucknow
14.8%were held out for validation: 3,492 of 23,551
5 + 1five routes, plus the ZED camera
Where the frames come fromA longer webcam recording from a production run.

133,245 labelled boxes

Four classes; every box is a plain rectangle.

  • Each bar is one class. The solid part is training boxes, the paler part is validation.
  • A box is a plain rectangle drawn around the object.
38,386masts, the most of any class
25,398arms, the fewest
14.0%of boxes sit in validation: 18,663
A labelled frame from Mumbai with pantograph, mast, arm and contact point boxes
What a labelled frame looks likeEach coloured rectangle is one of the 133,245 boxes.

Boxes per frame

How many labelled boxes a frame holds (15 means 15 or more).

  • Each bar counts the frames that hold that many boxes.
  • The last bar, 15+, means 15 or more.
8 boxesis the most common count: 3,183 frames
4 boxescomes next: 3,033 frames
1,072frames hold 15 boxes or more
A crowded frame with many labelled boxes
A crowded frame, Mumbai: every rectangle is one box.
The detector on the lineThe trained model running on the first trial run, from the webcam's point of view.

Two kinds of camera

A standard webcam, plus a ZED stereo camera tested as its replacement.

  • Purple is the webcam the system was built around.
  • Orange is the ZED stereo camera, tested as its possible replacement.
94.4%webcam frames: 22,241
5.6%ZED frames: 1,310, all filmed in Lucknow
2 viewsthe ZED's field of view differs, so the model has to learn it first
The left and right ZED views of the same scene
What the ZED recordsA left and a right view of the same scene, the input to stereo depth.

Why contact points are hard

Width against height of every box, as a share of the frame. Contact points are tiny: a few pixels of offset costs most of their overlap score. Open it to nudge a box and watch the overlap fall.

Where things appear in the frame

Density of box centres. Pantographs cluster on the centre line, contact points sit along it just above, masts spread out to the sides and arms sit lower. Open it to watch the dots turn into this map.

Data work

How the labels were made

Six steps, repeated task by task. Press any step to see the evidence.

The labelling screen, recorded on 29 May 2026.

How the labelling was run

CVAT ran on my own PC and was reachable both locally and from off-site through an ngrok tunnel.

CVAT on my PC reaches a labeller seat and a reviewer seat through an ngrok tunnel; I switched between the two seats My PCCVAT in Docker ngrok Labellerdraws the boxes Reviewerfollows behind,fixes mistakes swapped seats
  • 31 tasks of about 500 frames, taken one at a time.
  • Two seats on every task: a labeller, and a reviewer who follows behind correcting mistakes.
  • One person as admin and host, switching between the two seats.

The model proposes, I decide

A small pretrained detector draws a first box. It is a starting point: reviewing means fixing it.

An automatic pantograph proposal that is too tall
The proposal: the box runs too tall.
A manually corrected pantograph box
After review: a tight box on the pantograph.

How the data was split

Every bar is drawn to the same scale, so a ribbon is as wide as the number of images it carries. Both models trained on the same 29,380 images and were checked on different cuts of the rest.

  • Reviewed frames
  • Mast-focused set
  • Train
  • Validation
  • Test

The mast-focused set (11,022 images, annotated separately) joined at training time. RF-DETR's validation and test sets are one held-out pool cut in two by image, so they share video segments. YOLO26x's run counted 5,114 validation images, 79 fewer than the 5,193 held out.

Data work

Models and results

Validation scores per class (AP@50:95). Two models, two validation sets: read them side by side, not as a leaderboard.

YOLO26x

0.902
0.790
0.714
0.386

Overall mAP@50:95 0.698 on 5,114 validation images. 1280 px, about 8 days on one RTX 4070 Ti.

RF-DETR Large

0.923
0.704
0.686
0.389

Overall mAP@50:95 0.679 on 3,941 validation images. 1120 px, about 19 hours on one H100.

YOLO26x: 200 epochs

Validation mAP over the whole run; 1280 px, about 8 days.

RF-DETR Large: 35 epochs

Validation mAP (EMA weights); 1120 px, about 19 hours.

Per-class accuracy

AP@50:95 on each model's validation set.

Headline scores

Different validation sets, so not a ranking.

YOLO26x losses

Train and validation, box and class.

RF-DETR losses

Per-epoch training and validation loss.

What holds across both: the pantograph is detected well (about 0.90–0.92) and the contact point is the weak class (about 0.39) for both models. That points at the data (tiny boxes that are hard to place) more than at the model choice.

The full dataset (23,551 frames, 8.13 GB) is private and not available for download. The Kaggle write-up has sample frames, the full numbers, and the data-prep steps.