Skip to content

Commit 3d28172

Browse files
committed
formatting
1 parent f49de47 commit 3d28172

File tree

23 files changed

+1313
-351
lines changed

23 files changed

+1313
-351
lines changed

docker/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ FROM ubuntu:20.04
33
ENV DEBIAN_FRONTEND noninteractive
44

55
RUN apt-get update
6-
RUN apt-get -y upgrade
76
RUN apt-get install -y unzip graphviz curl musescore3 python3-pip
87

98
RUN pip install --upgrade pip

notebooks/02_deeplearning/01_mlp/mlp.ipynb

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@
126126
"outputs": [],
127127
"source": [
128128
"opt = optimizers.Adam(learning_rate=0.0005)\n",
129-
"model.compile(loss=\"categorical_crossentropy\", optimizer=opt, metrics=[\"accuracy\"])"
129+
"model.compile(\n",
130+
" loss=\"categorical_crossentropy\", optimizer=opt, metrics=[\"accuracy\"]\n",
131+
")"
130132
]
131133
},
132134
{
@@ -162,7 +164,20 @@
162164
"metadata": {},
163165
"outputs": [],
164166
"source": [
165-
"CLASSES = np.array([\"airplane\", \"automobile\", \"bird\", \"cat\", \"deer\", \"dog\", \"frog\", \"horse\", \"ship\", \"truck\"])\n",
167+
"CLASSES = np.array(\n",
168+
" [\n",
169+
" \"airplane\",\n",
170+
" \"automobile\",\n",
171+
" \"bird\",\n",
172+
" \"cat\",\n",
173+
" \"deer\",\n",
174+
" \"dog\",\n",
175+
" \"frog\",\n",
176+
" \"horse\",\n",
177+
" \"ship\",\n",
178+
" \"truck\",\n",
179+
" ]\n",
180+
")\n",
166181
"\n",
167182
"preds = model.predict(x_test)\n",
168183
"preds_single = CLASSES[np.argmax(preds, axis=-1)]\n",
@@ -187,8 +202,22 @@
187202
" img = x_test[idx]\n",
188203
" ax = fig.add_subplot(1, n_to_show, i + 1)\n",
189204
" ax.axis(\"off\")\n",
190-
" ax.text(0.5, -0.35, \"pred = \" + str(preds_single[idx]), fontsize=10, ha=\"center\", transform=ax.transAxes)\n",
191-
" ax.text(0.5, -0.7, \"act = \" + str(actual_single[idx]), fontsize=10, ha=\"center\", transform=ax.transAxes)\n",
205+
" ax.text(\n",
206+
" 0.5,\n",
207+
" -0.35,\n",
208+
" \"pred = \" + str(preds_single[idx]),\n",
209+
" fontsize=10,\n",
210+
" ha=\"center\",\n",
211+
" transform=ax.transAxes,\n",
212+
" )\n",
213+
" ax.text(\n",
214+
" 0.5,\n",
215+
" -0.7,\n",
216+
" \"act = \" + str(actual_single[idx]),\n",
217+
" fontsize=10,\n",
218+
" ha=\"center\",\n",
219+
" transform=ax.transAxes,\n",
220+
" )\n",
192221
" ax.imshow(img)"
193222
]
194223
}

