0

我的本地驱动器中的数据分布在很多文件中。我想从 Google Colab 访问这些数据。由于它分布在很大的区域并且数据容易受到不断变化的影响,我不想使用 upload() 选项,因为它会变得乏味且冗长。由于数据值的变化,我也试图避免上传到云端硬盘。所以我想知道是否有另一种访问本地数据的方法类似于所提供的代码。

def list_files(dir):
    r = []
    for root, dirs, files in os.walk(dir):
        for name in dirs:
            r.append(os.path.join(root, name))
    return r

train_path = list_files('/home/path/to/folder/containing/data/')

这似乎不起作用,因为 GC 无法访问我的本地机器。所以我总是得到一个从函数返回的空数组 (0,)

4

1 回答 1

0

The short answer is: no, you can't. The long answer is: you can skip the uploading phase each time you restart the runtime. You just need to use google.colab package in order to have a similar behaviour to the local environment. Upload all the files you need to your google drive, then just import:

from google.colab import drive
drive.mount('/content/gdrive')

After the authentication part, you will be able to access all your files stored in google drive. They will be imported as you have uploaded them, so you just have to modify the last line in this way:

train_path = list_files('gdrive/path/to/folder/containing/data/')

or in this way:

train_path = list_files('/content/gdrive/home/path/to/folder/containing/data/')
于 2019-06-05T10:28:43.647 回答