Get the path of the notebook on Google Colab

折月煮酒 提交于 2020-07-15 09:36:39

问题


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

!pip install hyperas

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

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


回答1:


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



回答2:


The accepted answer does not work for me. Here is my solution. The directory assigned by colab is /content/. You need to download the current notebook from google drive and upload it to /content/.



来源:https://stackoverflow.com/questions/49920031/get-the-path-of-the-notebook-on-google-colab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!