Skip to content

Commit

Permalink
Use logger instead of echo
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdalpino committed Aug 7, 2020
1 parent 565df0a commit 37da90e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
12 changes: 6 additions & 6 deletions train.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

include __DIR__ . '/vendor/autoload.php';

use Rubix\ML\Other\Loggers\Screen;
use Rubix\ML\Datasets\Labeled;
use Rubix\ML\PersistentModel;
use Rubix\ML\Pipeline;
Expand All @@ -15,14 +16,15 @@
use Rubix\ML\NeuralNet\ActivationFunctions\LeakyReLU;
use Rubix\ML\NeuralNet\Optimizers\Adam;
use Rubix\ML\Persisters\Filesystem;
use Rubix\ML\Other\Loggers\Screen;
use Rubix\ML\Datasets\Unlabeled;

use function Rubix\ML\array_transpose;

ini_set('memory_limit', '-1');

echo 'Loading data into memory ...' . PHP_EOL;
$logger = new Screen();

$logger->info('Loading data into memory');

$samples = $labels = [];

Expand Down Expand Up @@ -54,9 +56,7 @@
new Filesystem('mnist.model', true)
);

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

echo 'Training ...' . PHP_EOL;
$estimator->setLogger($logger);

$estimator->train($dataset);

Expand All @@ -67,7 +67,7 @@
->toCSV(['scores', 'losses'])
->write('progress.csv');

echo 'Progress saved to progress.csv' . PHP_EOL;
$logger->info('Progress saved to progress.csv');

if (strtolower(trim(readline('Save this model? (y|[n]): '))) === 'y') {
$estimator->save();
Expand Down
9 changes: 6 additions & 3 deletions validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

include __DIR__ . '/vendor/autoload.php';

use Rubix\ML\Other\Loggers\Screen;
use Rubix\ML\Datasets\Labeled;
use Rubix\ML\PersistentModel;
use Rubix\ML\Persisters\Filesystem;
Expand All @@ -11,7 +12,9 @@

ini_set('memory_limit', '-1');

echo 'Loading data into memory ...' . PHP_EOL;
$logger = new Screen();

$logger->info('Loading data into memory');

$samples = $labels = [];

Expand All @@ -26,7 +29,7 @@

$estimator = PersistentModel::load(new Filesystem('mnist.model'));

echo 'Making predictions ...' . PHP_EOL;
$logger->info('Making predictions');

$predictions = $estimator->predict($dataset);

Expand All @@ -41,4 +44,4 @@

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

echo 'Report saved to report.json' . PHP_EOL;
$logger->info('Report saved to report.json');

0 comments on commit 37da90e

Please sign in to comment.