-
Notifications
You must be signed in to change notification settings - Fork 8
/
validate.php
47 lines (31 loc) · 1.13 KB
/
validate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
include __DIR__ . '/vendor/autoload.php';
use Rubix\ML\Loggers\Screen;
use Rubix\ML\Datasets\Labeled;
use Rubix\ML\PersistentModel;
use Rubix\ML\Persisters\Filesystem;
use Rubix\ML\CrossValidation\Reports\AggregateReport;
use Rubix\ML\CrossValidation\Reports\ConfusionMatrix;
use Rubix\ML\CrossValidation\Reports\MulticlassBreakdown;
ini_set('memory_limit', '-1');
$logger = new Screen();
$logger->info('Loading data into memory');
$samples = $labels = [];
for ($label = 0; $label < 10; $label++) {
foreach (glob("testing/$label/*.png") as $file) {
$samples[] = [imagecreatefrompng($file)];
$labels[] = "#$label";
}
}
$dataset = new Labeled($samples, $labels);
$estimator = PersistentModel::load(new Filesystem('mnist.rbx'));
$logger->info('Making predictions');
$predictions = $estimator->predict($dataset);
$report = new AggregateReport([
'breakdown' => new MulticlassBreakdown(),
'matrix' => new ConfusionMatrix(),
]);
$results = $report->generate($predictions, $dataset->labels());
echo $results;
$results->toJSON()->saveTo(new Filesystem('report.json'));
$logger->info('Report saved to report.json');