有没有办法使用 google colab 从一个驱动器访问数据?

Jos*_*lde 9 onedrive google-colaboratory

我已经开始使用 google colab 来训练神经网络,但是我拥有的数据非常大(4GB 和 18GB)。我目前将所有这些数据存储在一个驱动器中,但我的 google 驱动器上没有足够的空间来传输这些文件。

有没有办法让我直接从 google colab 中的一个驱动器访问数据?

我试过直接从我自己的机器上加载数据,但是我觉得这个过程太耗时了,我的机器真的没有足够的空间来存储这些文件。我也试过在 ? 在文件的超链接中,但是这不会下载并且只显示超链接。使用 wget 时会产生“错误 403:禁止”。信息。

我希望 google colab 文件下载此压缩文件并从中解压缩数据以进行培训。

yuh*_*tao 5

好的,这是下载到colab的方法,选择文件并右键单击onedrive中的下载按钮但立即暂停

在此输入图像描述

然后进入下载界面,右键点击暂停的项目,复制链接地址 在此输入图像描述

!wget --no-check-certificate \
https://public.sn.files.1drv.com/xxx\ 
-O /content/filename.zip
Run Code Online (Sandbox Code Playgroud)

注意:几分钟后就会失效


Shu*_*hal 3

您可以使用OneDriveSDK,可在 PyPi 索引中下载。

首先,我们将使用以下命令将其安装在 Google Colab 中:

!pip install onedrivesdk
Run Code Online (Sandbox Code Playgroud)

这个过程太长,无法容纳在这里。您需要首先验证自己的身份,然后才能轻松上传/下载文件。

您可以使用此代码进行身份验证:

import onedrivesdk 

redirect_uri = 'http://localhost:8080/' client_secret = 'your_client_secret' client_id='your_client_id' api_base_url='https://api.onedrive.com/v1.0/' 
scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite'] 
http_provider = onedrivesdk.HttpProvider() 
auth_provider = onedrivesdk.AuthProvider( http_provider=http_provider, client_id=client_id, scopes=scopes) 
client = onedrivesdk.OneDriveClient(api_base_url, auth_provider, http_provider) 
auth_url = client.auth_provider.get_auth_url(redirect_uri) 

# Ask for the code 
print('Paste this URL into your browser, approve the app\'s access.') 
print('Copy everything in the address bar after "code=", and paste it below.') print(auth_url) 
code = input('Paste code here: ')  client.auth_provider.authenticate(code, redirect_uri, client_secret)
Run Code Online (Sandbox Code Playgroud)

这将产生一个代码,您需要将其粘贴到浏览器中,然后再次粘贴到控制台中以验证您自己的身份。

您可以使用以下方法下载文件:

root_folder = client.item(drive='me', id='root').children.get() 
id_of_file = root_folder[0].id client.item(drive='me', id=id_of_file).download('./path_to_file')
Run Code Online (Sandbox Code Playgroud)

  • 安装onedrivesdk时出现错误。`错误:命令出错,退出状态为 1:python setup.py Egg_info 检查日志以获取完整的命令输出。` (2认同)