Manuscript Offprint

arXiv:2608.30727

RailGen: Improving Railway Intrusion Detection via Agent-Guided Small-Scale Foreign Object Generation

Quan Hao, Ziyang Tao, Chenxi Zhang, Yudong Wang, Rui Shi, Liguo Zhang

Quan Hao, Ziyang Tao, Chenxi Zhang, Yudong Wang, Rui Shi and Liguo Zhang, Senior Member, IEEE

Abstract—Small-object detection under long-tailed data distributions is a fundamental yet challenging problem in multimedia. Railway Foreign Object Detection (RFOD) epitomizes this challenge with easily confused small intrusions and scarce samples. To address these issues, we propose a generative-augmented detection paradigm that leverages multimodal image generation to enrich the feature space of rare, small objects. We first construct RailGen, a multimodal image generation agent based on large models. Under semantic constraints, RailGen automatically invokes tools to generate railway scenes, calibrate intrusion positions, extract foreign objects, and fuse them into realistic intrusion effects. This process produces high-quality synthetic samples that effectively densify the feature representations of tail classes and complete the small-object feature space. Within this paradigm, we further propose FocalDEIM, a detection framework designed to enhance training with generated data. FocalDEIM improves dense matching with Focal Modulation for better small object discrimination and adopts Focal Loss to emphasize hard samples, thereby alleviating blurred inter-class boundaries in complex railway scenes. Experimental results demonstrate that RailGen can generate high-quality small-scale foreign objects, reducing the object pixel area by up to 58×58\times and by 13.85×13.85\times on average. Equipped with these challenging samples, our paradigm surpasses the baseline DEIM by 5.6% and 7.5% in mAP50mAP_{50} and mAP50−95mAP_{50-95} respectively, and outperforms existing state-of-the-art methods. Ablation studies verify RailGen's feature-space enrichment and FocalDEIM's boundary discrimination. The paradigm provides an effective multimodal generative solution for long-tailed small-object detection in safety-critical applications.

Index Terms—Multimodal agent, image generation, railway foreign object detection

I. INTRODUCTION

S MALL-OBJECT detection under long-tailed data distributions is a fundamental yet challenging problem in multimedia, where rare categories with tiny object scales typically suffer from under-represented feature spaces and poor discrimination. Railway Foreign Object Detection (RFOD) epitomizes this challenge. In high-speed railway operation, even small artificial or natural objects, such as balloons, plastic films, stones, or tree branches, intruding at critical positions of the overhead contact line and rail tracks can cause serious accidents including facility damage, train derailment, and emergency stops. Accurate detection of such foreign objects is therefore essential for safe and stable high-speed railway operation [1].

However, high-speed railway operating environment is complicated. Lighting conditions change constantly, track textures are highly repetitive, and overhead line backgrounds easily cause visual confusion. These factors make it difficult for detection models to distinguish small-sized foreign objects from the background, hence degrading detection performance [2]. Furthermore, real intrusion events are difficult to capture in practice. Existing datasets exhibit severe long-tail distributions, where normal scene samples vastly outnumber foreign object samples. This imbalance leads to an incomplete feature space, preventing detection models from learning discriminative representations of rare intrusion patterns.

Currently, railway foreign object intrusion detection primarily relies on object detection algorithms [3], [4], [5]. In particular, DETR-series methods based on the Transformer architecture have demonstrated advantages in global modeling and object matching, while techniques such as Focal Modulation improve small object detection through feature enhancement [6], [7]. Nevertheless, these methods still rely heavily on limited real samples for training and thus continue to suffer from incomplete feature spaces and insufficient generalization to hard examples in long-tail distributions and complex background [8], [9]. Although image generation techniques have emerged as a promising avenue for alleviating sample scarcity [10], [11], [12], [13], without accurate modeling of railway scenes and foreign object intrusion semantics, generative models are still prone to producing images with unreasonable object placement, scale distortion, and lighting inconsistency, making it difficult to complete the feature space and improve detection performance [14], [15], [16].

