问题
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