File size: 5,116 Bytes
ac96323
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
---
license: apache-2.0
tags:
  - image-classification
  - x-ray
  - customs
  - smuggling-detection
  - sonar
language:
  - ar
  - en
---

# ๐Ÿ”ฑ SONAR AI - Customs X-Ray Inspection Models

## Dr. Abbas Fadel Jassim | 2026

> AI-powered customs inspection system for X-ray cargo scanning

---

## ๐Ÿ“Š Models Performance Summary

| # | Model | Task | Classes | F1 Score | Architecture |
|---|-------|------|---------|----------|-------------|
| 1 | **Classification** | ุชุตู†ูŠู ุงู„ุจุถุงุนุฉ | 43 | **94.2%** | Swin-V2 Tiny |
| 2 | **Concealment** | ูƒุดู ุงู„ุฅุฎูุงุก | 2 | **98.4%** | Swin-V2 Tiny |
| 3 | **Risk Assessment** | ุชู‚ูŠูŠู… ุงู„ุฎุทูˆุฑุฉ | 5 | **97.3%** | DaViT Tiny |

---

## ๐Ÿ” Model 1: Classification (43 cargo categories)

**Task:** Classify X-ray images into 43 different cargo types

| Model | Params | Accuracy | F1 Score |
|-------|--------|----------|----------|
| ๐Ÿ† **Swin-V2 Tiny** | 27.6M | 94.2% | **94.1%** |
| ๐Ÿฅˆ **DaViT Tiny** | 27.6M | 94.2% | **94.1%** |

### Per-Class Performance (Swin-V2):

| Category | Precision | Recall | F1 | Samples |
|----------|-----------|--------|-----|---------|
| appliances | 98.2% | 98.2% | **98.2%** | 57 |
| auto_parts | 92.6% | 94.3% | **93.5%** | 53 |
| bags | 100% | 100% | **100%** | 12 |
| banana | 100% | 100% | **100%** | 40 |
| batteries | 100% | 88.9% | **94.1%** | 9 |
| beverages | 71.4% | 100% | **83.3%** | 10 |
| cables | 100% | 94.4% | **97.1%** | 18 |
| canned_food | 92.0% | 79.3% | **85.2%** | 29 |
| ceramic | 97.5% | 97.5% | **97.5%** | 40 |
| chemicals | 100% | 94.9% | **97.4%** | 39 |
| cleaning | 91.7% | 91.7% | **91.7%** | 24 |
| clothes | 91.8% | 96.3% | **94.0%** | 81 |
| cooking_oil | 76.9% | 100% | **87.0%** | 10 |
| cosmetics | 100% | 94.1% | **97.0%** | 17 |
| electronics | 92.7% | 87.9% | **90.3%** | 58 |
| fruits | 85.7% | 100% | **92.3%** | 6 |
| furniture | 97.1% | 96.6% | **96.8%** | 174 |
| glass | 95.2% | 100% | **97.6%** | 20 |
| kitchenware | 100% | 100% | **100%** | 2 |
| lubricants | 92.3% | 100% | **96.0%** | 12 |
| machinery | 87.5% | 95.5% | **91.3%** | 66 |
| meat | 92.3% | 92.3% | **92.3%** | 13 |
| medical | 100% | 100% | **100%** | 3 |
| milk | 98.4% | 98.4% | **98.4%** | 62 |
| motorcycle | 100% | 66.7% | **80.0%** | 6 |
| nuts | 92.9% | 100% | **96.3%** | 26 |

**Training:** 30 epochs, AdamW (lr=1e-4), CosineAnnealing, Albumentations augmentation

---

## ๐Ÿ” Model 2: Concealment Detection (match vs no_match)

**Task:** Detect hidden/smuggled items in X-ray containers

