Skip to content

Commit

Permalink
Make notebook 13 runnable in Colab without changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ageron committed Nov 6, 2019
1 parent 991d98f commit 1f43973
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions 13_loading_and_preprocessing_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
"_This notebook contains all the sample code and solutions to the exercises in chapter 13._"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<table align=\"left\">\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/ageron/handson-ml2/blob/master/13_loading_and_preprocessing_data.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
" </td>\n",
"</table>"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -20,7 +31,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"First, let's import a few common modules, ensure MatplotLib plots figures inline and prepare a function to save the figures. We also check that Python 3.5 or later is installed (although Python 2.x may work, it is deprecated so we strongly recommend you use Python 3 instead), as well as Scikit-Learn ≥0.20 and TensorFlow ≥2.0-preview."
"First, let's import a few common modules, ensure MatplotLib plots figures inline and prepare a function to save the figures. We also check that Python 3.5 or later is installed (although Python 2.x may work, it is deprecated so we strongly recommend you use Python 3 instead), as well as Scikit-Learn ≥0.20 and TensorFlow ≥2.0."
]
},
{
Expand All @@ -37,7 +48,15 @@
"import sklearn\n",
"assert sklearn.__version__ >= \"0.20\"\n",
"\n",
"# TensorFlow ≥2.0-preview is required\n",
"try:\n",
" # %tensorflow_version only exists in Colab.\n",
" %tensorflow_version 2.x\n",
" !pip install -q -U tfx==0.15.0rc0\n",
" print(\"You can safely ignore the package incompatibility errors.\")\n",
"except Exception:\n",
" pass\n",
"\n",
"# TensorFlow ≥2.0 is required\n",
"import tensorflow as tf\n",
"from tensorflow import keras\n",
"assert tf.__version__ >= \"2.0\"\n",
Expand Down Expand Up @@ -2307,8 +2326,7 @@
"HOUSING_URL = DOWNLOAD_ROOT + \"datasets/housing/housing.tgz\"\n",
"\n",
"def fetch_housing_data(housing_url=HOUSING_URL, housing_path=HOUSING_PATH):\n",
" if not os.path.isdir(housing_path):\n",
" os.makedirs(housing_path)\n",
" os.makedirs(housing_path, exist_ok=True)\n",
" tgz_path = os.path.join(housing_path, \"housing.tgz\")\n",
" urllib.request.urlretrieve(housing_url, tgz_path)\n",
" housing_tgz = tarfile.open(tgz_path)\n",
Expand Down Expand Up @@ -2966,18 +2984,6 @@
"model.fit(mnist_train, steps_per_epoch=60000 // 32, epochs=5)"
]
},
{
"cell_type": "code",
"execution_count": 110,
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" datasets = tfds.load(\"imagenet2012\", split=[\"train\", \"test\"])\n",
"except AssertionError as ex:\n",
" print(ex)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -2987,7 +2993,7 @@
},
{
"cell_type": "code",
"execution_count": 111,
"execution_count": 110,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -3027,7 +3033,7 @@
},
{
"cell_type": "code",
"execution_count": 112,
"execution_count": 111,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -3037,7 +3043,7 @@
},
{
"cell_type": "code",
"execution_count": 113,
"execution_count": 112,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -3080,7 +3086,7 @@
" -4.97694984e-02, -1.07776590e-01]], dtype=float32)>"
]
},
"execution_count": 113,
"execution_count": 112,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -3113,7 +3119,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.7.3"
},
"nav_menu": {
"height": "264px",
Expand Down

0 comments on commit 1f43973

Please sign in to comment.