Remove transpose conv section, fix python 3.7->3.8, small tweaks

main
Aurélien Geron 2022-01-31 11:10:02 +13:00
parent 9bd3b4ad9a
commit a18cb82f34
1 changed files with 22 additions and 26 deletions

View File

@ -63,7 +63,7 @@
"source": [
"import sys\n",
"\n",
"assert sys.version_info >= (3, 7)"
"assert sys.version_info >= (3, 8)"
]
},
{
@ -557,7 +557,7 @@
},
"outputs": [],
"source": [
"# extra code this cells generates and saves Figure 149\n",
"# extra code this cells shows what max pooling with stride = 2 looks like\n",
"\n",
"import matplotlib as mpl\n",
"\n",
@ -572,7 +572,6 @@
"ax2.set_title(\"Output\", fontsize=14)\n",
"ax2.imshow(output[0]) # plot the output for the 1st image\n",
"ax2.axis(\"off\")\n",
"save_fig(\"china_max_pooling\")\n",
"plt.show()"
]
},
@ -1436,21 +1435,6 @@
{
"cell_type": "code",
"execution_count": 57,
"metadata": {
"id": "E0XZoWKjpKz_"
},
"outputs": [],
"source": [
"def add_random_bounding_boxes(images, labels):\n",
" fake_bboxes = tf.random.uniform([tf.shape(images)[0], 4])\n",
" return images, (labels, fake_bboxes)\n",
"\n",
"fake_train_set = train_set.take(5).repeat(2).map(add_random_bounding_boxes)"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@ -1460,6 +1444,14 @@
},
"outputs": [],
"source": [
"# extra code fits the model using random target bounding boxes (in real life\n",
"# you would need to create proper targets instead)\n",
"\n",
"def add_random_bounding_boxes(images, labels):\n",
" fake_bboxes = tf.random.uniform([tf.shape(images)[0], 4])\n",
" return images, (labels, fake_bboxes)\n",
"\n",
"fake_train_set = train_set.take(5).repeat(2).map(add_random_bounding_boxes)\n",
"model.fit(fake_train_set, epochs=2)"
]
},
@ -1474,7 +1466,7 @@
},
{
"cell_type": "code",
"execution_count": 59,
"execution_count": 58,
"metadata": {
"id": "fgjxsrkLpKz_"
},
@ -1486,7 +1478,7 @@
},
{
"cell_type": "code",
"execution_count": 60,
"execution_count": 59,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
@ -1579,7 +1571,7 @@
},
{
"cell_type": "code",
"execution_count": 61,
"execution_count": 60,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@ -1589,7 +1581,8 @@
},
"outputs": [],
"source": [
"(X_train_full, y_train_full), (X_test, y_test) = tf.keras.datasets.mnist.load_data()\n",
"mnist = tf.keras.datasets.mnist.load_data()\n",
"(X_train_full, y_train_full), (X_test, y_test) = mnist\n",
"X_train_full = X_train_full / 255.\n",
"X_test = X_test / 255.\n",
"X_train, X_valid = X_train_full[:-5000], X_train_full[-5000:]\n",
@ -1602,7 +1595,7 @@
},
{
"cell_type": "code",
"execution_count": 62,
"execution_count": 61,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@ -1617,12 +1610,15 @@
"np.random.seed(42)\n",
"\n",
"model = tf.keras.Sequential([\n",
" tf.keras.layers.Conv2D(32, kernel_size=3, padding=\"same\", activation=\"relu\"),\n",
" tf.keras.layers.Conv2D(64, kernel_size=3, padding=\"same\", activation=\"relu\"),\n",
" tf.keras.layers.Conv2D(32, kernel_size=3, padding=\"same\",\n",
" activation=\"relu\", kernel_initializer=\"he_normal\"),\n",
" tf.keras.layers.Conv2D(64, kernel_size=3, padding=\"same\",\n",
" activation=\"relu\", kernel_initializer=\"he_normal\"),\n",
" tf.keras.layers.MaxPool2D(),\n",
" tf.keras.layers.Flatten(),\n",
" tf.keras.layers.Dropout(0.25),\n",
" tf.keras.layers.Dense(128, activation=\"relu\"),\n",
" tf.keras.layers.Dense(128, activation=\"relu\",\n",
" kernel_initializer=\"he_normal\"),\n",
" tf.keras.layers.Dropout(0.5),\n",
" tf.keras.layers.Dense(10, activation=\"softmax\")\n",
"])\n",