python - 将文件从 kaggle 上传到谷歌驱动器
问题描述
我正在使用 kaggle 训练模型,一旦训练完成,我想将训练后的模型上传到谷歌驱动器,因为我无法找到在本地下载模型的方法。在执行 pip install pydrive 之后,我研究了使用https://pythonhosted.org/PyDrive/我尝试进行身份验证
import os
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from oauth2client.client import GoogleCredentials
然后
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
我收到此错误 ApplicationDefaultCredentialsError:应用程序默认凭据不可用。如果在 Google Compute Engine 中运行,它们就可用。否则,必须定义环境变量 GOOGLE_APPLICATION_CREDENTIALS 指向定义凭据的文件。有关详细信息,请参阅https://developers.google.com/accounts/docs/application-default-credentials。
还有另一种方法可以做到这一点吗?
此外,当我手动停止训练时,我还没有在 kaggle 中提交我的文件,因此提交将永远持续下去,并且在我尝试提交并停止输出区域中的提交后,我得到了超过 6 个子目录的错误
解决方案
我遇到了同样的问题,并且能够从Kaggle
to下载文件Colab
然后移动到Google Drive
. 例如,如果当前目录是/kaggle/working
并且要移动的文件是processed_file.zip
then,
来自 Kaggle
from IPython.display import FileLink
FileLink(r'processed_file.zip')
这将生成一个链接,
https://....kaggle.net/...../processed_file.zip
来自 Colab
!wget "https://....kaggle.net/...../processed_file.zip"
挂载 Google 云端硬盘
from google.colab import drive
drive.mount('/content/drive')
将文件复制到 Google 云端硬盘
!cp "/content/processed_file.zip" "/content/drive/My Drive/workspace"
推荐阅读
- common-lisp - Lisp plist 仅在符号的属性列表单元格的上下文中?
- javascript - 点击事件上的 jQuery Mobile listview 小部件不会为 Mobile 触发
- vba - VBA代码根据页码更改多个文件中的单词页脚
- keyboard - ERGODOX - ORYX 中的下划线字符在哪里?
- r - 如何在r中纵向连接/附加数据框的列
- kotlin - 这段代码中关于 Kotlin 的 lambda 的语法是什么?
- multithreading - 当线程被调度在不同的 CPU 内核上时,预期的内存语义(例如写入后读取)会发生什么情况?
- python-3.x - Python 中的动态类创建:TypeError: __init__() 采用 1 个位置参数,但给出了 2 个
- python - 使用 Python Selenium webdriver 时出现站点阻塞和验证码
- python - 访问下拉菜单中的选项时获取“StaleElementReferenceException”