首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google Colab / Google Drive和h5py文件存储

Google Colab / Google Drive和h5py文件存储
EN

Stack Overflow用户
提问于 2019-12-15 22:16:56
回答 1查看 963关注 0票数 1

我正在尝试用谷歌Colab存储在我的谷歌硬盘上的数据来训练一个UNet神经网络。

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

为了防止这种情况,我用h5py库构建了一个".hdf5“文件。

代码语言:javascript
复制
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

文件创建正确:

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

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

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

谢谢,

EN

回答 1

Stack Overflow用户

发布于 2019-12-16 03:05:10

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

因此,我建议您使用GCS存储桶来存储它,而不是GDrive。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59344760

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档