我一直在尝试提取.pkl.gz文件中的一大组图像。这是我这样做的代码。
import gzip
import pickle
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import os
for f in os.listdir("W:CodeMachine Learningdigit-recognition-dnndata"):
print(f)
name = 'mnist.pkl.gz'
with gzip.open(name, 'rb') as f:
train_set, valid_set, test_set = pickle.load(f)
train_x, train_y = train_set
plt.imshow(train_x[0].reshape((28, 28)), cmap=cm.Greys_r)
plt.show()
不幸的是,输出是这样的:
getData.py
mnist.pkl.gz
Traceback (most recent call last):
File "w:CodeMachine Learningdigit-recognition-dnndatagetData.py", line 12, in <module>
with gzip.open(name, 'rb') as f:
File "C:UserstrexxAppDataLocalProgramsPythonPython39libgzip.py", line 58, in open
binary_file = GzipFile(filename, gz_mode, compresslevel)
File "C:UserstrexxAppDataLocalProgramsPythonPython39libgzip.py", line 173, in __init__
fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
FileNotFoundError: [Errno 2] No such file or directory: 'mnist.pkl.gz'
我的文件树是这样的:
data
├─ getData.py
└─ mnist.pkl.gz
有什么建议吗?
我尝试将name
更改为`
name = 'mnist.pkl'
和
name = 'mnist.gz'
结果是一样的。找不到文件。
尝试指定一个路径而不仅仅是名称。
用类似"W:my_dirmnist.pkl.gz
的东西替换mnist.pkl.gz