To address these issues, this paper proposes a generative-augmented detection paradigm for railway foreign object intrusion detection, where realistic image generation is leveraged to enrich the feature space for detection.

Specifically, we first construct RailGen, a framework based on multimodal large models, to generate semantically consistent and physically plausible railway foreign object intrusion samples. First, with Low-Rank Adaptation (LoRA) for domain adaptation, Flow Matching is used to model continuous probability flows and generate railway background and foreign object images. Then, machine vision tools semantically analyze foreign object intrusion relationship and determine intrusion positions and scales that satisfy scene priors and physical constraints, thereby enabling the effective generation

Quan Hao, Chenxi Zhang, Rui Shi and Liguo Zhang are with the School of Information Science and Technology, Beijing University of Technology, Beijing, China. (email: haoquan@emails.bjut.edu.cn; zcx20041004@emails.bjut.edu.cn; ruishi@bjut.edu.cn; zhangliguo@bjut.edu.cn)

Ziyang Tao is with the College of Computer Science, Beijing University of Technology, Beijing, China. (email: taoziyang@emails.bjut.edu.cn;)

Yudong Wang is with the Institute of Automation, State Key Laboratory of Multimodal Artificial Intelligence Systems, Chinese Academy of Sciences, Beijing 100190, China. (email: wangyudong2018@ia.ac.cn)

This work was supported by Beijing Natural Science Foundation (Grant No. L243026, 4244088), and National Natural Science Foundation of China (Grant No. U2233211, 62403017). (Corresponding author: Liguo Zhang.)

RailGen: Agent Driven Image Generation

Small Foreign Object and Scenario Image Generation

Figure

Scenario

LoRA

FO LoRA

Velocity-Driven ODE

LLM Brain And

Multi Modal Awareness

SigClip

Railway Small

Foreign Object

Semantic

Awareness

Realistic Scale

Perspective

Modeling

Intrusion Contact

Multimodal

Reasoning

Structure-Aware Physical

Conditional Injection

P: Storm-blown

branch intruding

onto railway tracks

N: unrealistic

placement on rails

Foreign Object

Extration

Invasion Awareness

Flow Matching

Integrating Model

RailGen Dataset

Figure

FocalDEIM: Focal Driven Small Railway Foreign Object Detection

Real Dataset

RailGen Dataset

Dense Matching

One-to-One

N Query

Features

M Ground

TruthTargets

Feature Space Completion

Focal Modulation

Feature-Level Enhancement

Multi-scale

DW Conv

Context

Aggregation

Adaptive Gatina

(Linear Projection)

Modulated

Features

Hybrid

Encoder

Focal

Encoder

N Query

Self-Attn

N Query

Cross-Attn

Focal

Memory

Focal

Modulation

Focal Cost

Assignment Optimization

Focal Cost Cosine Sim

Regression Cost

Hungarian

Matching

Optimal

Assignment

Classification Cost

Real RFOD Scenario Evaluation

Fig. 1. Overall pipeline of the generative-augmented detection paradigm for railway foreign object intrusion detection

of challenging small-scale foreign objects in railway scenes. Furthermore, foreign object regional features are extracted and fused into the railway scene, producing high-fidelity intrusion images. This process increases sample diversity and helps complete the feature space under long-tail data distributions.

In addition to RailGen which enriches the feature space by expanding the sample distribution with diverse and physically plausible generated samples, we further propose FocalDEIM for joint training on generated and real data. Based on the dense one-to-one matching paradigm, FocalDEIM introduces Focal Modulation to refine decoder query representations before Hungarian assignment through context-aware aggregation, thereby enhancing the discriminability of small foreign object features in complex railway scenes. In addition, Focal Loss is adopted as the classification objective to reweight hard and easily confused samples during training, guiding optimization toward more informative matches and further improving detection performance.

