A minimal PHP example (intuitive)

A simple convolution

PHP is not used for deep learning in production, but it is excellent for understanding.

 
<?php

include 'code.php';

// Example filter (vertical edges)
$kernel = [
    [
1, 0, -1],
    [
1, 0, -1],
    [
1, 0, -1],
];

// Example image (simplified)
$image = [
    [
10, 10, 10, 0, 0],
    [
10, 10, 10, 0, 0],
    [
10, 10, 10, 0, 0],
    [
10, 10, 10, 0, 0],
    [
10, 10, 10, 0, 0],
];

$featureMap = convolve($image, $kernel);

echo 
'Feature map:' . PHP_EOL;

foreach (
$featureMap as $row) {
    echo 
implode("\t", $row) . PHP_EOL;
}

Example:

kernel = [
    [1, 0, -1],
    [1, 0, -1],
    [1, 0, -1],
]

image = [
    [10, 10, 10, 0, 0],
    [10, 10, 10, 0, 0],
    [10, 10, 10, 0, 0],
    [10, 10, 10, 0, 0],
    [10, 10, 10, 0, 0],
]
Result: Memory: 0.005 Mb Time running: < 0.001 sec.
Feature map:
0	30	30
0	30	30
0	30	30

After the convolution you get a feature map where the edges "light up".