PHP code example of rafaelglikis / mnist-reader

1. Go to this page and download the library: Download rafaelglikis/mnist-reader library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rafaelglikis / mnist-reader example snippets


use MnistReader\MnistReader;
use MnistReader\Image;

$mnistReader = new MnistReader("data");

try {
    $mnistReader->loadData();
} catch (Exception $e){
    print $e->getMessage() . "\n";
    die();
}

$images = $mnistReader->getImages();

print $images['train'][0]->getLabel();

$images['train'][0]->printAscii();
$images['train'][0]->printChars();

$images['train'][0]->save('train.png');

$pixels = $images['train'][0]->getPixels();

print $images['test'][0]->getLabel();
$images['test'][0]->printAscii();
$images['test'][0]->printChars();
$images['test'][0]->save('test.png');
$pixels = $images['test'][0]->getPixels();