Google Colab / Google云端硬盘和h5py文件存储

问题描述 投票:1回答:1

我正在尝试使用Google Colab用我的Google驱动器中存储的数据训练UNet神经网络。

我创建了一个核心库,数据集等。但是访问数据很慢。

为了防止出现这种情况,我使用h5py库构建了一个“ .h5df”文件。

XDataPath="/content/drive/My Drive/Dataset/data/X"
YDataPath="/content/drive/My Drive/Dataset/data/Y"
h5Path="/content/drive/My Drive/Dataset/data/dataset.hdf5"
nbX=len(os.listdir(XDataPath))
nbY=len(os.listdir(YDataPath))

# CleanData
dst=[os.path.splitext(f)[0] for f in os.listdir(YDataPath)]
src=[os.path.splitext(f)[0] for f in os.listdir(XDataPath)]
for f in src:
  if f not in dst:
    fpth=os.path.join(XDataPath,f+'.jpg')
    os.remove(fpth)
    print(fpth)
for f in dst:
  if f not in src:
    fpth=os.path.join(YDataPath,f+'.png')
    os.remove(fpth)
    print(fpth)

with h5py.File(h5Path,'a') as hfile:
  if not "X" in hfile:
    hfile.create_dataset("X",(nbX,512,512,3))
  if not "Y" in hfile:
    hfile.create_dataset("Y",(nbY,512,512))

for i,Path in tqdm.tqdm_notebook(enumerate(os.listdir(XDataPath)),total=nbX):
    ImPath=os.path.join(XDataPath,Path)
    with h5py.File(h5Path,'a') as hfile:
        with Image.open(ImPath) as f:
            X=np.array(f)
            hfile["X"][i]=X

文件已正确创建:

enter image description here

[令我惊讶的是,我在Google驱动器上没有看到该文件(只有一个名称相同的0ko文件)。更多,我没有足够的存储空间来存储它

enter image description here

为什么未在驱动器上创建此文件?它存储在哪里?

另一个问题是,当我重新启动环境时,h5df文件现在是0ko,就像在我的Google驱动器上一样。而且当然是空的!

谢谢,

google-drive-api google-colaboratory h5py
1个回答
0
投票

该文件已创建并存储在Google Cloud(Colab实例)中。该文件太大,因此无法同步回Google云端硬盘。

所以,我建议您使用GCS存储桶而不是GDrive存储它。

© www.soinside.com 2019 - 2024. All rights reserved.