CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 19:30:01 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=6519cc2cbf9b6a9f93e4a3e7d574e7edd2ce01b006da7aacdfc170dc9bb5cb68a%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22tCYJMDrIM3FDLowlje8CFdPHIpux99Ul%22%3B%7D; HttpOnly; Path=/
cf-ray: 98d0c504aff3af3d-BLR
[Simba 2.0] MNIST data parser - Pastebin.com
SHARE
TWEET

[Simba 2.0] MNIST data parser
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*
- This code is part of the article found at:
- https://slacky.one/article/simba-2_0-a-step-into-machine-learning
- *)
- function BytesToInt32(Bytes: TByteArray; StartIndex: Integer): Integer;
- begin
- Result := (Bytes[StartIndex] shl 24) or (Bytes[StartIndex + 1] shl 16) or
- (Bytes[StartIndex + 2] shl 8) or Bytes[StartIndex + 3];
- end;
- function ParseMNISTFile(FileName: string): array of TSingleMatrix;
- var
- FileData: TByteArray;
- MagicNumber, NumImages, NumRows, NumCols: Integer;
- i, r, c, Offset: Integer;
- begin
- if not FileExists(FileName) then
- begin
- WriteLn('File not found: ', FileName);
- Exit;
- end;
- // Read the entire file into memory
- FileData := FileReadBytes(FileName);
- if Length(FileData) = 0 then
- begin
- WriteLn('Failed to read file or file is empty.');
- Exit;
- end;
- // Parse the header (16 bytes)
- MagicNumber := BytesToInt32(FileData, 0);
- NumImages := BytesToInt32(FileData, 4);
- NumRows := BytesToInt32(FileData, 8);
- NumCols := BytesToInt32(FileData, 12);
- if MagicNumber <> 2051 then
- begin
- WriteLn('Invalid magic number: ', MagicNumber);
- Exit;
- end;
- // Allocate memory for images
- SetLength(Result, NumImages);
- for i := 0 to NumImages - 1 do
- SetLength(Result[i], NumRows, NumCols);
- // Parse image data
- Offset := 16; // Image data starts after the header
- for i := 0 to NumImages - 1 do
- begin
- for r := 0 to NumRows - 1 do
- begin
- for c := 0 to NumCols - 1 do
- begin
- Result[i][r][c] := FileData[Offset];
- Inc(Offset);
- end;
- end;
- end;
- end;
- function ParseMNISTLabels(FileName: string): array of Byte;
- var
- FileData: TByteArray;
- MagicNumber, NumLabels, Offset: Integer;
- i: Integer;
- begin
- if not FileExists(FileName) then
- begin
- WriteLn('File not found: ', FileName);
- Exit;
- end;
- // Read the entire file into memory
- FileData := FileReadBytes(FileName);
- if Length(FileData) = 0 then
- begin
- WriteLn('Failed to read file or file is empty.');
- Exit;
- end;
- // Parse the header (8 bytes)
- MagicNumber := BytesToInt32(FileData, 0);
- NumLabels := BytesToInt32(FileData, 4);
- if MagicNumber <> 2049 then
- begin
- WriteLn('Invalid magic number: ', MagicNumber);
- Exit;
- end;
- // Allocate memory for labels
- SetLength(Result, NumLabels);
- // Parse labels (starting at offset 8)
- Offset := 8;
- for i := 0 to NumLabels - 1 do
- begin
- Result[i] := FileData[Offset];
- Inc(Offset);
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
-
📌 ChangeNOW Exploit
JavaScript | 4 sec ago | 0.24 KB
-
⭐⭐⭐Instant Profit Method⭐⭐
Java | 6 sec ago | 0.10 KB
-
⭐✅ Exploit 2500$ in 15 Minutes⭐⭐⭐ P
JavaScript | 12 sec ago | 0.25 KB
-
💵 Make 3000$ in 20 minutes 💵
JavaScript | 16 sec ago | 0.24 KB
-
⭐⭐⭐Make $1500 in 20 minutes⭐⭐
Java | 17 sec ago | 0.10 KB
-
⭐⭐⭐Make $1500 in 20 minutes⭐⭐
Java | 18 sec ago | 0.10 KB
-
📌 Swapzone +37% glitch
JavaScript | 25 sec ago | 0.24 KB
-
Free Crypto Method (NEVER SEEN BEFORE)⭐⭐ G
JavaScript | 25 sec ago | 0.25 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand