From 1c0c452196f49895c7a2b25149f856e3a937ab8c Mon Sep 17 00:00:00 2001 From: Andrew DalPino Date: Thu, 6 Aug 2020 20:21:35 -0500 Subject: [PATCH] Update to Rubix ML 0.1.0 --- README.md | 4 ++-- composer.json | 2 +- train.php | 12 ++++++------ validate.php | 6 ++++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a756d8193..f62d765f4 100644 --- a/README.md +++ b/README.md @@ -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"; } } ``` @@ -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"; } } diff --git a/composer.json b/composer.json index 1adb9ab07..71e7e6b42 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/train.php b/train.php index 829ff55cb..8c6f3ad55 100644 --- a/train.php +++ b/train.php @@ -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; @@ -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"; } } @@ -54,7 +54,7 @@ new Filesystem('mnist.model', true) ); -$estimator->setLogger(new Screen('MNIST')); +$estimator->setLogger(new Screen()); echo 'Training ...' . PHP_EOL; @@ -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; diff --git a/validate.php b/validate.php index 669111498..d1cad13f6 100644 --- a/validate.php +++ b/validate.php @@ -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"; } } @@ -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;