How to download MNIST images as PNGs

拈花ヽ惹草 提交于 2020-03-19 07:02:15

问题


I want to download the MNIST images to my computer as PNG files.

I found this page: http://yann.lecun.com/exdb/mnist/

After I pressed: train-images-idx3-ubyte.gz: training set images (9912422 bytes)

It downloads a .gz file, which I am not sure what to do with. Please let me know if you have any ideas or suggestions. Thank you!


回答1:


Maybe I was not being clear with my question (I know there was some confusion), but here is the answer I found that was very simple.

https://github.com/myleott/mnist_png

Simply download the repo and expand the .tar.gz file. Done!




回答2:


You need to unzip these particular files in order to use them. A better way of doing it would be:

Download via:

curl -O http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz

Download to a particular path:

curl -O target/path/filename URL

Unzip the downloaded gzip archives:

gunzip t*-ubyte.gz

For further processing of data see the documentation

import gzip
f = gzip.open('train-images-idx3-ubyte.gz','r')

image_size = 28
num_images = 5

import numpy as np
import matplotlib.pyplot as plt

f.read(16)
buf = f.read(image_size * image_size * num_images)
data = np.frombuffer(buf, dtype=np.uint8).astype(np.float32)
data = data.reshape(num_images, image_size, image_size, 1)
image = np.asarray(data[2]).squeeze()
plt.imshow(image)

For extracting image see here

Update

Try this link to simply download and expand .gz files



来源:https://stackoverflow.com/questions/55049511/how-to-download-mnist-images-as-pngs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!