神经网络不能处理给定的负载

Neural network can't handle load given

本文关键字:负载 不能 处理 神经网络      更新时间:2023-09-26

我在网上找到了一些用PHP完成的神经网络的源代码。你可以在这里找到:http://pastebin.com/MaqFXkWW

我认为这将是完美的决定你在画布上画的东西是否已经画过了。所以我开始构建一个概念证明,并构建这个neural_trainer.php脚本:

<? 
require_once ("class_neuralnetwork.php");
$pattern = $_POST['data'];
$n = new NeuralNetwork(90000, 90000, 1);
$n->setVerbose(false);
$n->addTestData($pattern, array (0));
$max = 9;

while (!($success = $n->train(1000, 0.01)) && $max -- > 0) {
    echo "Nothing found...<hr />";
}

if ($success) {
    $epochs = $n->getEpoch();
    echo "Success in $epochs training rounds!<hr />";
}

for ($i = 0; $i < count($n->trainInputs); $i ++) {
    $output = $n->calculate($n->trainInputs[$i]);
    print "<br />Testset $i; ";
    print "expected output = (".implode(", ", $n->trainOutput[$i]).") ";
    print "output from neural network = (".implode(", ", $output).")'n";
}

这是javascript,它发布到neural_trainer.php

//canvas1 is 300x300
var img1Data = ctx1.getImageData(0,0,canvas1.width,canvas1.height);
$.ajax({
    url: 'neural_training.php',
    data: { data: img },
    type: 'post',
    success: function(data) {
        console.log(data);
    }
});

但它一直抛出Allowed memory size of x bytes exhausted (tried to allocate x bytes),即使我把它放在class_neuralnetwork.php的顶部ini_set("memory_limit","340M"); ini_set('max_execution_time', 1000);

可供PHP使用的内存太小。要么通过memory_limit配置指令增加PHP可用的内存,要么重写脚本,使其消耗更少的内存。