【问题标题】:Google Colab / Google Drive and h5py file storageGoogle Colab / Google Drive 和 h5py 文件存储
【发布时间】:2020-04-08 05:11:24
【问题描述】:

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

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

为了防止它,我用 h5py 库构建了一个“.hdf5”文件。

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

文件已正确创建:

令我惊讶的是,我在我的谷歌驱动器上没有看到这个文件(只有一个同名的 0ko 文件)。 另外,我没有足够的存储空间来存储它

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

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

谢谢,

【问题讨论】:

    标签: google-drive-api google-colaboratory h5py


    【解决方案1】:

    该文件已创建并存储在 Google Cloud(Colab 实例)中。文件太大,无法同步回 Google Drive。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-24
      • 2022-08-20
      • 2018-10-22
      • 2020-09-17
      • 2018-09-27
      • 2019-12-16
      • 1970-01-01
      • 2018-11-11
      相关资源
      最近更新 更多