CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 15:45:41 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=cea2a5928435333ddfce452ef6fbd699463db2a0c401dcd6ef26bc314a31f16ca%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22V-ZnTncKaJA_d_lbWchhNtuAd6bG7eKm%22%3B%7D; HttpOnly; Path=/
cf-ray: 98cf7c67d8f3f473-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
-
⭐✅ MAKE $2000 INSTANTLY ✅ NEVER SEEN BEFORE ⭐...
JavaScript | 1 sec ago | 0.24 KB
-
✅⭐ Make huge profits on trading ⭐⭐ S
JavaScript | 3 sec ago | 0.24 KB
-
⭐ Free Crypto Method ✅ NEVER SEEN BEFORE ⭐⭐⭐
JavaScript | 11 sec ago | 0.24 KB
-
⭐✅ MAKE $2500 IN 15 MIN⭐⭐⭐ 6
JavaScript | 14 sec ago | 0.24 KB
-
✅⭐ Make huge profits on trading ✅ NEVER SEEN...
JavaScript | 21 sec ago | 0.24 KB
-
⭐✅ Exploit 2500$ in 15 Minutes⭐⭐⭐ E
JavaScript | 25 sec ago | 0.24 KB
-
⭐✅ Marketplace Glitch ✅ Working ✅ NEVER SEEN...
JavaScript | 30 sec ago | 0.24 KB
-
Free Crypto Method (NEVER SEEN BEFORE)⭐⭐ M
JavaScript | 36 sec ago | 0.24 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