Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Fatal Error while I try to run train.php #4

Closed
shinnenkara opened this issue Feb 2, 2020 · 4 comments
Closed

PHP Fatal Error while I try to run train.php #4

shinnenkara opened this issue Feb 2, 2020 · 4 comments

Comments

@shinnenkara
Copy link

shinnenkara commented Feb 2, 2020

PHP Fatal Error while I try to run train.php using 0.0.18-beta version of this library, XAMPP and PHP 7.3.8 on Windows 10

C:\xampp\php\php.exe D:\[projects]\PhpStorm\MNIST\train.php
Loading data into memory ...
Training ...
[2020-02-02 16:47:36] MNIST.INFO: Fitted ZScaleStandardizer

Fatal error: Uncaught InvalidArgumentException: The number of input nodes must be greater than 0, 0 given. in D:\[projects]\PhpStorm\MNIST\vendor\rubix\ml\src\NeuralNet\Layers\Placeholder1D.php:34
Stack trace:
#0 D:\[projects]\PhpStorm\MNIST\vendor\rubix\ml\src\Classifiers\MultilayerPerceptron.php(316): Rubix\ML\NeuralNet\Layers\Placeholder1D->__construct(0)
#1 D:\[projects]\PhpStorm\MNIST\vendor\rubix\ml\src\Pipeline.php(150): Rubix\ML\Classifiers\MultilayerPerceptron->train(Object(Rubix\ML\Datasets\Labeled))
#2 D:\[projects]\PhpStorm\MNIST\vendor\rubix\ml\src\PersistentModel.php(125): Rubix\ML\Pipeline->train(Object(Rubix\ML\Datasets\Labeled))
#3 D:\[projects]\PhpStorm\MNIST\train.php(61): Rubix\ML\PersistentModel->train(Object(Rubix\ML\Datasets\Labeled))
#4 {main}
  thrown in D:\[projects]\PhpStorm\MNIST\vendor\rubix\ml\src\NeuralNet\Layers\Placeholder1D.php on line 34
PHP Fatal error:  Uncaught InvalidArgumentException: The number of input nodes must be greater than 0, 0 given. in D:\[projects]\PhpStorm\MNIST\vendor\rubix\ml\src\NeuralNet\Layers\Placeholder1D.php:34
Stack trace:
#0 D:\[projects]\PhpStorm\MNIST\vendor\rubix\ml\src\Classifiers\MultilayerPerceptron.php(316): Rubix\ML\NeuralNet\Layers\Placeholder1D->__construct(0)
#1 D:\[projects]\PhpStorm\MNIST\vendor\rubix\ml\src\Pipeline.php(150): Rubix\ML\Classifiers\MultilayerPerceptron->train(Object(Rubix\ML\Datasets\Labeled))
#2 D:\[projects]\PhpStorm\MNIST\vendor\rubix\ml\src\PersistentModel.php(125): Rubix\ML\Pipeline->train(Object(Rubix\ML\Datasets\Labeled))
#3 D:\[projects]\PhpStorm\MNIST\train.php(61): Rubix\ML\PersistentModel->train(Object(Rubix\ML\Datasets\Labeled))
#4 {main}
  thrown in D:\[projects]\PhpStorm\MNIST\vendor\rubix\ml\src\NeuralNet\Layers\Placeholder1D.php on line 34

Process finished with exit code 255
@andrewdalpino
Copy link
Member

Hi @karasick thank you for the bug report

This may be related to #3 or it may not

In general, you'd get this exception because the training dataset is empty (contains no features)

Could you post the full training script? I'll be better able to diagnose the issue

@shinnenkara
Copy link
Author

shinnenkara commented Feb 5, 2020

Thanks for your answer and that's train.php (I have the pulled one from master, commit 87ea1b):

<?php

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

use Rubix\ML\Datasets\Labeled;
use Rubix\ML\PersistentModel;
use Rubix\ML\Pipeline;
use Rubix\ML\Transformers\ImageResizer;
use Rubix\ML\Transformers\ImageVectorizer;
use Rubix\ML\Transformers\ZScaleStandardizer;
use Rubix\ML\Classifiers\MultiLayerPerceptron;
use Rubix\ML\NeuralNet\Layers\Dense;
use Rubix\ML\NeuralNet\Layers\Dropout;
use Rubix\ML\NeuralNet\Layers\Activation;
use Rubix\ML\NeuralNet\ActivationFunctions\LeakyReLU;
use Rubix\ML\NeuralNet\Optimizers\Adam;
use Rubix\ML\Persisters\Filesystem;
use Rubix\ML\Other\Loggers\Screen;
use League\Csv\Writer;

use function Rubix\ML\array_transpose;

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

echo 'Loading data into memory ...' . PHP_EOL;

$samples = $labels = [];

for ($label = 0; $label < 10; $label++) {
    foreach (glob("training/$label/*.png") as $file) {
        $samples[] = [imagecreatefrompng($file)];
        $labels[] = $label;
    }
}

$dataset = new Labeled($samples, $labels);

$estimator = new PersistentModel(
    new Pipeline([
        new ImageResizer(28, 28),
        new ImageVectorizer(1),
        new ZScaleStandardizer(),
    ], new MultiLayerPerceptron([
        new Dense(100),
        new Activation(new LeakyReLU()),
        new Dropout(0.2),
        new Dense(100),
        new Activation(new LeakyReLU()),
        new Dropout(0.2),
        new Dense(100),
        new Activation(new LeakyReLU()),
        new Dropout(0.2),
    ], 200, new Adam(0.001))),
    new Filesystem('mnist.model', true)
);

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

echo 'Training ...' .  PHP_EOL;

$estimator->train($dataset);

$scores = $estimator->scores();
$losses = $estimator->steps();

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

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

if (strtolower(trim(readline('Save this model? (y|[n]): '))) === 'y') {
    $estimator->save();
}

and i have standard MNIST dataset in training and testing folders

@shinnenkara
Copy link
Author

shinnenkara commented Feb 5, 2020

Also i check last commit 3895be and train.php work as planned

@andrewdalpino
Copy link
Member

Awesome @karasick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants