ud730任务:notMNIST

题目链接
这个任务一共有六个小任务,在Problem 1前的三段代码是预处理图片的代码,分别用于载入需要的库、在相应网址中下载训练集的压缩包、解压压缩包,编译的时候直接把三段代码复制下来即可完成所有预备工作,解压花的时间会多一点,别强行终止程序就是了,如果强行终止,第二次再运行会出error。运行成功后会显示如下代码:

Found and verified .\notMNIST_large.tar.gz
Found and verified .\notMNIST_small.tar.gz
.\notMNIST_large already present - Skipping extraction of .\notMNIST_large.tar.gz.
['.\\notMNIST_large\\A', '.\\notMNIST_large\\B', '.\\notMNIST_large\\C', '.\\notMNIST_large\\D', '.\\notMNIST_large\\E', '.\\notMNIST_large\\F', '.\\notMNIST_large\\G', '.\\notMNIST_large\\H', '.\\notMNIST_large\\I', '.\\notMNIST_large\\J']
.\notMNIST_small already present - Skipping extraction of .\notMNIST_small.tar.gz.
['.\\notMNIST_small\\A', '.\\notMNIST_small\\B', '.\\notMNIST_small\\C', '.\\notMNIST_small\\D', '.\\notMNIST_small\\E', '.\\notMNIST_small\\F', '.\\notMNIST_small\\G', '.\\notMNIST_small\\H', '.\\notMNIST_small\\I', '.\\notMNIST_small\\J']

Problem1.就是让我们写代码把一些图片展示出来,博主不会写把展示一堆图片的,菜哭寄几呜呜呜:

from PIL import Image
#圆括号里是路径+图片名,记得不要用反斜杠表示目录之间的关系,要用正斜杠,反斜杠是个转义字符(可能是吧哈哈哈)
img=Image.open('F:/python/19.01.24/venv/notMNIST_small/A/MDEtMDEtMDAudHRm.png')
img.show()

Problem 2:将转化成pickle文件后的图片可视化

参考博客

with open("F:/python/19.01.24/venv/notMNIST_large/B.pickle",'rb') as pk_f:
    show_pickle=pickle.load(pk_f)#pickle.load()方法用于反序列化对象,将文件中的数据解析为一个python对象
    #第一个数是图片在文件里的***,从1开始,文件里的第二张图片是个“术”的繁体字,如运行截图所示:
img=show_pickle[2,:,:]
#imshow()用于显示灰度图
plt.imshow(img)
#show()在屏幕上显示图像
plt.show()

运行结果如下:
ud730任务:notMNIST