Code Monkey home page Code Monkey logo

mnist's Introduction

Rubix ML

PHP from Packagist Latest Stable Version Downloads from Packagist Code Checks GitHub

A high-level machine learning and deep learning library for the PHP language.

  • Developer-friendly API is delightful to use
  • 40+ supervised and unsupervised learning algorithms
  • Support for ETL, preprocessing, and cross-validation
  • Open source and free to use commercially

Installation

Install Rubix ML into your project using Composer:

$ composer require rubix/ml

Requirements

  • PHP 7.4 or above

Recommended

Optional

Documentation

Read the latest docs here.

What is Rubix ML?

Rubix ML is a free open-source machine learning (ML) library that allows you to build programs that learn from your data using the PHP language. We provide tools for the entire machine learning life cycle from ETL to training, cross-validation, and production with over 40 supervised and unsupervised learning algorithms. In addition, we provide tutorials and other educational content to help you get started using ML in your projects.

Getting Started

If you are new to machine learning, we recommend taking a look at the What is Machine Learning? section to get started. If you are already familiar with basic ML concepts, you can browse the basic introduction for a brief look at a typical Rubix ML project. From there, you can browse the official tutorials below which range from beginner to advanced skill level.

Tutorials & Example Projects

Check out these example projects using the Rubix ML library. Many come with instructions and a pre-cleaned dataset.

Interact With The Community

Contributing

See CONTRIBUTING.md for guidelines.

License

The code is licensed MIT and the documentation is licensed CC BY-NC 4.0.

mnist's People

Contributors

andrewdalpino avatar ncavare avatar yrslv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mnist's Issues

dont recognize

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

installation error

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!

PHP Fatal Error while I try to run train.php

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

Running train.php ends up with PHP Fatal Error

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.