notebooks/02_deeplearning/02_cnn/cnn.ipynb

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@
9898
"source": [
9999
"input_layer = layers.Input((32, 32, 3))\n",
100100
"\n",
101-
"x = layers.Conv2D(filters=32, kernel_size=3, strides=1, padding=\"same\")(input_layer)\n",
101+
"x = layers.Conv2D(filters=32, kernel_size=3, strides=1, padding=\"same\")(\n",
102+
" input_layer\n",
103+
")\n",
102104
"x = layers.BatchNormalization()(x)\n",
103105
"x = layers.LeakyReLU()(x)\n",
104106
"\n",
@@ -145,7 +147,9 @@
145147
"outputs": [],
146148
"source": [
147149
"opt = optimizers.Adam(learning_rate=0.0005)\n",
148-
"model.compile(loss=\"categorical_crossentropy\", optimizer=opt, metrics=[\"accuracy\"])"
150+
"model.compile(\n",
151+
" loss=\"categorical_crossentropy\", optimizer=opt, metrics=[\"accuracy\"]\n",
152+
")"
149153
]
150154
},
151155
{
@@ -156,7 +160,14 @@
156160
},
157161
"outputs": [],
158162
"source": [
159-
"model.fit(x_train, y_train, batch_size=32, epochs=10, shuffle=True, validation_data=(x_test, y_test))"
163+
"model.fit(\n",
164+
" x_train,\n",
165+
" y_train,\n",
166+
" batch_size=32,\n",
167+
" epochs=10,\n",
168+
" shuffle=True,\n",
169+
" validation_data=(x_test, y_test),\n",
170+
")"
160171
]
161172
},
162173
{
@@ -183,7 +194,20 @@
183194
"metadata": {},
184195
"outputs": [],
185196
"source": [
186-
"CLASSES = np.array([\"airplane\", \"automobile\", \"bird\", \"cat\", \"deer\", \"dog\", \"frog\", \"horse\", \"ship\", \"truck\"])\n",
197+
"CLASSES = np.array(\n",
198+
" [\n",
199+
" \"airplane\",\n",
200+
" \"automobile\",\n",
201+
" \"bird\",\n",
202+
" \"cat\",\n",
203+
" \"deer\",\n",
204+
" \"dog\",\n",
205+
" \"frog\",\n",
206+
" \"horse\",\n",
207+
" \"ship\",\n",
208+
" \"truck\",\n",
209+
" ]\n",
210+
")\n",
187211
"\n",
188212
"preds = model.predict(x_test)\n",
189213
"preds_single = CLASSES[np.argmax(preds, axis=-1)]\n",
@@ -208,8 +232,22 @@
208232
" img = x_test[idx]\n",
209233
" ax = fig.add_subplot(1, n_to_show, i + 1)\n",
210234
" ax.axis(\"off\")\n",
211-
" ax.text(0.5, -0.35, \"pred = \" + str(preds_single[idx]), fontsize=10, ha=\"center\", transform=ax.transAxes)\n",
212-
" ax.text(0.5, -0.7, \"act = \" + str(actual_single[idx]), fontsize=10, ha=\"center\", transform=ax.transAxes)\n",
235+
" ax.text(\n",
236+
" 0.5,\n",
237+
" -0.35,\n",
238+
" \"pred = \" + str(preds_single[idx]),\n",
239+
" fontsize=10,\n",
240+
" ha=\"center\",\n",
241+
" transform=ax.transAxes,\n",
242+
" )\n",
243+
" ax.text(\n",
244+
" 0.5,\n",
245+
" -0.7,\n",
246+
" \"act = \" + str(actual_single[idx]),\n",
247+
" fontsize=10,\n",
248+
" ha=\"center\",\n",
249+
" transform=ax.transAxes,\n",
250+
" )\n",
213251
" ax.imshow(img)"
214252
]
215253
}

