【发布时间】:2020-04-14 11:58:26
【问题描述】:
我在 tf.keras 中的代码如下所示。 我想在model_cnn文件夹的每个子目录(component_0,component_1)中检索一个文件(Xscale.npy)。
root_dir = '/content/drive/My Drive/DeepCID/model_cnn'
i=0
for (root, dirs, files) in os.walk(root_dir):
for d in dirs:
print(dirs)
os.chdir(os.path.join(root, d))
print(os.getcwd())
datafile3 = './Xscale.npy'
Xscale = np.load(datafile3)
错误信息是,
['.ipynb_checkpoints', 'component_0', 'component_1']
/content/drive/My Drive/DeepCID/model_cnn/.ipynb_checkpoints
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-1-862f78aebef9> in <module>()
57 print(os.getcwd())
58 datafile3 = './Xscale.npy'
---> 59 Xscale = np.load(datafile3)
60 Xtest = (Xtest0 - Xscale[0])/Xscale[1]
61
/usr/local/lib/python3.6/dist-packages/numpy/lib/npyio.py in load(file, mmap_mode, allow_pickle, fix_imports, encoding)
426 own_fid = False
427 else:
--> 428 fid = open(os_fspath(file), "rb")
429 own_fid = True
430
FileNotFoundError: [Errno 2] No such file or directory: './Xscale.npy'
我知道 '.ipynb_checkpoints' 是问题所在。 但是,当我查看文件夹时,没有 .ipynb_checkpoints 文件或文件夹。
我的问题是
1) 访问子目录中的文件时如何忽略 .ipynb_checkpoints?
2) 为什么 .ipynb_checkpoints 文件在 colab 磁盘中不可见?
提前致谢, D.-H.
【问题讨论】:
-
该文件在 GUI 中不可见,因为它是一个点文件,这意味着它默认是隐藏的。也不需要切换破坏东西的目录,只需提供项目的路径......
标签: python google-colaboratory tf.keras os.walk os.path