问题
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