X-Ray Illicit Object Detection Using Hybrid CNN-Transformer Neural Network Architectures

Jorgen Cani, Christos Diou, Spyridon Evangelatos, Panagiotis Radoglou‐Grammatikis, Vasileios Argyriou, Panagiotis Sarigiannidis, Iraklis Varlamis, Georgios Th. Papadopoulos

TL;DR

This paper explores the effectiveness of hybrid Convolutional Neural Network (CNN)-Transformer architectures for detecting illicit objects in X-ray security scans. By combining the strengths of CNNs for local feature extraction and Transformers for global context modeling, these hybrid models show increased robustness, particularly in scenarios with domain shifts, outperforming traditional CNN-only approaches on challenging datasets.

What Problem Does This Paper Address?

Detecting prohibited items in X-ray security scans is a critical but challenging task. Objects can be heavily occluded, intentionally concealed, or appear with significant intra-class variation, making them difficult to spot. While CNNs excel at capturing local details, they struggle with long-range dependencies. Vision Transformers (ViTs), on the other hand, are adept at modeling global context but often require vast amounts of training data and can be computationally intensive. The existing literature in X-ray security imaging has largely relied on CNN-based methods, with limited exploration of hybrid CNN-Transformer architectures that could potentially offer a better balance of performance and robustness. This paper aims to bridge this gap by systematically evaluating such hybrid models.

Methods

The authors investigate several hybrid CNN-Transformer architectures for object detection. They combine two types of backbones: a CNN (HGNetV2) and a hybrid CNN-Transformer (Next-ViT-S). These backbones are then paired with two different detection heads: YOLOv8 and RT-DETR. The resulting architectures are denoted as D(head, backbone). Specifically, they evaluate D(YOLOv8, Next-ViT-S), D(RT-DETR, HGNetV2), and D(RT-DETR, Next-ViT-S). These are compared against a standard CNN-only baseline: D(YOLOv8, CSP-DarkNet53), which is the default YOLOv8 configuration. The integration of the Next-ViT-S backbone into the YOLOv8 and RT-DETR frameworks required modifications to their respective neck networks to accommodate the different feature map sizes and spatial resolutions. The paper details specific skip connection strategies for these integrations.

Datasets

The study evaluates the proposed architectures on three challenging public X-ray inspection datasets:

  • EDS (Endogenous Shift): This dataset is notable for introducing a domain shift, as it contains X-ray images captured by three different scanners. This simulates real-world deployment challenges and tests model robustness. It includes ten classes of common objects.
  • HiXray: This dataset consists of real-world X-ray scans from an international airport, annotated by security personnel. It features eight classes of prohibited items.
  • PIDray: This dataset focuses on deliberately hidden items, mimicking scenarios where prohibited objects are intentionally concealed. It includes twelve classes of prohibited items.

Key Insights and Ideas

  • Hybrid Models Shine in Domain Shift Scenarios: The most striking finding is that hybrid CNN-Transformer architectures demonstrate superior robustness when faced with domain shifts, as seen in the EDS dataset. This suggests that the global context modeling capabilities of Transformers are crucial for adapting to variations in scanning equipment or conditions.
  • CNN Backbones Still Competitive on Homogeneous Data: For datasets like HiXray and PIDray, which originate from a single scanner type, the traditional CNN-only YOLOv8 detector with its CSP-DarkNet53 backbone performs exceptionally well, often outperforming the hybrid models. This highlights that for less varied data, the efficiency and local feature extraction of CNNs remain highly effective.
  • Detection Head Matters: The research indicates that the choice of detection head significantly impacts performance. YOLOv8-based detectors with a Next-ViT-S backbone consistently outperformed their RT-DETR counterparts, suggesting the YOLOv8 detection head is more adept at leveraging the features from these backbones in the context of X-ray security imaging.
  • Hybridization Requires Careful Design: Simply replacing a CNN backbone with a hybrid one doesn't automatically guarantee improved performance. The paper emphasizes the need for careful design and experimentation regarding compatibility between backbones and detection heads, as demonstrated by the varied performance across different configurations.
  • Transformer Benefits for Hidden Objects: While the CNN-only model excels on "easy" and "hard" subsets of PIDray, the hybrid D(YOLOv8, Next-ViT-S) detector shows a slight edge in recognizing intentionally concealed items, hinting at the potential of hybrid models for more challenging occlusion scenarios.

Key Results

  • Overall Performance: The D(YOLOv8, CSP-DarkNet53) detector achieved the best overall performance on the HiXray and PIDray datasets.
  • Domain Shift Performance: For the EDS dataset, hybrid CNN-Transformer detectors generally outperformed the CNN-only baseline. D(RT-DETR, HGNetV2) showed the highest performance on EDS.
  • Object Scale Impact: In the EDS dataset, hybrid models (specifically D(YOLOv8, Next-ViT-S) and D(RT-DETR, HGNetV2)) significantly outperformed the CNN-only detector for medium-sized objects. This effect was less pronounced for large objects. For HiXray and PIDray, object scale had less impact on performance.
  • Specific Class Performance: On the EDS dataset, the CNN-only detector performed inferiorly for classes like 'Plastic bottle', 'Scissor', 'Lighter', 'Power bank', and 'Pressure', suggesting hybrid models are better for objects with fine-grained patterns or broader chemical composition appearances.

Limitations and Future Work

The authors acknowledge that the performance of hybrid architectures is highly dependent on the specific combination of backbone and detection head, and that further experimentation is needed. They suggest that future research should focus on investigating additional hybrid CNN-Transformer configurations and conducting broader experimental evaluations across more diverse datasets. The paper also provides source code and network weights to facilitate further research in this area.

Summary updated

Abstract

In the field of X-ray security applications, even the smallest details can significantly impact outcomes. Objects that are heavily occluded or intentionally concealed pose a great challenge for detection, whether by human observation or through advanced technological applications. While certain Deep Learning (DL) architectures demonstrate strong performance in processing local information, such as Convolutional Neural Networks (CNNs), others excel in handling distant information, e.g., transformers. In X-ray security imaging the literature has been dominated by the use of CNN-based methods, while the integration of the two aforementioned leading architectures has not been sufficiently explored. In this paper, various hybrid CNN-transformer architectures are evaluated against a common CNN object detection baseline, namely YOLOv8. In particular, a CNN (HGNetV2) and a hybrid CNN-transformer (Next-ViT-S) backbone are combined with different CNN/transformer detection heads (YOLOv8 and RT-DETR). The resulting architectures are comparatively evaluated on three challenging public X-ray inspection datasets, namely EDS, HiXray, and PIDray. Interestingly, while the YOLOv8 detector with its default backbone (CSP-DarkNet53) is generally shown to be advantageous on the HiXray and PIDray datasets, when a domain distribution shift is incorporated in the X-ray images (as happens in the EDS datasets), hybrid CNN-transformer architectures exhibit increased robustness. Detailed comparative evaluation results, including object-level detection performance and object-size error analysis, demonstrate the strengths and weaknesses of each architectural combination and suggest guidelines for future research. The source code and network weights of the models employed in this study are available at https://github.com/jgenc/xray-comparative-evaluation.
BibTeX
@misc{cani2025x,
  author = {Jorgen Cani and Christos Diou and Spyridon Evangelatos and Panagiotis Radoglou‐Grammatikis and Vasileios Argyriou and Panagiotis Sarigiannidis and Iraklis Varlamis and Georgios Th. Papadopoulos},
  title = {{X-Ray Illicit Object Detection Using Hybrid CNN-Transformer Neural Network Architectures}},
  year = {2025},
  eprint = {2505.00564},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2505.00564},
}
Figure