notebooks/03_vae/01_autoencoder/autoencoder.ipynb

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,12 @@
131131
"outputs": [],
132132
"source": [
133133
"# Encoder\n",
134-
"encoder_input = layers.Input(shape=(IMAGE_SIZE, IMAGE_SIZE, CHANNELS), name=\"encoder_input\")\n",
135-
"x = layers.Conv2D(32, (3, 3), strides=2, activation=\"relu\", padding=\"same\")(encoder_input)\n",
134+
"encoder_input = layers.Input(\n",
135+
" shape=(IMAGE_SIZE, IMAGE_SIZE, CHANNELS), name=\"encoder_input\"\n",
136+
")\n",
137+
"x = layers.Conv2D(32, (3, 3), strides=2, activation=\"relu\", padding=\"same\")(\n",
138+
" encoder_input\n",
139+
")\n",
136140
"x = layers.Conv2D(64, (3, 3), strides=2, activation=\"relu\", padding=\"same\")(x)\n",
137141
"x = layers.Conv2D(128, (3, 3), strides=2, activation=\"relu\", padding=\"same\")(x)\n",
138142
"shape_before_flattening = K.int_shape(x)[1:] # the decoder will need this!\n",
@@ -155,11 +159,22 @@
155159
"decoder_input = layers.Input(shape=(EMBEDDING_DIM,), name=\"decoder_input\")\n",
156160
"x = layers.Dense(np.prod(shape_before_flattening))(decoder_input)\n",
157161
"x = layers.Reshape(shape_before_flattening)(x)\n",
158-
"x = layers.Conv2DTranspose(128, (3, 3), strides=2, activation=\"relu\", padding=\"same\")(x)\n",
159-
"x = layers.Conv2DTranspose(64, (3, 3), strides=2, activation=\"relu\", padding=\"same\")(x)\n",
160-
"x = layers.Conv2DTranspose(32, (3, 3), strides=2, activation=\"relu\", padding=\"same\")(x)\n",
162+
"x = layers.Conv2DTranspose(\n",
163+
" 128, (3, 3), strides=2, activation=\"relu\", padding=\"same\"\n",
164+
")(x)\n",
165+
"x = layers.Conv2DTranspose(\n",
166+
" 64, (3, 3), strides=2, activation=\"relu\", padding=\"same\"\n",
167+
")(x)\n",
168+
"x = layers.Conv2DTranspose(\n",
169+
" 32, (3, 3), strides=2, activation=\"relu\", padding=\"same\"\n",
170+
")(x)\n",
161171
"decoder_output = layers.Conv2D(\n",
162-
" CHANNELS, (3, 3), strides=1, activation=\"sigmoid\", padding=\"same\", name=\"decoder_output\"\n",
172+
" CHANNELS,\n",
173+
" (3, 3),\n",
174+
" strides=1,\n",
175+
" activation=\"sigmoid\",\n",
176+
" padding=\"same\",\n",
177+
" name=\"decoder_output\",\n",
163178
")(x)\n",
164179
"\n",
165180
"decoder = models.Model(decoder_input, decoder_output)\n",
@@ -174,7 +189,9 @@
174189
"outputs": [],
175190
"source": [
176191
"# Autoencoder\n",
177-
"autoencoder = models.Model(encoder_input, decoder(encoder_output)) # decoder(encoder_output)\n",
192+
"autoencoder = models.Model(\n",
193+
" encoder_input, decoder(encoder_output)\n",
194+
") # decoder(encoder_output)\n",
178195
"autoencoder.summary()"
179196
]
180197
},
@@ -344,7 +361,14 @@
344361
"\n",
345362
"figsize = 8\n",
346363
"plt.figure(figsize=(figsize, figsize))\n",
347-
"plt.scatter(embeddings[:, 0], embeddings[:, 1], cmap=\"rainbow\", c=example_labels, alpha=0.8, s=3)\n",
364+
"plt.scatter(\n",
365+
" embeddings[:, 0],\n",
366+
" embeddings[:, 1],\n",
367+
" cmap=\"rainbow\",\n",
368+
" c=example_labels,\n",
369+
" alpha=0.8,\n",
370+
" s=3,\n",
371+
")\n",
348372
"plt.colorbar()\n",
349373
"plt.show()"
350374
]
@@ -369,7 +393,9 @@
369393
"\n",
370394
"# Sample some points in the latent space\n",
371395
"grid_width, grid_height = (6, 3)\n",
372-
"sample = np.random.uniform(mins, maxs, size=(grid_width * grid_height, EMBEDDING_DIM))"
396+
"sample = np.random.uniform(\n",
397+
" mins, maxs, size=(grid_width * grid_height, EMBEDDING_DIM)\n",
398+
")"
373399
]
374400
},
375401
{
@@ -408,7 +434,14 @@
408434
"for i in range(grid_width * grid_height):\n",
409435
" ax = fig.add_subplot(grid_height, grid_width, i + 1)\n",
410436
" ax.axis(\"off\")\n",
411-
" ax.text(0.5, -0.35, str(np.round(sample[i, :], 1)), fontsize=10, ha=\"center\", transform=ax.transAxes)\n",
437+
" ax.text(\n",
438+
" 0.5,\n",
439+
" -0.35,\n",
440+
" str(np.round(sample[i, :], 1)),\n",
441+
" fontsize=10,\n",
442+
" ha=\"center\",\n",
443+
" transform=ax.transAxes,\n",
444+
" )\n",
412445
" ax.imshow(reconstructions[i, :, :], cmap=\"Greys\")"
413446
]
414447
},
@@ -423,7 +456,14 @@
423456
"figsize = 12\n",
424457
"grid_size = 15\n",
425458
"plt.figure(figsize=(figsize, figsize))\n",
426-
"plt.scatter(embeddings[:, 0], embeddings[:, 1], cmap=\"rainbow\", c=example_labels, alpha=0.8, s=300)\n",
459+
"plt.scatter(\n",
460+
" embeddings[:, 0],\n",
461+
" embeddings[:, 1],\n",
462+
" cmap=\"rainbow\",\n",
463+
" c=example_labels,\n",
464+
" alpha=0.8,\n",
465+
" s=300,\n",
466+
")\n",
427467
"plt.colorbar()\n",
428468
"\n",
429469
"x = np.linspace(min(embeddings[:, 0]), max(embeddings[:, 0]), grid_size)\n",

0 commit comments

Comments
 (0)