我在网上找到了一些用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);
的顶部