Skip to content

Commit

Permalink
Update week 2 assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitry-ishenko committed Mar 28, 2020
1 parent c283180 commit 2578ab3
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 299 deletions.
2 changes: 1 addition & 1 deletion week2/preprocessed_mnist.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import keras
from tensorflow import keras


def load_dataset(flatten=False):
Expand Down
17 changes: 4 additions & 13 deletions week2/v2/digits_classification.ipynb
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# set tf 1.x for colab\n",
"%tensorflow_version 1.x"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -38,7 +28,7 @@
"from sklearn.metrics import accuracy_score\n",
"from matplotlib import pyplot as plt\n",
"%matplotlib inline\n",
"import tensorflow as tf\n",
"import tensorflow.compat.v1 as tf\n",
"print(\"We're using TF\", tf.__version__)\n",
"\n",
"import sys\n",
Expand Down Expand Up @@ -176,7 +166,7 @@
"metadata": {},
"outputs": [],
"source": [
"import keras\n",
"from tensorflow import keras\n",
"\n",
"y_train_oh = keras.utils.to_categorical(y_train, 10)\n",
"y_val_oh = keras.utils.to_categorical(y_val, 10)\n",
Expand All @@ -192,6 +182,7 @@
"outputs": [],
"source": [
"# run this again if you remake your graph\n",
"tf.disable_eager_execution()\n",
"s = reset_tf_session()"
]
},
Expand Down Expand Up @@ -398,4 +389,4 @@
},
"nbformat": 4,
"nbformat_minor": 1
}
}
6 changes: 1 addition & 5 deletions week2/v2/grading_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
# -*- coding: utf-8 -*-


def get_tensor_shape(t):
return [d.value for d in t.shape]


def get_tensors_shapes_string(tensors):
res = []
for t in tensors:
res.extend([str(v) for v in get_tensor_shape(t)])
res.extend([str(v) for v in t.shape])
return " ".join(res)
96 changes: 17 additions & 79 deletions week2/v2/ill-conditioned-demo.ipynb

Large diffs are not rendered by default.

15 changes: 3 additions & 12 deletions week2/v2/intro_to_tensorflow.ipynb
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# set tf 1.x for colab\n",
"%tensorflow_version 1.x"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -48,10 +38,11 @@
"metadata": {},
"outputs": [],
"source": [
"import tensorflow as tf\n",
"import tensorflow.compat.v1 as tf\n",
"import sys\n",
"sys.path.append(\"../..\")\n",
"from keras_utils import reset_tf_session\n",
"tf.disable_eager_execution()\n",
"s = reset_tf_session()\n",
"print(\"We're using TF\", tf.__version__)"
]
Expand Down Expand Up @@ -581,4 +572,4 @@
},
"nbformat": 4,
"nbformat_minor": 1
}
}
23 changes: 6 additions & 17 deletions week2/v2/mnist_with_keras.ipynb
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# set tf 1.x for colab\n",
"%tensorflow_version 1.x"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -46,13 +36,12 @@
"%matplotlib inline\n",
"import tensorflow as tf\n",
"print(\"We're using TF\", tf.__version__)\n",
"import keras\n",
"from tensorflow import keras\n",
"print(\"We are using Keras\", keras.__version__)\n",
"\n",
"import sys\n",
"sys.path.append(\"../..\")\n",
"import keras_utils\n",
"from keras_utils import reset_tf_session"
"import keras_utils"
]
},
{
Expand Down Expand Up @@ -127,11 +116,11 @@
"outputs": [],
"source": [
"# building a model with keras\n",
"from keras.layers import Dense, Activation\n",
"from keras.models import Sequential\n",
"from tensorflow.keras.layers import Dense, Activation\n",
"from tensorflow.keras.models import Sequential\n",
"\n",
"# we still need to clear a graph though\n",
"s = reset_tf_session()\n",
"K.clear_session()\n",
"\n",
"model = Sequential() # it is a feed-forward network without loops like in RNN\n",
"model.add(Dense(256, input_shape=(784,))) # the first layer must specify the input shape (replacing placeholders)\n",
Expand Down Expand Up @@ -259,4 +248,4 @@
},
"nbformat": 4,
"nbformat_minor": 1
}
}
2 changes: 1 addition & 1 deletion week2/v2/preprocessed_mnist.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import keras
from tensorflow import keras


def load_dataset(flatten=False):
Expand Down
Loading

0 comments on commit 2578ab3

Please sign in to comment.