Skip to content

Commit

Permalink
Update to Rubix ML 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdalpino committed Aug 7, 2020
1 parent cbb835a commit 1c0c452
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $samples = $labels = [];
for ($label = 0; $label < 10; $label++) {
foreach (glob("training/$label/*.png") as $file) {
$samples[] = [imagecreatefrompng($file)];
$labels[] = (string) $label;
$labels[] = "$label";
}
}
```
Expand Down Expand Up @@ -144,7 +144,7 @@ $samples = $labels = [];
for ($label = 0; $label < 10; $label++) {
foreach (glob("testing/$label/*.png") as $file) {
$samples[] = [imagecreatefrompng($file)];
$labels[] = (string) $label;
$labels[] = "$label";
}
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"require": {
"php": ">=7.2",
"ext-gd": "*",
"rubix/ml": "^0.1.0-rc3"
"rubix/ml": "^0.1.0"
},
"suggest": {
"ext-tensor": "For faster training and inference"
Expand Down
12 changes: 6 additions & 6 deletions train.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Rubix\ML\NeuralNet\Optimizers\Adam;
use Rubix\ML\Persisters\Filesystem;
use Rubix\ML\Other\Loggers\Screen;
use League\Csv\Writer;
use Rubix\ML\Datasets\Unlabeled;

use function Rubix\ML\array_transpose;

Expand All @@ -29,7 +29,7 @@
for ($label = 0; $label < 10; $label++) {
foreach (glob("training/$label/*.png") as $file) {
$samples[] = [imagecreatefrompng($file)];
$labels[] = (string) $label;
$labels[] = "$label";
}
}

Expand All @@ -54,7 +54,7 @@
new Filesystem('mnist.model', true)
);

$estimator->setLogger(new Screen('MNIST'));
$estimator->setLogger(new Screen());

echo 'Training ...' . PHP_EOL;

Expand All @@ -63,9 +63,9 @@
$scores = $estimator->scores();
$losses = $estimator->steps();

$writer = Writer::createFromPath('progress.csv', 'w+');
$writer->insertOne(['score', 'loss']);
$writer->insertAll(array_transpose([$scores, $losses]));
Unlabeled::build(array_transpose([$scores, $losses]))
->toCSV(['scores', 'losses'])
->write('progress.csv');

echo 'Progress saved to progress.csv' . PHP_EOL;

Expand Down
6 changes: 4 additions & 2 deletions validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
for ($label = 0; $label < 10; $label++) {
foreach (glob("testing/$label/*.png") as $file) {
$samples[] = [imagecreatefrompng($file)];
$labels[] = (string) $label;
$labels[] = "$label";
}
}

Expand All @@ -37,6 +37,8 @@

$results = $report->generate($predictions, $dataset->labels());

file_put_contents('report.json', json_encode($results, JSON_PRETTY_PRINT));
echo $results;

$results->toJSON()->write('report.json');

echo 'Report saved to report.json' . PHP_EOL;

0 comments on commit 1c0c452

Please sign in to comment.