rubixml / mnist Goto Github PK
View Code? Open in Web Editor NEWHandwritten digit recognizer using a feed-forward neural network and the MNIST dataset of 70,000 human-labeled handwritten digits.
Home Page: https://rubixml.com
License: MIT License
Handwritten digit recognizer using a feed-forward neural network and the MNIST dataset of 70,000 human-labeled handwritten digits.
Home Page: https://rubixml.com
License: MIT License
hello,
after train and validate the model can not recognize a png hand written numeric image.why?
what need i to set yet for fine working?
Regards,
Gabor
I`m using 0.0.18-beta version of this library with PHP Version 7.3.12 bundled in XAMPP Version: 7.3.12 on Windows 10.
Whenever I try to run train.php, I get the following error:
C:\xampp\php\php.exe D:\Projects\MNIST\train.php
Loading data into memory ...
Training ...
[2020-02-02 12:01:26] MNIST.INFO: Fitted ZScaleStandardizer
PHP Fatal error: Uncaught InvalidArgumentException: Classifiers require categorical labels, continuous given. in D:\Projects\MNIST\vendor\rubix\ml\src\Other\Specifications\LabelsAreCompatibleWithLearner.php:27
Stack trace:
#0 D:\Projects\MNIST\vendor\rubix\ml\src\Classifiers\MultilayerPerceptron.php(347): Rubix\ML\Other\Specifications\LabelsAreCompatibleWithLearner::check(Object(Rubix\ML\Datasets\Labeled), Object(Rubix\ML\Classifiers\MultilayerPerceptron))
#1 D:\Projects\MNIST\vendor\rubix\ml\src\Classifiers\MultilayerPerceptron.php(324): Rubix\ML\Classifiers\MultilayerPerceptron->partial(Object(Rubix\ML\Datasets\Labeled))
#2 D:\Projects\MNIST\vendor\rubix\ml\src\Pipeline.php(150): Rubix\ML\Classifiers\MultilayerPerceptron->train(Object(Rubix\ML\Datasets\Labeled))
#3 D:\Projects\MNIST\vendor\rubix\ml\src\PersistentModel.php(125): Rubix\ML\Pipeline->train(Object(Rubix\ML\Datasets\Labeled))
#4 D:\Projects\MNIST\train.php(61): Rubix\ML\PersistentModel->train(Object(Rubix\ML\Datasets\Labeled))
#5 {main}
thrown in D:\Projects\MNIST\vendor\rubix\ml\src\Other\Specifications\LabelsAreCompatibleWithLearner.php on line 27
Fatal error: Uncaught InvalidArgumentException: Classifiers require categorical labels, continuous given. in D:\Projects\MNIST\vendor\rubix\ml\src\Other\Specifications\LabelsAreCompatibleWithLearner.php:27
Stack trace:
#0 D:\Projects\MNIST\vendor\rubix\ml\src\Classifiers\MultilayerPerceptron.php(347): Rubix\ML\Other\Specifications\LabelsAreCompatibleWithLearner::check(Object(Rubix\ML\Datasets\Labeled), Object(Rubix\ML\Classifiers\MultilayerPerceptron))
#1 D:\Projects\MNIST\vendor\rubix\ml\src\Classifiers\MultilayerPerceptron.php(324): Rubix\ML\Classifiers\MultilayerPerceptron->partial(Object(Rubix\ML\Datasets\Labeled))
#2 D:\Projects\MNIST\vendor\rubix\ml\src\Pipeline.php(150): Rubix\ML\Classifiers\MultilayerPerceptron->train(Object(Rubix\ML\Datasets\Labeled))
#3 D:\Projects\MNIST\vendor\rubix\ml\src\PersistentModel.php(125): Rubix\ML\Pipeline->train(Object(Rubix\ML\Datasets\Labeled))
#4 D:\Projects\MNIST\train.php(61): Rubix\ML\PersistentModel->train(Object(Rubix\ML\Datasets\Labeled))
#5 {main}
thrown in D:\Projects\MNIST\vendor\rubix\ml\src\Other\Specifications\LabelsAreCompatibleWithLearner.php on line 27
UPD: I found out that label type is determined by determine()
method in ...\vendor\rubix\ml\src\DataType.php
and that only data of type string
is corresponding to categorical
type. So I tried converting each $label
value to string before writing it to $labels
array in train.php:
for ($label = 0; $label < 10; $label++) {
foreach (glob("training/$label/*.png") as $file) {
$label = strval($label);
$samples[] = [imagecreatefrompng($file)];
$labels[] = $label;
}
}
This did the trick for me and I was able to run the script from PhpStorm 2019.3 built-in terminal. Nevertheless, for some reason the training only completed 1 epoch and finished. This seems to be a really strange behavior. Below is the output for that run (the prompt for saving the model does not appear on screen, but giving 'y' as the input saves the model):
C:\xampp\php\php.exe D:\Projects\MNIST\train.php
Loading data into memory ...
Training ...
[2020-02-02 17:07:40] MNIST.INFO: Fitted ZScaleStandardizer
[2020-02-02 17:07:45] MNIST.INFO: Learner init hidden=[0=Dense 1=Activation 2=Dropout 3=Dense 4=Activation 5=Dropout 6=Dense 7=Activation 8=Dropout] batch_size=200 optimizer=Adam alpha=0.0001 epochs=1000 min_change=0.0001 window=3 hold_out=0.1 cost_fn=CrossEntropy metric=FBeta
[2020-02-02 17:16:39] MNIST.INFO: Epoch 1 score=0.03078281535439 loss=0
[2020-02-02 17:16:39] MNIST.INFO: Training complete
Progress saved to progress.csv
y
Process finished with exit code 0
But when I try to run the script from Windows Command Prompt or PowerShell I get the following error:
C:\xampp\php\php.exe D:\Projects\MNIST\train.php
Loading data into memory ...
Training ...
[2020-02-02 18:04:09] MNIST.INFO: Fitted ZScaleStandardizer
PHP Fatal error: Uncaught InvalidArgumentException: The number of input nodes must be greater than 0, 0 given. in D:\Projects\MNIST\vendor\rubix\ml\src\NeuralNet\Layers\Placeholder1D.php:34
Stack trace:
#0 D:\Projects\MNIST\vendor\rubix\ml\src\Classifiers\MultilayerPerceptron.php(316): Rubix\ML\NeuralNet\Layers\Placeholder1D->__construct(0)
#1 D:\Projects\MNIST\vendor\rubix\ml\src\Pipeline.php(150): Rubix\ML\Classifiers\MultilayerPerceptron->train(Object(Rubix\ML\Datasets\Labeled))
#2 D:\Projects\MNIST\vendor\rubix\ml\src\PersistentModel.php(125): Rubix\ML\Pipeline->train(Object(Rubix\ML\Datasets\Labeled))
#3 D:\Projects\MNIST\train.php(71): Rubix\ML\PersistentModel->train(Object(Rubix\ML\Datasets\Labeled))
#4 {main}
thrown in D:\Projects\MNIST\vendor\rubix\ml\src\NeuralNet\Layers\Placeholder1D.php on line 34
Fatal error: Uncaught InvalidArgumentException: The number of input nodes must be greater than 0, 0 given. in D:\Projects\MNIST\vendor\rubix\ml\src\NeuralNet\Layers\Placeholder1D.php:34
Stack trace:
#0 D:\Projects\MNIST\vendor\rubix\ml\src\Classifiers\MultilayerPerceptron.php(316): Rubix\ML\NeuralNet\Layers\Placeholder1D->__construct(0)
#1 D:\Projects\MNIST\vendor\rubix\ml\src\Pipeline.php(150): Rubix\ML\Classifiers\MultilayerPerceptron->train(Object(Rubix\ML\Datasets\Labeled))
#2 D:\Projects\MNIST\vendor\rubix\ml\src\PersistentModel.php(125): Rubix\ML\Pipeline->train(Object(Rubix\ML\Datasets\Labeled))
#3 D:\Projects\MNIST\train.php(71): Rubix\ML\PersistentModel->train(Object(Rubix\ML\Datasets\Labeled))
#4 {main}
thrown in D:\Projects\MNIST\vendor\rubix\ml\src\NeuralNet\Layers\Placeholder1D.php on line 34
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
In the README.md it says that training takes less than 3 hours. I let the pc work overnight for over 8 hours and it reached only epoch 6. Is there any way to reduce the training time (in exchange for worse accuracy)? Is there any chance you could provide the pre-trained mnist.model data?
Hello!
I am trying to install but pecl gives me the following error:
libtool: compile: cc -I. -I/tmp/pear/temp/tensor/ext -I/tmp/pear/temp/pear-build-rootgoI8i3/tensor-3.0.00/include -I/tmp/pear/temp/pear-build-rootgoI8i3/tensor-3.0.00/main -I/tmp/pear/temp/tensor/ext -I/usr/include/php/20210902 -I/usr/include/php/20210902/main -I/usr/include/php/20210902/TSRM -I/usr/include/php/20210902/Zend -I/usr/include/php/20210902/ext -I/usr/include/php/20210902/ext/date/lib -DHAVE_CONFIG_H -g -O2 -O3 -ffast-math -c /tmp/pear/temp/tensor/ext/kernel/main.c -MMD -MF kernel/main.dep -MT kernel/main.lo -fPIC -DPIC -o kernel/.libs/main.o /tmp/pear/temp/tensor/ext/kernel/main.c: In function ‘zephir_fast_count’: /tmp/pear/temp/tensor/ext/kernel/main.c:154:45: error: ‘spl_ce_Countable’ undeclared (first use in this function); did you mean ‘zend_ce_countable’? 154 | if (instanceof_function(Z_OBJCE_P(value), spl_ce_Countable)) { | ^~~~~~~~~~~~~~~~ | zend_ce_countable /tmp/pear/temp/tensor/ext/kernel/main.c:154:45: note: each undeclared identifier is reported only once for each function it appears in /tmp/pear/temp/tensor/ext/kernel/main.c: In function ‘zephir_fast_count_ev’: /tmp/pear/temp/tensor/ext/kernel/main.c:204:45: error: ‘spl_ce_Countable’ undeclared (first use in this function); did you mean ‘zend_ce_countable’? 204 | if (instanceof_function(Z_OBJCE_P(value), spl_ce_Countable)) { | ^~~~~~~~~~~~~~~~ | zend_ce_countable /tmp/pear/temp/tensor/ext/kernel/main.c: In function ‘zephir_fast_count_int’: /tmp/pear/temp/tensor/ext/kernel/main.c:252:45: error: ‘spl_ce_Countable’ undeclared (first use in this function); did you mean ‘zend_ce_countable’? 252 | if (instanceof_function(Z_OBJCE_P(value), spl_ce_Countable)) { | ^~~~~~~~~~~~~~~~ | zend_ce_countable /tmp/pear/temp/tensor/ext/kernel/main.c: In function ‘zephir_function_exists’: /tmp/pear/temp/tensor/ext/kernel/main.c:285:101: warning: comparison between pointer and integer 285 | if (zend_hash_str_exists(CG(function_table), Z_STRVAL_P(function_name), Z_STRLEN_P(function_name)) != NULL) { | ^~ /tmp/pear/temp/tensor/ext/kernel/main.c: In function ‘zephir_function_exists_ex’: /tmp/pear/temp/tensor/ext/kernel/main.c:301:76: warning: comparison between pointer and integer 301 | if (zend_hash_str_exists(CG(function_table), function_name, function_len) != NULL) { | ^~ make: *** [Makefile:205: kernel/main.lo] Error 1 ERROR:
make' failed
`
my system is ubuntu server 20.04 with php 8.0.14
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.