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 de781dd commit 698c468
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\Extractors\NDJSON;
use Rubix\ML\PersistentModel;
Expand All @@ -11,14 +12,15 @@
use Rubix\ML\Classifiers\SoftmaxClassifier;
use Rubix\ML\NeuralNet\Optimizers\Momentum;
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');

$dataset = Labeled::fromIterator(new NDJSON('train.ndjson'));

Expand All @@ -30,9 +32,7 @@
new Filesystem('har.model')
);

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

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

$estimator->train($dataset);

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

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

if (strtolower(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\Extractors\NDJSON;
use Rubix\ML\PersistentModel;
Expand All @@ -12,13 +13,15 @@

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

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

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

$dataset = Labeled::fromIterator(new NDJSON('test.ndjson'));

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

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

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

Expand All @@ -33,4 +36,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 698c468

Please sign in to comment.