PHP Classes

File: examples/kernel/ai/taihandler/taihandler.convnd.php

Recommend this page to a friend!
  Packages of Christos Drogidis   Ascoos OS   examples/kernel/ai/taihandler/taihandler.convnd.php   Download  
File: examples/kernel/ai/taihandler/taihandler.convnd.php
Role: Example script
Content type: text/plain
Description: Demonstrates convND on a 2-channel 3x3 input using a multi-channel kernel.
Class: Ascoos OS
A PHP Web 5.0 Kernel for decentralized web and IoT
Author: By
Last change:
Date: 6 days ago
Size: 2,805 bytes
 

Contents

Class file image Download
<?php
/*
dobu {
    file:id(`example-00002522`),name(`taihandler.convnd`) {
        ascoos {
            logo {`
                  __ _ ___ ___ ___ ___ ___ ___ ___
                 / _' |/ / / __/ _ \ / _ \ / / / _ \ / /
                | (_| |\ \| (_| (_) | (_) |\ \ | (_) |\ \
                 \__,_|/__/ \___\___/ \___/ /__/ \___/ /__/
            `},
            name {`ASCOOS OS`},
            version {`1.0.0`}
        },
        example {
            class {`TAIHandler`},
            methods {`convND()`},
            source {`kernel/ai/taihandler/taihandler.convnd.php`},
            category:langs {
                en {`ND Convolution Engine`},
                el {`ND ???????????? ??????????`}
            },
            subcategory:langs {
                en {`Multi-channel ND Convolution`},
                el {`???????????? ND ????????`}
            },
            summary:langs {
                en {`ND convolution on nested multi-channel tensors`},
                el {`ND ???????? ?? ????????????? ?????????????? ???????`}
            },
            desc:langs {
                en {`Demonstrates convND on a 2-channel 3x3 input using a multi-channel kernel.`},
                el {`??????????? convND ?? ?????? 2 ???????? 3x3 ?? ???????????? ??????.`}
            },
            author {`Drogidis Christos`},
            since {`1.0.0`},
            sincePHP {`8.4.0`}
        },
        results:langs {
            all {`Input: [[[1,2,3],[4,5,6],[7,8,9]],[[9,8,7],[6,5,4],[3,2,1]]]
Kernel: [[[[1,0],[0,-1]],[[0,1],[-1,0]]]]
Output (convND VALID): [[[-2,-2],[-2,-2]]]

Execution statistics
Execution Time 0.181 ms
Memory Delta 4.55 KB
Peak Memory 18.00 MB
PHP Version 8.4.24
Ascoos OS`}
        }
    }
}
*/
declare(strict_types=1);
use
ASCOOS\OS\Kernel\AI\TAIHandler;

$startTime = microtime(true);
$startMem = memory_get_usage();

$ai = new TAIHandler([], []);

$input = [
    [
// Channel 1
       
[1,2,3],
        [
4,5,6],
        [
7,8,9]
    ],
    [
// Channel 2
       
[9,8,7],
        [
6,5,4],
        [
3,2,1]
    ]
];

$kernel = [
    [
// Output channel 1
       
[ // Input channel 1
           
[1,0],
            [
0,-1]
        ],
        [
// Input channel 2
           
[0,1],
            [-
1,0]
        ]
    ]
];

$output = $ai->convND($input, $kernel, 1, 'valid');

echo
"<pre>";
echo
"Input: " . json_encode($input) . "\n";
echo
"Kernel: " . json_encode($kernel) . "\n";
echo
"Output (convND VALID): " . json_encode($output) . "\n";
echo
"</pre>";

$ai->Free();
print_stats($startTime, $startMem);
?>