| Model | Params | Accuracy | F1 Score |
|-------|--------|----------|----------|
| ๐Ÿ† **Swin-V2 Tiny** | 27.6M | 98.4% | **98.4%** |
| ๐Ÿฅˆ **DaViT Tiny** | 27.6M | 98.4% | **98.4%** |
| ๐Ÿฅ‰ **EVA-02 Tiny** | 5.5M | 97.8% | **97.8%** |
| 4๏ธโƒฃ **MaxViT Tiny** | 30.4M | 96.7% | **96.8%** |

### Classes:
- **match:** Container contents match declaration (6,348 images)
- **no_match:** Concealed/smuggled items detected (702 images)

---

## โš ๏ธ Model 3: Risk Assessment (5 levels)

**Task:** Assess risk level of container cargo

| Model | Params | Accuracy | F1 Score |
|-------|--------|----------|----------|
| ๐Ÿ† **DaViT Tiny** | 27.6M | 97.2% | **97.3%** |
| ๐Ÿฅˆ **Swin-V2 Tiny** | 27.6M | 97.2% | **97.2%** |

### Risk Levels:

| Level | Name (AR) | Name (EN) | Samples | F1 Score |
|-------|-----------|-----------|---------|----------|
| 0 | ุขู…ู† | Safe | 6,355 | **99.1%** |
| 1-2 | ู…ู†ุฎูุถ | Low | 5 | โš ๏ธ Limited |
| 3 | ู…ุชูˆุณุท | Medium | 387 | **79.5%** |
| 4 | ุนุงู„ูŠ | High | 297 | **84.5%** |
| 5 | ุญุฑุฌ | Critical | 6 | โš ๏ธ Limited |

**Note:** Low and Critical levels have very few training samples.

---

## ๐Ÿ“ Files
```
SONAR-AI-Models/
โ”œโ”€โ”€ concealment/
โ”‚   โ”œโ”€โ”€ best_swinv2.pth      (110 MB, 98.4% F1)
โ”‚   โ”œโ”€โ”€ best_davit.pth       (110 MB, 98.4% F1)
โ”‚   โ”œโ”€โ”€ best_eva02.pth       (22 MB, 97.8% F1)
โ”‚   โ””โ”€โ”€ best_maxvit.pth      (122 MB, 96.8% F1)
โ”œโ”€โ”€ classification/
โ”‚   โ”œโ”€โ”€ best_swinv2_43cls.pth (110 MB, 94.1% F1)
โ”‚   โ””โ”€โ”€ best_davit_43cls.pth  (110 MB, 94.1% F1)
โ”œโ”€โ”€ risk/
โ”‚   โ”œโ”€โ”€ best_swinv2_risk.pth  (110 MB, 97.2% F1)
โ”‚   โ””โ”€โ”€ best_davit_risk.pth   (110 MB, 97.3% F1)
โ””โ”€โ”€ results/
    โ”œโ”€โ”€ classification_cm.png
    โ”œโ”€โ”€ classification_training.png
    โ”œโ”€โ”€ risk_cm.png
    โ””โ”€โ”€ risk_training.png
```

## ๐Ÿ› ๏ธ Usage
```python
import timm, torch
from torchvision import transforms
from PIL import Image

# Load model
model = timm.create_model('swinv2_tiny_window8_256', pretrained=False, num_classes=43)
ckpt = torch.load('classification/best_swinv2_43cls.pth', map_location='cpu')
model.load_state_dict(ckpt['model_state_dict'])
model.eval()

# Inference
tf = transforms.Compose([
    transforms.Resize((256, 256)),
    transforms.ToTensor(),
    transforms.Normalize([0.485,0.456,0.406], [0.229,0.224,0.225])
])
img = tf(Image.open('xray.jpg').convert('RGB')).unsqueeze(0)
with torch.no_grad():
    pred = model(img).argmax(1).item()
```

## ๐Ÿ“œ License
Apache 2.0

## ๐Ÿ‘จโ€๐Ÿ’ป Author
**Dr. Abbas Fadel Jassim** - 2026