Skip to content

Instantly share code, notes, and snippets.

@ioannisa
Created December 8, 2018 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ioannisa/9a343f776e9b3813d0fc2357bf7b7d7d to your computer and use it in GitHub Desktop.
Save ioannisa/9a343f776e9b3813d0fc2357bf7b7d7d to your computer and use it in GitHub Desktop.
hangouts-demo.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "hangouts-demo.ipynb",
"version": "0.3.2",
"provenance": [],
"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/ioannisa/9a343f776e9b3813d0fc2357bf7b7d7d/hangouts-demo.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"metadata": {
"id": "7-2Fnmn6d5-N",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"#####by [Ioannis Anifantakis](https://anifantakis.eu)\n",
"#####related [YouTube video](https://www.youtube.com/watch?v=TUpEg_BnkYg)\n",
"\n",
"# Start using Colaboratory in Google Drive\n",
"* Create a folder in Google Drive, name it as you like\n",
"* **Right-click > More**\n",
"* Select **Colaboratory**\n",
" * *if you don't see \"Colaboratory\" in available options*\n",
" * select **+ Connect more apps**\n",
" * On the window that opens, search for **Colaboratory**\n",
" * Finally, click on **Connect**\n",
"\n",
"\n",
"# Enable GPU on Colab\n",
"\n",
"###Method 1\n",
"* Go to **Edit -> Notebook settings**\n",
"* On **Hardware accelerator** select **GPU**\n",
"\n",
"###Method 2\n",
"* Go to **Runtime -> Change runtime type**\n",
"* On **Hardware accelerator** select **GPU**\n",
"\n",
"\n",
"# ADD PYTORCH ON COLAB\n",
"\n",
"Add the below code, or just\n",
"\n",
"* open the left sidebar at colab\n",
"* Go to **Code snippets**\n",
"* On **Filter code snippets** type **pytorch**\n",
"* Add the snippet to your notebook\n",
"\n"
]
},
{
"metadata": {
"id": "SxAcq3r-W9jJ",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"# http://pytorch.org/\n",
"from os.path import exists\n",
"from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag\n",
"platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag())\n",
"cuda_output = !ldconfig -p|grep cudart.so|sed -e 's/.*\\.\\([0-9]*\\)\\.\\([0-9]*\\)$/cu\\1\\2/'\n",
"accelerator = cuda_output[0] if exists('/dev/nvidia0') else 'cpu'\n",
"\n",
"!pip install -q http://download.pytorch.org/whl/{accelerator}/torch-0.4.1-{platform}-linux_x86_64.whl torchvision\n",
"import torch"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "7QU73LXxeQg5",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"# DOWNLOAD (Flower Data) to Temporary Storage"
]
},
{
"metadata": {
"id": "62SxzQK0eURo",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"import requests\n",
"\n",
"url = 'https://s3.amazonaws.com/content.udacity-data.com/courses/nd188/flower_data.zip'\n",
"target_path = 'flowers_train.zip'\n",
"\n",
"response = requests.get(url, stream=True)\n",
"handle = open(target_path, \"wb\")\n",
"for chunk in response.iter_content(chunk_size=512):\n",
" if chunk: # filter out keep-alive new chunks\n",
" handle.write(chunk)\n",
"handle.close()"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "BgoRLpnzOZdL",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"Unzip the downloaded file (from the temporary storage), into the temporary storage"
]
},
{
"metadata": {
"id": "a78dXDIdeW-q",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"!unzip flowers_train.zip"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "IbK8-iNieC3A",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"# MOUNT GOOGLE DRIVE\n",
"\n",
"It is just two lines of code!\n",
"But when you request access to of colaboratory to Google Drive, you need to verify this access.\n",
"So executing the \"mount\" command will prompt you with a link that generates an access token that you simply have to paste to continue using colab with access on Google Drive.\n",
"\n",
"It is easier than it sounds...\n",
"\n",
"Good luck!"
]
},
{
"metadata": {
"id": "SDAvScPReETn",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"from google.colab import drive\n",
"drive.mount('/content/drive')"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "weP62CwMebXa",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"# DOWNLOAD (Flower Data) to Google Drive (permanent storage)\n",
"\n",
"However, I suggest not using the google drive for cases like the flower data, as it will take considerably more time to test over drive data compared to the temporary vm storage. Flower data is 8.000 pictures.\n",
"\n",
"I have seen in many cases that reading the flower data for each epoch from Google Drive is several times slower than reading it from the temporary location.\n",
"\n",
"Use the Google Drive storage for small (and few) files, or to save/load your model."
]
},
{
"metadata": {
"id": "AW0lnJ4zek6c",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"!wget https://s3.amazonaws.com/content.udacity-data.com/courses/nd188/flower_data.zip -P \"drive/My Drive/Colab/challenge_project\""
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "pUheTAhpeomk",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"!unzip \"drive/My Drive/Colab/challenge_project/flower_data.zip\" -d \"drive/My Drive/Colab/challenge_project/\""
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "Cf0kZxF2e_5k",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"# **DOWNLOAD GITHUB REPO (Course Data) to Google Drive**"
]
},
{
"metadata": {
"id": "jJc5Q1xXfFz4",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"!git clone https://github.com/udacity/deep-learning-v2-pytorch.git \"drive/My Drive/Colab/course-content/\""
],
"execution_count": 0,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment