|
2 | 2 | "cells": [ |
3 | 3 | { |
4 | 4 | "cell_type": "markdown", |
5 | | - "metadata": { |
6 | | - "deletable": true, |
7 | | - "editable": true |
8 | | - }, |
| 5 | + "metadata": {}, |
9 | 6 | "source": [ |
10 | 7 | "# Face Generation\n", |
11 | 8 | "In this project, you'll use generative adversarial networks to generate new images of faces.\n", |
|
22 | 19 | { |
23 | 20 | "cell_type": "code", |
24 | 21 | "execution_count": null, |
25 | | - "metadata": { |
26 | | - "collapsed": false, |
27 | | - "deletable": true, |
28 | | - "editable": true |
29 | | - }, |
| 22 | + "metadata": {}, |
30 | 23 | "outputs": [], |
31 | 24 | "source": [ |
32 | 25 | "data_dir = './data'\n", |
|
46 | 39 | }, |
47 | 40 | { |
48 | 41 | "cell_type": "markdown", |
49 | | - "metadata": { |
50 | | - "deletable": true, |
51 | | - "editable": true |
52 | | - }, |
| 42 | + "metadata": {}, |
53 | 43 | "source": [ |
54 | 44 | "## Explore the Data\n", |
55 | 45 | "### MNIST\n", |
|
59 | 49 | { |
60 | 50 | "cell_type": "code", |
61 | 51 | "execution_count": null, |
62 | | - "metadata": { |
63 | | - "collapsed": false, |
64 | | - "deletable": true, |
65 | | - "editable": true |
66 | | - }, |
| 52 | + "metadata": {}, |
67 | 53 | "outputs": [], |
68 | 54 | "source": [ |
69 | 55 | "show_n_images = 25\n", |
|
82 | 68 | }, |
83 | 69 | { |
84 | 70 | "cell_type": "markdown", |
85 | | - "metadata": { |
86 | | - "deletable": true, |
87 | | - "editable": true |
88 | | - }, |
| 71 | + "metadata": {}, |
89 | 72 | "source": [ |
90 | 73 | "### CelebA\n", |
91 | 74 | "The [CelebFaces Attributes Dataset (CelebA)](http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html) dataset contains over 200,000 celebrity images with annotations. Since you're going to be generating faces, you won't need the annotations. You can view the first number of examples by changing `show_n_images`." |
|
94 | 77 | { |
95 | 78 | "cell_type": "code", |
96 | 79 | "execution_count": null, |
97 | | - "metadata": { |
98 | | - "collapsed": false, |
99 | | - "deletable": true, |
100 | | - "editable": true |
101 | | - }, |
| 80 | + "metadata": {}, |
102 | 81 | "outputs": [], |
103 | 82 | "source": [ |
104 | 83 | "show_n_images = 25\n", |
|
112 | 91 | }, |
113 | 92 | { |
114 | 93 | "cell_type": "markdown", |
115 | | - "metadata": { |
116 | | - "deletable": true, |
117 | | - "editable": true |
118 | | - }, |
| 94 | + "metadata": {}, |
119 | 95 | "source": [ |
120 | 96 | "## Preprocess the Data\n", |
121 | 97 | "Since the project's main focus is on building the GANs, we'll preprocess the data for you. The values of the MNIST and CelebA dataset will be in the range of -0.5 to 0.5 of 28x28 dimensional images. The CelebA images will be cropped to remove parts of the image that don't include a face, then resized down to 28x28.\n", |
|
137 | 113 | { |
138 | 114 | "cell_type": "code", |
139 | 115 | "execution_count": null, |
140 | | - "metadata": { |
141 | | - "collapsed": false, |
142 | | - "deletable": true, |
143 | | - "editable": true |
144 | | - }, |
| 116 | + "metadata": {}, |
145 | 117 | "outputs": [], |
146 | 118 | "source": [ |
147 | 119 | "\"\"\"\n", |
|
164 | 136 | }, |
165 | 137 | { |
166 | 138 | "cell_type": "markdown", |
167 | | - "metadata": { |
168 | | - "deletable": true, |
169 | | - "editable": true |
170 | | - }, |
| 139 | + "metadata": {}, |
171 | 140 | "source": [ |
172 | 141 | "### Input\n", |
173 | 142 | "Implement the `model_inputs` function to create TF Placeholders for the Neural Network. It should create the following placeholders:\n", |
|
181 | 150 | { |
182 | 151 | "cell_type": "code", |
183 | 152 | "execution_count": null, |
184 | | - "metadata": { |
185 | | - "collapsed": false, |
186 | | - "deletable": true, |
187 | | - "editable": true |
188 | | - }, |
| 153 | + "metadata": {}, |
189 | 154 | "outputs": [], |
190 | 155 | "source": [ |
191 | 156 | "import problem_unittests as tests\n", |
|
212 | 177 | }, |
213 | 178 | { |
214 | 179 | "cell_type": "markdown", |
215 | | - "metadata": { |
216 | | - "deletable": true, |
217 | | - "editable": true |
218 | | - }, |
| 180 | + "metadata": {}, |
219 | 181 | "source": [ |
220 | 182 | "### Discriminator\n", |
221 | 183 | "Implement `discriminator` to create a discriminator neural network that discriminates on `images`. This function should be able to reuse the variables in the neural network. Use [`tf.variable_scope`](https://www.tensorflow.org/api_docs/python/tf/variable_scope) with a scope name of \"discriminator\" to allow the variables to be reused. The function should return a tuple of (tensor output of the discriminator, tensor logits of the discriminator)." |
|
224 | 186 | { |
225 | 187 | "cell_type": "code", |
226 | 188 | "execution_count": null, |
227 | | - "metadata": { |
228 | | - "collapsed": false, |
229 | | - "deletable": true, |
230 | | - "editable": true |
231 | | - }, |
| 189 | + "metadata": {}, |
232 | 190 | "outputs": [], |
233 | 191 | "source": [ |
234 | 192 | "def discriminator(images, reuse=False):\n", |
|
251 | 209 | }, |
252 | 210 | { |
253 | 211 | "cell_type": "markdown", |
254 | | - "metadata": { |
255 | | - "deletable": true, |
256 | | - "editable": true |
257 | | - }, |
| 212 | + "metadata": {}, |
258 | 213 | "source": [ |
259 | 214 | "### Generator\n", |
260 | 215 | "Implement `generator` to generate an image using `z`. This function should be able to reuse the variables in the neural network. Use [`tf.variable_scope`](https://www.tensorflow.org/api_docs/python/tf/variable_scope) with a scope name of \"generator\" to allow the variables to be reused. The function should return the generated 28 x 28 x `out_channel_dim` images." |
|
263 | 218 | { |
264 | 219 | "cell_type": "code", |
265 | 220 | "execution_count": null, |
266 | | - "metadata": { |
267 | | - "collapsed": false, |
268 | | - "deletable": true, |
269 | | - "editable": true |
270 | | - }, |
| 221 | + "metadata": {}, |
271 | 222 | "outputs": [], |
272 | 223 | "source": [ |
273 | 224 | "def generator(z, out_channel_dim, is_train=True):\n", |
|
291 | 242 | }, |
292 | 243 | { |
293 | 244 | "cell_type": "markdown", |
294 | | - "metadata": { |
295 | | - "deletable": true, |
296 | | - "editable": true |
297 | | - }, |
| 245 | + "metadata": {}, |
298 | 246 | "source": [ |
299 | 247 | "### Loss\n", |
300 | 248 | "Implement `model_loss` to build the GANs for training and calculate the loss. The function should return a tuple of (discriminator loss, generator loss). Use the following functions you implemented:\n", |
|
305 | 253 | { |
306 | 254 | "cell_type": "code", |
307 | 255 | "execution_count": null, |
308 | | - "metadata": { |
309 | | - "collapsed": false, |
310 | | - "deletable": true, |
311 | | - "editable": true |
312 | | - }, |
| 256 | + "metadata": {}, |
313 | 257 | "outputs": [], |
314 | 258 | "source": [ |
315 | 259 | "def model_loss(input_real, input_z, out_channel_dim):\n", |
|
333 | 277 | }, |
334 | 278 | { |
335 | 279 | "cell_type": "markdown", |
336 | | - "metadata": { |
337 | | - "deletable": true, |
338 | | - "editable": true |
339 | | - }, |
| 280 | + "metadata": {}, |
340 | 281 | "source": [ |
341 | 282 | "### Optimization\n", |
342 | 283 | "Implement `model_opt` to create the optimization operations for the GANs. Use [`tf.trainable_variables`](https://www.tensorflow.org/api_docs/python/tf/trainable_variables) to get all the trainable variables. Filter the variables with names that are in the discriminator and generator scope names. The function should return a tuple of (discriminator training operation, generator training operation)." |
|
345 | 286 | { |
346 | 287 | "cell_type": "code", |
347 | 288 | "execution_count": null, |
348 | | - "metadata": { |
349 | | - "collapsed": false, |
350 | | - "deletable": true, |
351 | | - "editable": true |
352 | | - }, |
| 289 | + "metadata": {}, |
353 | 290 | "outputs": [], |
354 | 291 | "source": [ |
355 | 292 | "def model_opt(d_loss, g_loss, learning_rate, beta1):\n", |
|
374 | 311 | }, |
375 | 312 | { |
376 | 313 | "cell_type": "markdown", |
377 | | - "metadata": { |
378 | | - "deletable": true, |
379 | | - "editable": true |
380 | | - }, |
| 314 | + "metadata": {}, |
381 | 315 | "source": [ |
382 | 316 | "## Neural Network Training\n", |
383 | 317 | "### Show Output\n", |
|
388 | 322 | "cell_type": "code", |
389 | 323 | "execution_count": null, |
390 | 324 | "metadata": { |
391 | | - "collapsed": true, |
392 | | - "deletable": true, |
393 | | - "editable": true |
| 325 | + "collapsed": true |
394 | 326 | }, |
395 | 327 | "outputs": [], |
396 | 328 | "source": [ |
|
423 | 355 | }, |
424 | 356 | { |
425 | 357 | "cell_type": "markdown", |
426 | | - "metadata": { |
427 | | - "deletable": true, |
428 | | - "editable": true |
429 | | - }, |
| 358 | + "metadata": {}, |
430 | 359 | "source": [ |
431 | 360 | "### Train\n", |
432 | 361 | "Implement `train` to build and train the GANs. Use the following functions you implemented:\n", |
|
441 | 370 | "cell_type": "code", |
442 | 371 | "execution_count": null, |
443 | 372 | "metadata": { |
444 | | - "collapsed": true, |
445 | | - "deletable": true, |
446 | | - "editable": true |
| 373 | + "collapsed": true |
447 | 374 | }, |
448 | 375 | "outputs": [], |
449 | 376 | "source": [ |
|
473 | 400 | }, |
474 | 401 | { |
475 | 402 | "cell_type": "markdown", |
476 | | - "metadata": { |
477 | | - "deletable": true, |
478 | | - "editable": true |
479 | | - }, |
| 403 | + "metadata": {}, |
480 | 404 | "source": [ |
481 | 405 | "### MNIST\n", |
482 | 406 | "Test your GANs architecture on MNIST. After 2 epochs, the GANs should be able to generate images that look like handwritten digits. Make sure the loss of the generator is lower than the loss of the discriminator or close to 0." |
|
486 | 410 | "cell_type": "code", |
487 | 411 | "execution_count": null, |
488 | 412 | "metadata": { |
489 | | - "collapsed": false, |
490 | | - "deletable": true, |
491 | | - "editable": true, |
492 | 413 | "scrolled": true |
493 | 414 | }, |
494 | 415 | "outputs": [], |
|
512 | 433 | }, |
513 | 434 | { |
514 | 435 | "cell_type": "markdown", |
515 | | - "metadata": { |
516 | | - "deletable": true, |
517 | | - "editable": true |
518 | | - }, |
| 436 | + "metadata": {}, |
519 | 437 | "source": [ |
520 | 438 | "### CelebA\n", |
521 | 439 | "Run your GANs on CelebA. It will take around 20 minutes on the average GPU to run one epoch. You can run the whole epoch or stop when it starts to generate realistic faces." |
|
525 | 443 | "cell_type": "code", |
526 | 444 | "execution_count": null, |
527 | 445 | "metadata": { |
528 | | - "collapsed": false, |
529 | | - "deletable": true, |
530 | | - "editable": true, |
531 | 446 | "scrolled": true |
532 | 447 | }, |
533 | 448 | "outputs": [], |
|
551 | 466 | }, |
552 | 467 | { |
553 | 468 | "cell_type": "markdown", |
554 | | - "metadata": { |
555 | | - "deletable": true, |
556 | | - "editable": true |
557 | | - }, |
| 469 | + "metadata": {}, |
558 | 470 | "source": [ |
559 | 471 | "### Submitting This Project\n", |
560 | 472 | "When submitting this project, make sure to run all the cells before saving the notebook. Save the notebook file as \"dlnd_face_generation.ipynb\" and save it as a HTML file under \"File\" -> \"Download as\". Include the \"helper.py\" and \"problem_unittests.py\" files in your submission." |
|
577 | 489 | "name": "python", |
578 | 490 | "nbconvert_exporter": "python", |
579 | 491 | "pygments_lexer": "ipython3", |
580 | | - "version": "3.5.2" |
| 492 | + "version": "3.6.2" |
581 | 493 | } |
582 | 494 | }, |
583 | 495 | "nbformat": 4, |
584 | | - "nbformat_minor": 0 |
| 496 | + "nbformat_minor": 1 |
585 | 497 | } |
0 commit comments