DEV Community

Ziad Alezzi
Ziad Alezzi

Posted on

I made an AI that detects landmines

Machine Learning is transforming industries worldwide. Yet in mine action, where lives are at stake, we are barely seeing any implementation even though the potential is so high.

I'm Ziad Alezzi, a 16 year old developer from Lebanon, my dream is to pursue my education in Japan under scholarship and to work towards a citizenship. To contribute to that goal, I made this video to prove that even with fundamental programming knowledge and publicly available tools, I was able to make two machine learning models to demonstrate:

"If I can do this, Mine Action Organizations with Professional Developers absolutely can."

Part 1: The Problem

The moment I began this project, I faced difficulty immediately. Landmines are sensitive military objects. Public image datasets are not available. And with insufficient labeled data, training an image classification model is impossible.

Instead of stopping there, I generated my own dataset.

Part 2: The Solution

In three days, I learned the basics of 3D modeling using Blender.

I downloaded freely available 3D Landmines, assembled them, added rusty textures to make them look realistic, and placed them in different terrains. By changing camera angles, positions, and soil textures, I was able to generate as many synthetic training images as I wanted.

This approach, called synthetic data generation, is widely used in AI research but not in mine action.

With my handmade dataset ready, I fine-tuned a pretrained convolutional neural network using the fast.ai library.


To prove how accessible experimenting with AI has become, I used the fast.ai library that has made it so that anyone can make their own image model with only 17 lines of code!

from fastai.vision.all import * 
from pathlib import Path

path = Path('data')
dls = DataBlock(
    blocks=(ImageBlock, CategoryBlock),
    get_items=get_image_files,
    splitter=RandomSplitter(valid_pct=0.1, seed=42),
    get_y=parent_label,
    item_tfms=[Resize(224, method='squish')]
).dataloaders(path, bs=6)
speed_learn = vision_learner(dls, 
                             'beit_base_patch16_224', 
                             metrics=error_rate, 
                             pretrained=True, 
                             pretrained_cfg=None, 
                             img_size=224)
speed_learn.fine_tune(5)
Enter fullscreen mode Exit fullscreen mode

Making an image model of this scale in 2015 used to require a research team and many years of development, but advancements in GPU capabilities has made it easy for even the average developer on a regular laptop.


The training process took only 10 seconds,

Yet was able to classify a photo of a real landmine which my mother had taken herself as she was touring a minefield for Lebanon's MAG (Mine Action Group)

Remember, the model was trained only on synthetic blender-generated images I created myself. Yet it still managed to successfully classify a real landmine with over 70% confidence.


My model was trained on images i made in blender like this:
Landmine In Blender
And was able to detect the same type of landmine taken in real life:

Real landmine photo
The process went like this:

1- Get the freely available landmine parts
Landmine Parts
2- Assemble the parts and add rusty textures
Assembled landmine
3- Put the landmine model in different scenes and take images to use as training data
landmine model in scenes


The goal here was proof of concept, not deployment readiness. However this demonstrated how accessible experimenting with AI has become.

Why image models alone aren't enough

In reality, most landmines are hidden underneath the ground. So while an image model is useful for cases like detecting butterfly landmines (antipersonel mines that are usually above the ground) using thermal imaging from drones, and has been done by researchers in Ukraine, it cannot be generalized to every mine.


They used simple low cost drones with thermal sensors attached:

drone with sensor
Had it fly over PFM-1 (Russian butterfly mines) to collect data:
Training setup
And were able to detect these mines through thermal sensing:
thermal imaging of mines
Citation: "Nikulin, Alex & Smet, Timothy & Baur, Jasper & Frazer, William & Abramowitz, Jacob. (2018). Detection and Identification of Remnant PFM-1 ‘Butterfly Mines’ with a UAV-Based Thermal-Imaging Protocol. Remote Sensing. 10. 10.3390/rs10111672."


This is where sensor-based detection becomes important.

In 2018, students at Gazi University in Turkey wrote a PhD thesis where they used drones equipped with sensors to collect the following environmental variables:

  • Soil type
  • Voltage detected
  • Drone altitude

These inputs were fed into a machine learning model capable of predicting the presence and type of buried mines.
Variables used by gazi students

