load-mnist ( -- data-set )


Vocabulary
machine-learning.data-sets

Inputs and outputs
data-setan object


Definition


: load-mnist ( -- data-set )
"resource:datasets" dup make-directories [
{
"http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz"
"http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz"
"http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz"
"http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz"
} [
[ "resource:datasets/" download-to-directory ]
parallel-each
] [
[
dup file-stem exists?
[ drop ] [ file-name gzip-decompress-file ] if
] each
] [ [ file-stem binary file-contents ] map ] tri first4
{
[ mnist-data>array ]
[ mnist-labels>array ]
[ mnist-data>array ]
[ mnist-labels>array ]
} spread 4array
] with-directory ;