I have a pkl file from MNIST dataset, which consists of handwritten digit images.
I'd like to take a look at each of those digit images, so I need to unpack the pkl file, except I can't find out how.
Is there a way to unpack/unzip pkl file?
I have a pkl file from MNIST dataset, which consists of handwritten digit images.
I'd like to take a look at each of those digit images, so I need to unpack the pkl file, except I can't find out how.
Is there a way to unpack/unzip pkl file?
Generally
Your
pkl
file is, in fact, a serializedpickle
file, which means it has been dumped using Python'spickle
module.To un-pickle the data you can:
For the MNIST data set
Note
gzip
is only needed if the file is compressed:Where each set can be further divided (i.e. for the training set):
Those would be the inputs (digits) and outputs (labels) of your sets.
If you want to display the digits:
The other alternative would be to look at the original data:
http://yann.lecun.com/exdb/mnist/
But that will be harder, as you'll need to create a program to read the binary data in those files. So I recommend you to use Python, and load the data with
pickle
. As you've seen, it's very easy. ;-)In case you want to work with the original MNIST files, here is how you can deserialize them.
If you haven't downloaded the files yet, do that first by running the following in the terminal:
Then save the following as
deserialize.py
and run it.The script doesn't normalize the pixel values like in the pickled file. To do that, all you have to do is
Handy one-liner
Will print
__str__
for the pickled object.The generic problem of visualizing an object is of course undefined, so if
__str__
is not enough, you will need a custom script.