2

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

Luis Sobrecueva
  • 680
  • 1
  • 6
  • 13
  • Have you tried to type in the notebook name directly? I think colab should be running in the directory where the jupyter notebook is in. – TYZ Apr 19 '18 at 13:18
  • yes, I tried and it didn't work :( It says FileNotFoundError, I'd need the whole path – Luis Sobrecueva Apr 19 '18 at 14:29

2 Answers2

4

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')
korakot
  • 37,818
  • 16
  • 123
  • 144
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/.

Sean
  • 197
  • 2
  • 7