【问题标题】:Get the path of the notebook on Google Colab在 Google Colab 上获取 notebook 的路径
【发布时间】:2023-03-20 21:25:01
【问题描述】:

我正在尝试在Google Colab 笔记本中使用hyperas(keras 的超参数优化),我已经成功安装了 hyperas:

!pip install hyperas

但是minimize函数参数notebook_name有问题,使用笔记本时必须设置

此参数必须填写笔记本的路径,但在 Colab 中我不知道如何获取它

【问题讨论】:

  • 您是否尝试过直接输入笔记本名称?我认为colab应该在jupyter notebook所在的目录下运行。
  • 是的,我试过了,但没用 :( 它说 FileNotFoundError,我需要整个路径

标签: path jupyter-notebook google-colaboratory


【解决方案1】:

接受的答案对我不起作用。这是我的解决方案。 colab 分配的目录是/content/。您需要从 google drive 下载当前笔记本并将其上传到 /content/。

【讨论】:

  • 这不是好的解决方案。我之前为 geckodriver.exe 尝试过,但没有成功。
【解决方案2】:

您可以从 Google 云端硬盘复制 notebook.ipybn。然后hyperas 可以从中提取信息。

# Install the PyDrive wrapper & import libraries.
!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials

# Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

# Copy/download the file
fid = drive.ListFile({'q':"title='notebook.ipynb'"}).GetList()[0]['id']
f = drive.CreateFile({'id': fid})
f.GetContentFile('notebook.ipynb')

【讨论】:

  • 太棒了!它是这样工作的,非常感谢您的回答:)
最近更新 更多