Extensive experiments demonstrate that RailGen can generate high-quality small-scale foreign objects, reducing the object pixel area by up to 58×58\times and by 13.85×13.85\times on average. By leveraging these challenging samples, the proposed method improves mAP50mAP_{50} and mAP50−95mAP_{50-95} over the baseline model by 5.6% and 7.5% respectively, and outperforms existing state-of-the-art methods. Ablation studies further highlight the effectiveness of the proposed generation-detection synergy.

The main contributions of this paper are summarized as follows:

• We propose RailGen, a semantically consistent multimodal agent that generates realistic railway images through state-of-the-art generation performance, completing the feature space of detection models.

• We introduce FocalDEIM, a detection framework that enhances generated-data training via Focal Modulation for small object discrimination in dense matching and Focal Loss for hard-sample learning.

References (48)

  • Yolov5s-d: A railway catenary dropper state identification and small defect detection model
  • Optimized yolov11m for real-time high-speed railway catenary defect detection
  • Deep learning-based railway foreign object intrusion intelligent perception using attention-aggregated semantic segmentation
  • Yolov12: Attention-centric real-time object detectors (opens arXiv in a new tab)
  • Yolov13: Real-time object detection with hypergraph-enhanced adaptive visual perception (opens arXiv in a new tab)
  • Deim: Detr with improved matching for fast convergence
  • Focal modulation networks
  • A survey on long-tailed visual recognition
  • A survey on deep learning tools dealing with data scarcity: definitions, challenges, solutions, tips, and applications
  • Neuro-vae-symbolic dynamic traffic management
  • Dualfocus gan for robust watermarking in transportation cyber-physical systems
  • High-resolution image synthesis with latent diffusion models
  • Multi-scale cnn-transformer hybrid network for rail fastener defect detection
  • Advancements in obstacle intrusion detection methods for rail transit: A comprehensive review
  • Generative approach for detecting small intrusive foreign objects in high-speed railway scenario
  • Rosd: Railway intrusion object generalized detection via open-set detection
  • An effective railway intrusion detection method using dynamic intrusion region and lightweight neural network
  • Detrs beat yolos on real-time object detection
  • Object detection with transformers: A review
  • An adaptive sample assignment network for tiny object detection
  • Extended feature pyramid network for small object detection
  • Sdpdet: Learning scale-separated dynamic proposals for end-to-end drone-view detection
  • Focal modulation for image restoration: Y. cui et al
  • Railway obstacle intrusion warning mechanism integrating yolo-based detection and risk assessment
  • Auto-Encoding Variational Bayes
  • Generative adversarial networks (opens arXiv in a new tab)
  • Flow Matching for Generative Modeling
  • Flux.1 kontext: Flow matching for in-context image generation and editing in latent space (opens arXiv in a new tab)
  • LoRA: Low-rank adaptation of large language models
  • Gemma 3 Technical Report
  • Foodlmm: A versatile food assistant using large multi-modal model
  • Detailed object description with controllable dimensions
  • Learning Transferable Visual Models From Natural Language Supervision
  • Image segmentation using text and image prompts
  • Segment anything
  • A survey on llm-as-a-judge
  • Semantic image synthesis via diffusion models
  • Adding conditional control to text-to-image diffusion models
  • Railfod23: A dataset for foreign object detection on railroad transmission lines
  • Nano Banana
  • Soda10m: A large-scale 2d self/semi-supervised object detection dataset for autonomous driving
  • An analysis of single-layer networks in unsupervised feature learning
  • YOLO-Master: MOE-accelerated with specialized transformers for enhanced real-time detection
  • YOLO-World: Real-time open-vocabulary object detection
  • End-to-end object detection with transformers
  • Deformable DETR: deformable transformers for end-to-end object detection
  • Emerging properties in self-supervised vision transformers
  • Detrs with collaborative hybrid assignments training