在Google Colab上获取笔记本的路径 [英] Get the path of the notebook on Google Colab

查看:802
本文介绍了在Google Colab上获取笔记本的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Google Colab 笔记本,我已经成功安装了Hyperas:

I'm trying to use hyperas (hyperparameter optimization for keras) in a Google Colab notebook, I've installed hyperas sucefully with:

!pip install hyperas

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

but there is a problem with the minimize function parameter notebook_name that is mandatory to set when you are using a notebook

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

This param has to be filled with the path of the notebook but in Colab I don't know how to get it

推荐答案

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

You can copy the notebook.ipybn from Google Drive. Then hyperas can extract the info from it.

# 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')

这篇关于在Google Colab上获取笔记本的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