Skip to content

Commit

Permalink
Created using Colaboratory
Browse files Browse the repository at this point in the history
  • Loading branch information
rstager committed Jan 23, 2020
1 parent 3596d05 commit 115b573
Showing 1 changed file with 166 additions and 0 deletions.
166 changes: 166 additions & 0 deletions pytorch_tutorial1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "pytorch_tutorial1.ipynb",
"provenance": [],
"authorship_tag": "ABX9TyPKLLjECvMJ707vhHjRLNLR",
"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/github/EastbayML/pytorch_tutorial/blob/master/pytorch_tutorial1.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "t5i_26lOZ3nU",
"colab_type": "text"
},
"source": [
"\n",
"East Bay Machine Learning pytorch tutorial series.\n",
"\n",
"---\n",
"\n",
"We will use this notebook as the launch point for our pytorch tutorial series.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "WxpEAveycl2y",
"colab_type": "text"
},
"source": [
"We willl used a google doc as a shared online whiteboard. \n",
"https://docs.google.com/document/d/1N-5Ue0rk7g8CImayet-cgnaCkHJzXky7aeHrwUocXEM/edit?usp=sharing"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "nfKyRKincd7P",
"colab_type": "text"
},
"source": [
"To enable GPU hardware accelerator, just go to Runtime -> Change runtime type -> Hardware accelerator -> GPU"
]
},
{
"cell_type": "code",
"metadata": {
"id": "Fvf8AG2BbTkx",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 187
},
"outputId": "f68bd44a-1fac-405f-8abe-79bd08461eb9"
},
"source": [
"from __future__ import print_function\n",
"import torch\n",
"if torch.cuda.is_available():\n",
" device = torch.device(\"cuda\") # a CUDA device object\n",
" x = torch.empty(5, 3)\n",
" y = torch.ones_like(x, device=device) # directly create a tensor on GPU\n",
" x = x.to(device) # or just use strings ``.to(\"cuda\")``\n",
" z = x + y\n",
" print(z)\n",
" print(z.to(\"cpu\", torch.double))\n",
"else:\n",
" print(\"Cuda not available.\")"
],
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"text": [
"tensor([[1., 1., 1.],\n",
" [1., 1., 1.],\n",
" [1., 1., 1.],\n",
" [1., 1., 1.],\n",
" [1., 1., 1.]], device='cuda:0')\n",
"tensor([[1., 1., 1.],\n",
" [1., 1., 1.],\n",
" [1., 1., 1.],\n",
" [1., 1., 1.],\n",
" [1., 1., 1.]], dtype=torch.float64)\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "Cxu3FaMgdSDL",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 260
},
"outputId": "c8bf0972-134f-4e31-9e69-1aeb1b79321c"
},
"source": [
"import pydot, graphviz\n",
"from keras.utils import plot_model\n",
"plot_model(model, to_file='model.png')"
],
"execution_count": 3,
"outputs": [
{
"output_type": "stream",
"text": [
"Using TensorFlow backend.\n"
],
"name": "stderr"
},
{
"output_type": "display_data",
"data": {
"text/html": [
"<p style=\"color: red;\">\n",
"The default version of TensorFlow in Colab will soon switch to TensorFlow 2.x.<br>\n",
"We recommend you <a href=\"https://www.tensorflow.org/guide/migrate\" target=\"_blank\">upgrade</a> now \n",
"or ensure your notebook will continue to use TensorFlow 1.x via the <code>%tensorflow_version 1.x</code> magic:\n",
"<a href=\"https://colab.research.google.com/notebooks/tensorflow_version.ipynb\" target=\"_blank\">more info</a>.</p>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {
"tags": []
}
},
{
"output_type": "error",
"ename": "NameError",
"evalue": "ignored",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-3-edaa5e034957>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mpydot\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgraphviz\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mkeras\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mutils\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mplot_model\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mplot_model\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mto_file\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'model.png'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'model' is not defined"
]
}
]
}
]
}

0 comments on commit 115b573

Please sign in to comment.