nimble install https://github.com/marcolussetti/mnist_tools
This libraries provides 6 functions:
# Loads Training Data into a sequence of MnistImage
# Downloads the files if not present in source directory
proc mnistTrainingData*(sourceDir: string = ""): seq[tuple[a: int, b: seq[int]]]
# Loads Training Data into a sequence of MnistImage
# Downloads the files if not present in source directory
proc mnistTestData*(sourceDir: string = ""): seq[tuple[a: int, b: seq[int]]]
# Returns a string visualization of an image, showing items above the threshold
proc mnistCoarseAsciiImage*(image: seq[int], cols: int = 28, threshold: int = 50): string
# Allows for manually specifying paths to load
proc mnistLoad*(imageFilePath: string, labelFilePath: string): seq[tuple[a: int, b: seq[int]]]
# Manually request download of MNIST files to specified directory
proc mnistDownload*(outputDir: string = "")
# Convert the datasets to CSV
proc mnistToCsv*(sourceDir = "", outputDir = "")
Provides a very coarse ascii print of the image as such:
import mnist_tools
# Will automatically download in local directory or other provided path
let mnistTraining = mnistTrainingData()
let mnistTest = mnistTestData()
echo mnistTraining[7].image.mnistCoarseAsciiImage # Should print a "3"
If all you need is the MNIST dataset as csvs, you can create a nim file with just a call to the function and then run it:
import mnist_tools
mnistToCsv()
nim c whateverfile.nim
# *nix
./whateverfile
# Win
whateverfile.exe