Citation: "Yilmaz, C., Kahraman, H. T., & Söyler, S. (2018). Passive mine detection and classification method based on hybrid model. IEEE Access, 6, 47870-47888."

Inspired by this, I built a simplified tabular classification model using PyTorch which achieved 80% accuracy in detecting underground mines in a simulated dataset.


I used textbook applied Machine Learning with the PyTorch library, with nothing fancy:

import numpy as np
import torch
import pandas as pd
import torch.nn.functional as F


data = pd.read_csv('data2/mines.csv')
t_dep = torch.tensor(data['label'], dtype=torch.long)
t_indep = torch.tensor(data.drop(columns=['label']).astype(np.float32).values, dtype=torch.float)
t_indep = (t_indep - t_indep.mean(dim=0)) / t_indep.std(dim=0)
n_coeffs = t_indep.shape[1]

def init_coeffs():
    hiddens = [10, 8] # Update for each hidden layer
    sizes = [n_coeffs] + hiddens + [5]
    n = len(sizes)
    layers, consts = [], []
    for i in range(n-1):
        w = torch.empty(sizes[i], sizes[i+1])
        torch.nn.init.kaiming_uniform_(w, a=0)  # stable for ReLU
        layers.append(w.requires_grad_())

        b = torch.zeros(1, sizes[i+1], requires_grad=True)  # biases start at 0
        consts.append(b)
    return layers, consts
def update_coeffs(coeffs, lr):
    layers, consts = coeffs
    for layer in layers + consts:
        if layer.grad is not None:
            layer.sub_(layer.grad * lr)
            layer.grad.zero_()
    return layers, consts

def calc_preds(coeffs, indeps):
    layers, consts = coeffs
    n = len(layers)
    y_pred = indeps

    for i, layer in enumerate(layers):
        y_pred = y_pred @ layer + consts[i]
        if i != n-1: y_pred = F.relu(y_pred)
    preds = F.softmax(y_pred, dim=1)
    logits = y_pred
    return preds, logits

def one_epoch(t_dep, t_indep, coeffs, lr):
    preds, logits = calc_preds(coeffs, t_indep)
    loss = torch.nn.CrossEntropyLoss()(logits, t_dep)
    loss.backward()
    with torch.no_grad(): return update_coeffs(coeffs, lr)

def train_model(t_dep, t_indep, epochs=699, lr=1, loss_arr=[], acc_arr=[]):
    torch.manual_seed(777)
    coeffs = init_coeffs()
    for i in range(epochs):
        coeffs = one_epoch(t_dep, t_indep, coeffs, lr)
        preds, logits = calc_preds(coeffs, t_indep)
        loss = torch.nn.CrossEntropyLoss()(logits, t_dep)
        acc = accuracy(coeffs, t_dep, t_indep) * 100
        print(f"Iteration: {i:03d} | Loss: {loss:.4f} | Accuracy: {acc:.2f}%")
        loss_arr.append(loss.item())
        acc_arr.append(acc)

    return coeffs, loss_arr, acc_arr
Enter fullscreen mode Exit fullscreen mode

Again, this was not industrial-grade research, but a demonstration of accessibility.

In the context on Lebanon

Lebanon continues to suffer from landmines and unexploded ordnance. Areas affected by conflict remain potentially dangerous even after ceasefires. Mine action teams taking too long to sweep the areas can mean danger for returning citizens. And this is exactly what happened with Lebanon after the ceasefire a year ago, evacuated citizens returned back to their potentially landmine-contaminated land not knowing of the dangers that awaited them.

Instead of this truth, imagine this scenario:

  • On day one after the ceasfire, drone swarms are deployed
  • Equipped with simple voltage and soil sensors
  • AI model analyzes terrain in real time
  • Minefields are mapped quickly and precisely
  • Safe and dangerous areas become known to returning civilians
  • Demining teams know exactly where each mine is and what type it is before entering

This level of operational efficiency could substantially decrease potential casualties and make recovery way faster.

Again, while my models alone certaintly cannot achieve that:

If a high school student with limited resources can prototype these models, the barrier to mine action groups innovating in this field is clearly not technical inability.

And really, an important question comes up:

"Why must there be more developers working on making mines, but not against them?"

This Was ML

lucirie (Ziad Alezzi) · GitHub

lucirie has 25 repositories available. Follow their code on GitHub.

favicon github.com

Top comments (0)