Last active
June 16, 2019 18:59
-
-
Save sheremetyev/ffa8d1ca1559379c0e99e5bc20d05369 to your computer and use it in GitHub Desktop.
jupyter.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "jupyter.ipynb", | |
"version": "0.3.2", | |
"provenance": [], | |
"private_outputs": true, | |
"collapsed_sections": [], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"accelerator": "GPU" | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/sheremetyev/ffa8d1ca1559379c0e99e5bc20d05369/jupyter.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"metadata": { | |
"id": "pRl2pz6lhebt", | |
"colab_type": "text" | |
}, | |
"cell_type": "markdown", | |
"source": [ | |
"# Run Jupyter Notebook\n", | |
"\n", | |
"Colab uses custom version of Jupyter which has different keyboard shortcuts and breaks some features (e.g. display of widgets). This notebook starts vanilla version of Jupyter which doesn't have these problems. Don't forget to enable GPU in **Edit->Notebook Settings** before running the code." | |
] | |
}, | |
{ | |
"metadata": { | |
"id": "2qdU1KGyixmY", | |
"colab_type": "text" | |
}, | |
"cell_type": "markdown", | |
"source": [ | |
"Clone Fast.ai course repository for convenience. This is optional - you can also upload notebooks one by one later." | |
] | |
}, | |
{ | |
"metadata": { | |
"id": "XQwzavmBg2NY", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"cell_type": "code", | |
"source": [ | |
"!git clone https://github.com/fastai/course-v3.git" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"id": "EOARWzzSjK4Y", | |
"colab_type": "text" | |
}, | |
"cell_type": "markdown", | |
"source": [ | |
"Install fastai library." | |
] | |
}, | |
{ | |
"metadata": { | |
"id": "8Eir2G3YjHk-", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"cell_type": "code", | |
"source": [ | |
"!pip install fastai --upgrade" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"id": "yVuA6OMcjYCM", | |
"colab_type": "text" | |
}, | |
"cell_type": "markdown", | |
"source": [ | |
"Upgrade Jupyter - default version fails to open some notebooks." | |
] | |
}, | |
{ | |
"metadata": { | |
"id": "0tQOAPUzjOXM", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"cell_type": "code", | |
"source": [ | |
"!pip install notebook --upgrade" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"id": "LdW_qsUjjeJ4", | |
"colab_type": "text" | |
}, | |
"cell_type": "markdown", | |
"source": [ | |
"Enable widgets in Jupyter." | |
] | |
}, | |
{ | |
"metadata": { | |
"id": "n2b3ZSobjb50", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"cell_type": "code", | |
"source": [ | |
"!jupyter nbextension enable --py widgetsnbextension" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"id": "NdfKM0N6jl2d", | |
"colab_type": "text" | |
}, | |
"cell_type": "markdown", | |
"source": [ | |
"Start Jupyter Notebook in background, listening on port 6006." | |
] | |
}, | |
{ | |
"metadata": { | |
"id": "tCEVeQCgjjCc", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"cell_type": "code", | |
"source": [ | |
"get_ipython().system_raw('jupyter-notebook --ip=0.0.0.0 --port=6006 --no-browser >& jupyter-notebook.log &')" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"id": "FyNBa2PKj0_y", | |
"colab_type": "text" | |
}, | |
"cell_type": "markdown", | |
"source": [ | |
"Download and start ngrok to forward connection to Jupyter." | |
] | |
}, | |
{ | |
"metadata": { | |
"id": "8569D7fIjx8S", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"cell_type": "code", | |
"source": [ | |
"!wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip\n", | |
"!unzip ngrok-stable-linux-amd64.zip\n", | |
"get_ipython().system_raw('./ngrok http 6006 &')" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"id": "QPDAk_VBkF1-", | |
"colab_type": "text" | |
}, | |
"cell_type": "markdown", | |
"source": [ | |
"Get URL of the forwarded connection." | |
] | |
}, | |
{ | |
"metadata": { | |
"id": "8xJLT8g-j_lj", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"cell_type": "code", | |
"source": [ | |
"!curl -s http://localhost:4040/api/tunnels | python3 -c \"import sys, json; print(json.load(sys.stdin)['tunnels'][0]['public_url'])\"" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"id": "ghWFN1d3kU0x", | |
"colab_type": "text" | |
}, | |
"cell_type": "markdown", | |
"source": [ | |
"Now just open the URL shown above and use Jupyter as usual. Course notebooks are in `course-v3/nbs/dl1` folder. By default data fill be stored in that folder as well." | |
] | |
}, | |
{ | |
"metadata": { | |
"id": "pSkOkvu_kt8z", | |
"colab_type": "text" | |
}, | |
"cell_type": "markdown", | |
"source": [ | |
"Note that Colab terminates session after 12 hours or after 90 minutes of inactivity. All local data is lost after session is terminated. If you'd like to preserve any data or notebooks then mount Google Drive and store files in `gdrive/My Drive` folder." | |
] | |
}, | |
{ | |
"metadata": { | |
"id": "Nu0hCgNAkQfB", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"cell_type": "code", | |
"source": [ | |
"#from google.colab import drive\n", | |
"#drive.mount('/content/gdrive', force_remount=True)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment