簡體   English   中英

有沒有辦法訪問本地文件,而無需在Google Colab中使用upload()選項或將數據上傳到驅動器然后訪問它

[英]Is there a way to access local files without having to use upload() option in Google Colab or uploading the data to the drive and then accessing it

我的本地驅動器中的數據遍布很多文件。 我想從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,)

簡短的回答是:不,你不能。 答案很長:每次重新啟動運行時都可以跳過上傳階段。 您只需使用google.colab包就可以獲得與本地環境類似的行為。 將您需要的所有文件上傳到Google雲端硬盤,然后只需導入:

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

在身份驗證部分之后,您將能夠訪問存儲在Google雲端硬盤中的所有文件。 它們將在您上傳它們時導入,因此您只需以這種方式修改最后一行:

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

或以這種方式:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM