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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "0d3774bd-5295-42ac-b0e6-4f3d3a82901a",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"import tensorflow as tf\n",
|
11 |
+
"from tensorflow import keras\n",
|
12 |
+
"from tensorflow.keras import layers\n",
|
13 |
+
"import numpy as np\n",
|
14 |
+
"import matplotlib.pyplot as plt\n",
|
15 |
+
"import os\n",
|
16 |
+
"import gdown\n",
|
17 |
+
"from zipfile import ZipFile\n"
|
18 |
+
]
|
19 |
+
},
|
20 |
+
{
|
21 |
+
"cell_type": "code",
|
22 |
+
"execution_count": 2,
|
23 |
+
"id": "4f7cd728-3373-4fb7-b595-f594b7b14525",
|
24 |
+
"metadata": {},
|
25 |
+
"outputs": [],
|
26 |
+
"source": [
|
27 |
+
"os.makedirs(\"celeba_gan\")\n",
|
28 |
+
"\n",
|
29 |
+
"url = \"https://drive.google.com/uc?id=1O7m1010EJjLE5QxLZiM9Fpjs7Oj6e684\"\n",
|
30 |
+
"output = \"celeba_gan/data.zip\"\n",
|
31 |
+
"gdown.download(url, output, quiet=True)\n",
|
32 |
+
"\n",
|
33 |
+
"with ZipFile(\"celeba_gan/data.zip\", \"r\") as zipobj:\n",
|
34 |
+
" zipobj.extractall(\"celeba_gan\")\n"
|
35 |
+
]
|
36 |
+
},
|
37 |
+
{
|
38 |
+
"cell_type": "code",
|
39 |
+
"execution_count": 4,
|
40 |
+
"id": "c74b2281-2fae-4be9-8463-0f9bba9d0c45",
|
41 |
+
"metadata": {},
|
42 |
+
"outputs": [
|
43 |
+
{
|
44 |
+
"name": "stdout",
|
45 |
+
"output_type": "stream",
|
46 |
+
"text": [
|
47 |
+
"Found 202599 files belonging to 1 classes.\n"
|
48 |
+
]
|
49 |
+
}
|
50 |
+
],
|
51 |
+
"source": [
|
52 |
+
"dataset = keras.preprocessing.image_dataset_from_directory(\n",
|
53 |
+
" \"celeba_gan\", label_mode=None, image_size=(64, 64), batch_size=32\n",
|
54 |
+
")\n",
|
55 |
+
"dataset = dataset.map(lambda x: x / 255.0)"
|
56 |
+
]
|
57 |
+
},
|
58 |
+
{
|
59 |
+
"cell_type": "code",
|
60 |
+
"execution_count": 8,
|
61 |
+
"id": "c9e9b947-45b0-456c-ba7e-914d43045f18",
|
62 |
+
"metadata": {},
|
63 |
+
"outputs": [
|
64 |
+
{
|
65 |
+
"data": {
|
66 |
+
"image/png": "iVBORw0KGgoAAAANSUhEUg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msBHwdc3g2GIGUC1OEg5E4os/FaBOXxi33eO7YBHLrdjs8UikLIfoGzy1y0xo04wiTTp5iEDU//xTMg9v9Pp1f5GVOwGMtyHnSty68myGs41gElU9BXpfyfy6e70HQL6dCYSl0cyoUlqKR1s63iRJIqhaFGKjK97gP1ZsSqGzV7fF8Mf0+9/pAZHly4N9jUUV7Cl4eRSGpK3qROAf+3RhjXKB/tzZ5lbFHP/RY1f69C19lfQFQ0lUIFveSesriSgdooD4sKNsTwcXgmTMec1uN9IKpziFsLj54UElPJTQxIAWTdAw9hGQgdg5jA6Ch8lpoTsKyDcYYs8vmDNXNhVjluNgnIpfhNUDvLGOMGUHlNbzno0eX2TgMQkinfH2zAPIyg0gRlnw9sOqHfBaNYtZrx7zuCIVC8WcC3ZwKhaXQzalQWIpmmRMCU1ORuxNpvowGQZV9Z4HOMRlxVbPD1P58KmFIF8Br74qaFsePQ0B4xF3jJpDTtmwIIPZBjR6KJGQRVL2O2jyn7VwL1fkkt5ahkPVA3uCJxoyB9KimANmsyIXqHc4h7xNNJnhvKB8aw80zUk5FubDVItOHXCuU79o+N+mgeQCPKwJ+L/i+SJORx4Li6Rw4J2OMyVPUNdRHf+QiUVoI6++C+Whvl79XbbDzlSLqCueFOg/UtRhjDHq1Nq1jHfTLqVBYCt2cCoWlcGZR6SoUirce+uVUKCyFbk6FwlLo5lQoLIVuToXCUujmVCgshW5OhcJS/F9fW39ZVVKmIgAAAABJRU5ErkJggg==\n",
|
67 |
+
"text/plain": [
|
68 |
+
"<Figure size 432x288 with 1 Axes>"
|
69 |
+
]
|
70 |
+
},
|
71 |
+
"metadata": {
|
72 |
+
"needs_background": "light"
|
73 |
+
},
|
74 |
+
"output_type": "display_data"
|
75 |
+
}
|
76 |
+
],
|
77 |
+
"source": [
|
78 |
+
"for x in dataset:\n",
|
79 |
+
" plt.axis(\"off\")\n",
|
80 |
+
" plt.imshow((x.numpy() * 255).astype(\"int32\")[0])\n",
|
81 |
+
" break\n"
|
82 |
+
]
|
83 |
+
},
|
84 |
+
{
|
85 |
+
"cell_type": "code",
|
86 |
+
"execution_count": 9,
|
87 |
+
"id": "2dea3fa4-1ac8-4889-8b52-8ec3e2ac7c9e",
|
88 |
+
"metadata": {},
|
89 |
+
"outputs": [
|
90 |
+
{
|
91 |
+
"name": "stdout",
|
92 |
+
"output_type": "stream",
|
93 |
+
"text": [
|
94 |
+
"Model: \"discriminator\"\n",
|
95 |
+
"_________________________________________________________________\n",
|
96 |
+
" Layer (type) Output Shape Param # \n",
|
97 |
+
"=================================================================\n",
|
98 |
+
" conv2d (Conv2D) (None, 32, 32, 64) 3136 \n",
|
99 |
+
" \n",
|
100 |
+
" leaky_re_lu (LeakyReLU) (None, 32, 32, 64) 0 \n",
|
101 |
+
" \n",
|
102 |
+
" conv2d_1 (Conv2D) (None, 16, 16, 128) 131200 \n",
|
103 |
+
" \n",
|
104 |
+
" leaky_re_lu_1 (LeakyReLU) (None, 16, 16, 128) 0 \n",
|
105 |
+
" \n",
|
106 |
+
" conv2d_2 (Conv2D) (None, 8, 8, 128) 262272 \n",
|
107 |
+
" \n",
|
108 |
+
" leaky_re_lu_2 (LeakyReLU) (None, 8, 8, 128) 0 \n",
|
109 |
+
" \n",
|
110 |
+
" flatten (Flatten) (None, 8192) 0 \n",
|
111 |
+
" \n",
|
112 |
+
" dropout (Dropout) (None, 8192) 0 \n",
|
113 |
+
" \n",
|
114 |
+
" dense (Dense) (None, 1) 8193 \n",
|
115 |
+
" \n",
|
116 |
+
"=================================================================\n",
|
117 |
+
"Total params: 404,801\n",
|
118 |
+
"Trainable params: 404,801\n",
|
119 |
+
"Non-trainable params: 0\n",
|
120 |
+
"_________________________________________________________________\n"
|
121 |
+
]
|
122 |
+
}
|
123 |
+
],
|
124 |
+
"source": [
|
125 |
+
"discriminator = keras.Sequential(\n",
|
126 |
+
" [\n",
|
127 |
+
" keras.Input(shape=(64, 64, 3)),\n",
|
128 |
+
" layers.Conv2D(64, kernel_size=4, strides=2, padding=\"same\"),\n",
|
129 |
+
" layers.LeakyReLU(alpha=0.2),\n",
|
130 |
+
" layers.Conv2D(128, kernel_size=4, strides=2, padding=\"same\"),\n",
|
131 |
+
" layers.LeakyReLU(alpha=0.2),\n",
|
132 |
+
" layers.Conv2D(128, kernel_size=4, strides=2, padding=\"same\"),\n",
|
133 |
+
" layers.LeakyReLU(alpha=0.2),\n",
|
134 |
+
" layers.Flatten(),\n",
|
135 |
+
" layers.Dropout(0.2),\n",
|
136 |
+
" layers.Dense(1, activation=\"sigmoid\"),\n",
|
137 |
+
" ],\n",
|
138 |
+
" name=\"discriminator\",\n",
|
139 |
+
")\n",
|
140 |
+
"discriminator.summary()\n"
|
141 |
+
]
|
142 |
+
},
|
143 |
+
{
|
144 |
+
"cell_type": "code",
|
145 |
+
"execution_count": 10,
|
146 |
+
"id": "2a2507b1-9ad7-48f3-8f90-1052ac67886b",
|
147 |
+
"metadata": {},
|
148 |
+
"outputs": [
|
149 |
+
{
|
150 |
+
"name": "stdout",
|
151 |
+
"output_type": "stream",
|
152 |
+
"text": [
|
153 |
+
"Model: \"generator\"\n",
|
154 |
+
"_________________________________________________________________\n",
|
155 |
+
" Layer (type) Output Shape Param # \n",
|
156 |
+
"=================================================================\n",
|
157 |
+
" dense_1 (Dense) (None, 8192) 1056768 \n",
|
158 |
+
" \n",
|
159 |
+
" reshape (Reshape) (None, 8, 8, 128) 0 \n",
|
160 |
+
" \n",
|
161 |
+
" conv2d_transpose (Conv2DTra (None, 16, 16, 128) 262272 \n",
|
162 |
+
" nspose) \n",
|
163 |
+
" \n",
|
164 |
+
" leaky_re_lu_3 (LeakyReLU) (None, 16, 16, 128) 0 \n",
|
165 |
+
" \n",
|
166 |
+
" conv2d_transpose_1 (Conv2DT (None, 32, 32, 256) 524544 \n",
|
167 |
+
" ranspose) \n",
|
168 |
+
" \n",
|
169 |
+
" leaky_re_lu_4 (LeakyReLU) (None, 32, 32, 256) 0 \n",
|
170 |
+
" \n",
|
171 |
+
" conv2d_transpose_2 (Conv2DT (None, 64, 64, 512) 2097664 \n",
|
172 |
+
" ranspose) \n",
|
173 |
+
" \n",
|
174 |
+
" leaky_re_lu_5 (LeakyReLU) (None, 64, 64, 512) 0 \n",
|
175 |
+
" \n",
|
176 |
+
" conv2d_3 (Conv2D) (None, 64, 64, 3) 38403 \n",
|
177 |
+
" \n",
|
178 |
+
"=================================================================\n",
|
179 |
+
"Total params: 3,979,651\n",
|
180 |
+
"Trainable params: 3,979,651\n",
|
181 |
+
"Non-trainable params: 0\n",
|
182 |
+
"_________________________________________________________________\n"
|
183 |
+
]
|
184 |
+
}
|
185 |
+
],
|
186 |
+
"source": [
|
187 |
+
"latent_dim = 128\n",
|
188 |
+
"\n",
|
189 |
+
"generator = keras.Sequential(\n",
|
190 |
+
" [\n",
|
191 |
+
" keras.Input(shape=(latent_dim,)),\n",
|
192 |
+
" layers.Dense(8 * 8 * 128),\n",
|
193 |
+
" layers.Reshape((8, 8, 128)),\n",
|
194 |
+
" layers.Conv2DTranspose(128, kernel_size=4, strides=2, padding=\"same\"),\n",
|
195 |
+
" layers.LeakyReLU(alpha=0.2),\n",
|
196 |
+
" layers.Conv2DTranspose(256, kernel_size=4, strides=2, padding=\"same\"),\n",
|
197 |
+
" layers.LeakyReLU(alpha=0.2),\n",
|
198 |
+
" layers.Conv2DTranspose(512, kernel_size=4, strides=2, padding=\"same\"),\n",
|
199 |
+
" layers.LeakyReLU(alpha=0.2),\n",
|
200 |
+
" layers.Conv2D(3, kernel_size=5, padding=\"same\", activation=\"sigmoid\"),\n",
|
201 |
+
" ],\n",
|
202 |
+
" name=\"generator\",\n",
|
203 |
+
")\n",
|
204 |
+
"generator.summary()\n"
|
205 |
+
]
|
206 |
+
},
|
207 |
+
{
|
208 |
+
"cell_type": "markdown",
|
209 |
+
"id": "88691fae-b91b-40ad-9ce3-765777608598",
|
210 |
+
"metadata": {},
|
211 |
+
"source": [
|
212 |
+
"# Override train_step"
|
213 |
+
]
|
214 |
+
},
|
215 |
+
{
|
216 |
+
"cell_type": "code",
|
217 |
+
"execution_count": 11,
|
218 |
+
"id": "0cd186bd-94f4-4f3b-9937-5062bb568415",
|
219 |
+
"metadata": {},
|
220 |
+
"outputs": [],
|
221 |
+
"source": [
|
222 |
+
"class GAN(keras.Model):\n",
|
223 |
+
" def __init__(self, discriminator, generator, latent_dim):\n",
|
224 |
+
" super(GAN, self).__init__()\n",
|
225 |
+
" self.discriminator = discriminator\n",
|
226 |
+
" self.generator = generator\n",
|
227 |
+
" self.latent_dim = latent_dim\n",
|
228 |
+
"\n",
|
229 |
+
" def compile(self, d_optimizer, g_optimizer, loss_fn):\n",
|
230 |
+
" super(GAN, self).compile()\n",
|
231 |
+
" self.d_optimizer = d_optimizer\n",
|
232 |
+
" self.g_optimizer = g_optimizer\n",
|
233 |
+
" self.loss_fn = loss_fn\n",
|
234 |
+
" self.d_loss_metric = keras.metrics.Mean(name=\"d_loss\")\n",
|
235 |
+
" self.g_loss_metric = keras.metrics.Mean(name=\"g_loss\")\n",
|
236 |
+
"\n",
|
237 |
+
" @property\n",
|
238 |
+
" def metrics(self):\n",
|
239 |
+
" return [self.d_loss_metric, self.g_loss_metric]\n",
|
240 |
+
"\n",
|
241 |
+
" def train_step(self, real_images):\n",
|
242 |
+
" # Sample random points in the latent space\n",
|
243 |
+
" batch_size = tf.shape(real_images)[0]\n",
|
244 |
+
" random_latent_vectors = tf.random.normal(shape=(batch_size, self.latent_dim))\n",
|
245 |
+
"\n",
|
246 |
+
" # Decode them to fake images\n",
|
247 |
+
" generated_images = self.generator(random_latent_vectors)\n",
|
248 |
+
"\n",
|
249 |
+
" # Combine them with real images\n",
|
250 |
+
" combined_images = tf.concat([generated_images, real_images], axis=0)\n",
|
251 |
+
"\n",
|
252 |
+
" # Assemble labels discriminating real from fake images\n",
|
253 |
+
" labels = tf.concat(\n",
|
254 |
+
" [tf.ones((batch_size, 1)), tf.zeros((batch_size, 1))], axis=0\n",
|
255 |
+
" )\n",
|
256 |
+
" # Add random noise to the labels - important trick!\n",
|
257 |
+
" labels += 0.05 * tf.random.uniform(tf.shape(labels))\n",
|
258 |
+
"\n",
|
259 |
+
" # Train the discriminator\n",
|
260 |
+
" with tf.GradientTape() as tape:\n",
|
261 |
+
" predictions = self.discriminator(combined_images)\n",
|
262 |
+
" d_loss = self.loss_fn(labels, predictions)\n",
|
263 |
+
" grads = tape.gradient(d_loss, self.discriminator.trainable_weights)\n",
|
264 |
+
" self.d_optimizer.apply_gradients(\n",
|
265 |
+
" zip(grads, self.discriminator.trainable_weights)\n",
|
266 |
+
" )\n",
|
267 |
+
"\n",
|
268 |
+
" # Sample random points in the latent space\n",
|
269 |
+
" random_latent_vectors = tf.random.normal(shape=(batch_size, self.latent_dim))\n",
|
270 |
+
"\n",
|
271 |
+
" # Assemble labels that say \"all real images\"\n",
|
272 |
+
" misleading_labels = tf.zeros((batch_size, 1))\n",
|
273 |
+
"\n",
|
274 |
+
" # Train the generator (note that we should *not* update the weights\n",
|
275 |
+
" # of the discriminator)!\n",
|
276 |
+
" with tf.GradientTape() as tape:\n",
|
277 |
+
" predictions = self.discriminator(self.generator(random_latent_vectors))\n",
|
278 |
+
" g_loss = self.loss_fn(misleading_labels, predictions)\n",
|
279 |
+
" grads = tape.gradient(g_loss, self.generator.trainable_weights)\n",
|
280 |
+
" self.g_optimizer.apply_gradients(zip(grads, self.generator.trainable_weights))\n",
|
281 |
+
"\n",
|
282 |
+
" # Update metrics\n",
|
283 |
+
" self.d_loss_metric.update_state(d_loss)\n",
|
284 |
+
" self.g_loss_metric.update_state(g_loss)\n",
|
285 |
+
" return {\n",
|
286 |
+
" \"d_loss\": self.d_loss_metric.result(),\n",
|
287 |
+
" \"g_loss\": self.g_loss_metric.result(),\n",
|
288 |
+
" }\n"
|
289 |
+
]
|
290 |
+
},
|
291 |
+
{
|
292 |
+
"cell_type": "markdown",
|
293 |
+
"id": "6ccd520d-d223-4447-92c8-24299d7b1f5e",
|
294 |
+
"metadata": {},
|
295 |
+
"source": [
|
296 |
+
"## Create a callback that periodically saves generated images"
|
297 |
+
]
|
298 |
+
},
|
299 |
+
{
|
300 |
+
"cell_type": "code",
|
301 |
+
"execution_count": 12,
|
302 |
+
"id": "621b2abf-e343-47b8-82dd-5103a738f249",
|
303 |
+
"metadata": {},
|
304 |
+
"outputs": [],
|
305 |
+
"source": [
|
306 |
+
"class GANMonitor(keras.callbacks.Callback):\n",
|
307 |
+
" def __init__(self, num_img=3, latent_dim=128):\n",
|
308 |
+
" self.num_img = num_img\n",
|
309 |
+
" self.latent_dim = latent_dim\n",
|
310 |
+
"\n",
|
311 |
+
" def on_epoch_end(self, epoch, logs=None):\n",
|
312 |
+
" random_latent_vectors = tf.random.normal(shape=(self.num_img, self.latent_dim))\n",
|
313 |
+
" generated_images = self.model.generator(random_latent_vectors)\n",
|
314 |
+
" generated_images *= 255\n",
|
315 |
+
" generated_images.numpy()\n",
|
316 |
+
" for i in range(self.num_img):\n",
|
317 |
+
" img = keras.preprocessing.image.array_to_img(generated_images[i])\n",
|
318 |
+
" img.save(\"generated_img_%03d_%d.png\" % (epoch, i))\n"
|
319 |
+
]
|
320 |
+
},
|
321 |
+
{
|
322 |
+
"cell_type": "markdown",
|
323 |
+
"id": "0588f900-8567-4d3d-87e0-5ae559d85c36",
|
324 |
+
"metadata": {},
|
325 |
+
"source": [
|
326 |
+
"## Train the end-to-end model"
|
327 |
+
]
|
328 |
+
},
|
329 |
+
{
|
330 |
+
"cell_type": "code",
|
331 |
+
"execution_count": 13,
|
332 |
+
"id": "1c771d14-b327-40ab-8458-4eaf73c16a28",
|
333 |
+
"metadata": {},
|
334 |
+
"outputs": [
|
335 |
+
{
|
336 |
+
"name": "stdout",
|
337 |
+
"output_type": "stream",
|
338 |
+
"text": [
|
339 |
+
" 5/6332 [..............................] - ETA: 16:15:50 - d_loss: 0.6776 - g_loss: 0.7854"
|
340 |
+
]
|
341 |
+
},
|
342 |
+
{
|
343 |
+
"ename": "KeyboardInterrupt",
|
344 |
+
"evalue": "",
|
345 |
+
"output_type": "error",
|
346 |
+
"traceback": [
|
347 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
348 |
+
"\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
|
349 |
+
"\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_15592/2002100634.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 8\u001b[0m )\n\u001b[0;32m 9\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 10\u001b[1;33m gan.fit(\n\u001b[0m\u001b[0;32m 11\u001b[0m \u001b[0mdataset\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mepochs\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mepochs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcallbacks\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mGANMonitor\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnum_img\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m10\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlatent_dim\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlatent_dim\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 12\u001b[0m )\n",
|
350 |
+
"\u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\keras\\utils\\traceback_utils.py\u001b[0m in \u001b[0;36merror_handler\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 62\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 63\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 64\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 65\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m# pylint: disable=broad-except\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 66\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_process_traceback_frames\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__traceback__\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
351 |
+
"\u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\keras\\engine\\training.py\u001b[0m in \u001b[0;36mfit\u001b[1;34m(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)\u001b[0m\n\u001b[0;32m 1382\u001b[0m _r=1):\n\u001b[0;32m 1383\u001b[0m \u001b[0mcallbacks\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mon_train_batch_begin\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstep\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1384\u001b[1;33m \u001b[0mtmp_logs\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtrain_function\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0miterator\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1385\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mdata_handler\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshould_sync\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1386\u001b[0m \u001b[0mcontext\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0masync_wait\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
352 |
+
"\u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\tensorflow\\python\\util\\traceback_utils.py\u001b[0m in \u001b[0;36merror_handler\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 148\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 149\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 150\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 151\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 152\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_process_traceback_frames\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__traceback__\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
353 |
+
"\u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\tensorflow\\python\\eager\\def_function.py\u001b[0m in \u001b[0;36m__call__\u001b[1;34m(self, *args, **kwds)\u001b[0m\n\u001b[0;32m 913\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 914\u001b[0m \u001b[1;32mwith\u001b[0m \u001b[0mOptionalXlaContext\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_jit_compile\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 915\u001b[1;33m \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_call\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 916\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 917\u001b[0m \u001b[0mnew_tracing_count\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexperimental_get_tracing_count\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
354 |
+
"\u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\tensorflow\\python\\eager\\def_function.py\u001b[0m in \u001b[0;36m_call\u001b[1;34m(self, *args, **kwds)\u001b[0m\n\u001b[0;32m 945\u001b[0m \u001b[1;31m# In this case we have created variables on the first call, so we run the\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 946\u001b[0m \u001b[1;31m# defunned version which is guaranteed to never create variables.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 947\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_stateless_fn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# pylint: disable=not-callable\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 948\u001b[0m \u001b[1;32melif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_stateful_fn\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 949\u001b[0m \u001b[1;31m# Release the lock early so that multiple threads can perform the call\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
355 |
+
"\u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\tensorflow\\python\\eager\\function.py\u001b[0m in \u001b[0;36m__call__\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m 2954\u001b[0m (graph_function,\n\u001b[0;32m 2955\u001b[0m filtered_flat_args) = self._maybe_define_function(args, kwargs)\n\u001b[1;32m-> 2956\u001b[1;33m return graph_function._call_flat(\n\u001b[0m\u001b[0;32m 2957\u001b[0m filtered_flat_args, captured_inputs=graph_function.captured_inputs) # pylint: disable=protected-access\n\u001b[0;32m 2958\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
|
356 |
+
"\u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\tensorflow\\python\\eager\\function.py\u001b[0m in \u001b[0;36m_call_flat\u001b[1;34m(self, args, captured_inputs, cancellation_manager)\u001b[0m\n\u001b[0;32m 1851\u001b[0m and executing_eagerly):\n\u001b[0;32m 1852\u001b[0m \u001b[1;31m# No tape is watching; skip to running the function.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1853\u001b[1;33m return self._build_call_outputs(self._inference_function.call(\n\u001b[0m\u001b[0;32m 1854\u001b[0m ctx, args, cancellation_manager=cancellation_manager))\n\u001b[0;32m 1855\u001b[0m forward_backward = self._select_forward_and_backward_functions(\n",
|
357 |
+
"\u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\tensorflow\\python\\eager\\function.py\u001b[0m in \u001b[0;36mcall\u001b[1;34m(self, ctx, args, cancellation_manager)\u001b[0m\n\u001b[0;32m 497\u001b[0m \u001b[1;32mwith\u001b[0m \u001b[0m_InterpolateFunctionError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 498\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mcancellation_manager\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 499\u001b[1;33m outputs = execute.execute(\n\u001b[0m\u001b[0;32m 500\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msignature\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 501\u001b[0m \u001b[0mnum_outputs\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_num_outputs\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
358 |
+
"\u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\tensorflow\\python\\eager\\execute.py\u001b[0m in \u001b[0;36mquick_execute\u001b[1;34m(op_name, num_outputs, inputs, attrs, ctx, name)\u001b[0m\n\u001b[0;32m 52\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 53\u001b[0m \u001b[0mctx\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mensure_initialized\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 54\u001b[1;33m tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,\n\u001b[0m\u001b[0;32m 55\u001b[0m inputs, attrs, num_outputs)\n\u001b[0;32m 56\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mcore\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_NotOkStatusException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
359 |
+
"\u001b[1;31mKeyboardInterrupt\u001b[0m: "
|
360 |
+
]
|
361 |
+
}
|
362 |
+
],
|
363 |
+
"source": [
|
364 |
+
"epochs = 1 # In practice, use ~100 epochs\n",
|
365 |
+
"\n",
|
366 |
+
"gan = GAN(discriminator=discriminator, generator=generator, latent_dim=latent_dim)\n",
|
367 |
+
"gan.compile(\n",
|
368 |
+
" d_optimizer=keras.optimizers.Adam(learning_rate=0.0001),\n",
|
369 |
+
" g_optimizer=keras.optimizers.Adam(learning_rate=0.0001),\n",
|
370 |
+
" loss_fn=keras.losses.BinaryCrossentropy(),\n",
|
371 |
+
")\n",
|
372 |
+
"\n",
|
373 |
+
"gan.fit(\n",
|
374 |
+
" dataset, epochs=epochs, callbacks=[GANMonitor(num_img=10, latent_dim=latent_dim)]\n",
|
375 |
+
")\n"
|
376 |
+
]
|
377 |
+
},
|
378 |
+
{
|
379 |
+
"cell_type": "code",
|
380 |
+
"execution_count": null,
|
381 |
+
"id": "ce3c558b-a39a-48f5-b109-d077057b3dcf",
|
382 |
+
"metadata": {},
|
383 |
+
"outputs": [],
|
384 |
+
"source": []
|
385 |
+
}
|
386 |
+
],
|
387 |
+
"metadata": {
|
388 |
+
"kernelspec": {
|
389 |
+
"display_name": "Python 3 (ipykernel)",
|
390 |
+
"language": "python",
|
391 |
+
"name": "python3"
|
392 |
+
},
|
393 |
+
"language_info": {
|
394 |
+
"codemirror_mode": {
|
395 |
+
"name": "ipython",
|
396 |
+
"version": 3
|
397 |
+
},
|
398 |
+
"file_extension": ".py",
|
399 |
+
"mimetype": "text/x-python",
|
400 |
+
"name": "python",
|
401 |
+
"nbconvert_exporter": "python",
|
402 |
+
"pygments_lexer": "ipython3",
|
403 |
+
"version": "3.9.6"
|
404 |
+
}
|
405 |
+
},
|
406 |
+
"nbformat": 4,
|
407 |
+
"nbformat_minor": 5
|
408 |
+
}
|