Google Colab在从Google Drive读取图像时速度太慢 [英] Google Colab is so slow while reading images from Google Drive

查看:0
本文介绍了Google Colab在从Google Drive读取图像时速度太慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我自己有一个深度学习项目的数据集。我把它上传到了Google Drive上,并链接到了Colab的一个页面上。但Colab在一秒钟内只能读取2-3张图片,而我的电脑可以读取数十张。(我使用imread来读取图像。)

keras的模型编译过程没有速度问题,但仅在从Google Drive读取图像时存在速度问题。有谁知道解决办法吗?也有人遇到了这个问题,但它仍然没有解决:Google Colab very slow reading data (images) from Google Drive(我知道这是链接中问题的一种重复,但我转发了它,因为它仍然没有解决。我希望这没有违反堆栈溢出规则。)

编辑:我用来阅读图片的代码片段:

def getDataset(path, classes, pixel=32, rate=0.8):
    X = []
    Y = []

    i = 0
    # getting images:
    for root, _, files in os.walk(path):
        for file in files:
            imagePath = os.path.join(root, file)
            className = os.path.basename(root)

            try:
                image = Image.open(imagePath)
                image = np.asarray(image)
                image = np.array(Image.fromarray(image.astype('uint8')).resize((pixel, pixel)))
                image = image if len(image.shape) == 3 else color.gray2rgb(image)
                X.append(image)
                Y.append(classes[className])
            except:
                print(file, "could not be opened")

    X = np.asarray(X, dtype=np.float32)
    Y = np.asarray(Y, dtype=np.int16).reshape(1, -1)

    return shuffleDataset(X, Y, rate)

推荐答案

我想就解压缩文件的实际情况提供更详细的答案。这是加快读取数据的最佳方式,因为将文件解压缩到VM磁盘比从驱动器中单独读取每个文件要快得多。

假设您在本地计算机的文件夹数据中有所需的图像或数据。压缩数据以获取Data.zip并将其上载到驱动器。

现在,挂载您的驱动器并运行以下命令:

!unzip "/content/drive/My Drive/path/to/Data.Zip" -d "/content"

只需修改您的所有图像路径以通过/Content/Data,读取图像就会快得多。

这篇关于Google Colab在从Google Drive读取图像时速度太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