Skip to content

Commit 2a39b5b

Browse files
committed
Neural Net. Vincent Van starry night on class
1 parent 575f767 commit 2a39b5b

13 files changed

+196
-82
lines changed

class_20/.ipynb_checkpoints/NeuralArt-checkpoint.ipynb

Lines changed: 98 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@
2828
},
2929
{
3030
"cell_type": "code",
31-
"execution_count": 2,
31+
"execution_count": 48,
3232
"metadata": {
3333
"collapsed": true
3434
},
3535
"outputs": [],
3636
"source": [
37-
"base_image_path = '../class_19/2007_000187.jpg'\n",
38-
"style_reference_image_path = 'donelli.jpg'\n",
37+
"base_image_path = 'image.jpg'\n",
38+
"style_reference_image_path = 'style.jpg'\n",
3939
"result_prefix = 'im'\n",
4040
"iterations = 10\n",
4141
"\n",
4242
"total_variation_weight = 1.0\n",
43-
"style_weight = 1.0\n",
44-
"content_weight = 0.025\n",
43+
"style_weight = 0.7\n",
44+
"content_weight = 0.5\n",
4545
"\n",
4646
"width, height = load_img(base_image_path).size\n",
4747
"img_nrows = 400\n",
@@ -50,7 +50,7 @@
5050
},
5151
{
5252
"cell_type": "code",
53-
"execution_count": 3,
53+
"execution_count": 49,
5454
"metadata": {
5555
"collapsed": true
5656
},
@@ -81,7 +81,7 @@
8181
},
8282
{
8383
"cell_type": "code",
84-
"execution_count": 4,
84+
"execution_count": 50,
8585
"metadata": {
8686
"collapsed": true
8787
},
@@ -93,7 +93,7 @@
9393
},
9494
{
9595
"cell_type": "code",
96-
"execution_count": 5,
96+
"execution_count": 51,
9797
"metadata": {
9898
"collapsed": true
9999
},
@@ -108,7 +108,7 @@
108108
},
109109
{
110110
"cell_type": "code",
111-
"execution_count": 12,
111+
"execution_count": 52,
112112
"metadata": {
113113
"collapsed": false
114114
},
@@ -120,7 +120,7 @@
120120
"_________________________________________________________________\n",
121121
"Layer (type) Output Shape Param # \n",
122122
"=================================================================\n",
123-
"input_1 (InputLayer) (3, 400, 533, 3) 0 \n",
123+
"input_4 (InputLayer) (3, 400, 533, 3) 0 \n",
124124
"_________________________________________________________________\n",
125125
"block1_conv1 (Conv2D) (3, 400, 533, 64) 1792 \n",
126126
"_________________________________________________________________\n",
@@ -173,7 +173,7 @@
173173
},
174174
{
175175
"cell_type": "code",
176-
"execution_count": 9,
176+
"execution_count": 53,
177177
"metadata": {
178178
"collapsed": false
179179
},
@@ -182,25 +182,25 @@
182182
"name": "stdout",
183183
"output_type": "stream",
184184
"text": [
185-
"block4_pool Tensor(\"block4_pool/MaxPool:0\", shape=(3, 25, 33, 512), dtype=float32)\n",
186-
"block1_pool Tensor(\"block1_pool/MaxPool:0\", shape=(3, 200, 266, 64), dtype=float32)\n",
187-
"block4_conv1 Tensor(\"block4_conv1/Relu:0\", shape=(3, 50, 66, 512), dtype=float32)\n",
188-
"block2_conv1 Tensor(\"block2_conv1/Relu:0\", shape=(3, 200, 266, 128), dtype=float32)\n",
189-
"block2_conv2 Tensor(\"block2_conv2/Relu:0\", shape=(3, 200, 266, 128), dtype=float32)\n",
190-
"block4_conv2 Tensor(\"block4_conv2/Relu:0\", shape=(3, 50, 66, 512), dtype=float32)\n",
191-
"block4_conv3 Tensor(\"block4_conv3/Relu:0\", shape=(3, 50, 66, 512), dtype=float32)\n",
192-
"block2_pool Tensor(\"block2_pool/MaxPool:0\", shape=(3, 100, 133, 128), dtype=float32)\n",
193-
"block5_conv3 Tensor(\"block5_conv3/Relu:0\", shape=(3, 25, 33, 512), dtype=float32)\n",
194-
"block5_conv2 Tensor(\"block5_conv2/Relu:0\", shape=(3, 25, 33, 512), dtype=float32)\n",
195-
"block5_conv1 Tensor(\"block5_conv1/Relu:0\", shape=(3, 25, 33, 512), dtype=float32)\n",
196-
"block3_pool Tensor(\"block3_pool/MaxPool:0\", shape=(3, 50, 66, 256), dtype=float32)\n",
197-
"block1_conv2 Tensor(\"block1_conv2/Relu:0\", shape=(3, 400, 533, 64), dtype=float32)\n",
198-
"block1_conv1 Tensor(\"block1_conv1/Relu:0\", shape=(3, 400, 533, 64), dtype=float32)\n",
199-
"input_1 Tensor(\"concat:0\", shape=(3, 400, 533, 3), dtype=float32)\n",
200-
"block3_conv1 Tensor(\"block3_conv1/Relu:0\", shape=(3, 100, 133, 256), dtype=float32)\n",
201-
"block3_conv3 Tensor(\"block3_conv3/Relu:0\", shape=(3, 100, 133, 256), dtype=float32)\n",
202-
"block3_conv2 Tensor(\"block3_conv2/Relu:0\", shape=(3, 100, 133, 256), dtype=float32)\n",
203-
"block5_pool Tensor(\"block5_pool/MaxPool:0\", shape=(3, 12, 16, 512), dtype=float32)\n"
185+
"block4_pool Tensor(\"block4_pool_4/MaxPool:0\", shape=(3, 25, 33, 512), dtype=float32)\n",
186+
"block1_pool Tensor(\"block1_pool_4/MaxPool:0\", shape=(3, 200, 266, 64), dtype=float32)\n",
187+
"block4_conv1 Tensor(\"block4_conv1_4/Relu:0\", shape=(3, 50, 66, 512), dtype=float32)\n",
188+
"block2_conv1 Tensor(\"block2_conv1_4/Relu:0\", shape=(3, 200, 266, 128), dtype=float32)\n",
189+
"block2_conv2 Tensor(\"block2_conv2_4/Relu:0\", shape=(3, 200, 266, 128), dtype=float32)\n",
190+
"block4_conv2 Tensor(\"block4_conv2_4/Relu:0\", shape=(3, 50, 66, 512), dtype=float32)\n",
191+
"block4_conv3 Tensor(\"block4_conv3_4/Relu:0\", shape=(3, 50, 66, 512), dtype=float32)\n",
192+
"block5_conv2 Tensor(\"block5_conv2_4/Relu:0\", shape=(3, 25, 33, 512), dtype=float32)\n",
193+
"block2_pool Tensor(\"block2_pool_4/MaxPool:0\", shape=(3, 100, 133, 128), dtype=float32)\n",
194+
"block5_conv3 Tensor(\"block5_conv3_4/Relu:0\", shape=(3, 25, 33, 512), dtype=float32)\n",
195+
"block1_conv1 Tensor(\"block1_conv1_4/Relu:0\", shape=(3, 400, 533, 64), dtype=float32)\n",
196+
"block5_conv1 Tensor(\"block5_conv1_4/Relu:0\", shape=(3, 25, 33, 512), dtype=float32)\n",
197+
"block3_pool Tensor(\"block3_pool_4/MaxPool:0\", shape=(3, 50, 66, 256), dtype=float32)\n",
198+
"block1_conv2 Tensor(\"block1_conv2_4/Relu:0\", shape=(3, 400, 533, 64), dtype=float32)\n",
199+
"input_4 Tensor(\"concat_3:0\", shape=(3, 400, 533, 3), dtype=float32)\n",
200+
"block3_conv1 Tensor(\"block3_conv1_4/Relu:0\", shape=(3, 100, 133, 256), dtype=float32)\n",
201+
"block3_conv3 Tensor(\"block3_conv3_4/Relu:0\", shape=(3, 100, 133, 256), dtype=float32)\n",
202+
"block3_conv2 Tensor(\"block3_conv2_4/Relu:0\", shape=(3, 100, 133, 256), dtype=float32)\n",
203+
"block5_pool Tensor(\"block5_pool_4/MaxPool:0\", shape=(3, 12, 16, 512), dtype=float32)\n"
204204
]
205205
}
206206
],
@@ -212,7 +212,7 @@
212212
},
213213
{
214214
"cell_type": "code",
215-
"execution_count": 10,
215+
"execution_count": 54,
216216
"metadata": {
217217
"collapsed": true
218218
},
@@ -247,7 +247,7 @@
247247
},
248248
{
249249
"cell_type": "code",
250-
"execution_count": 11,
250+
"execution_count": 55,
251251
"metadata": {
252252
"collapsed": true
253253
},
@@ -263,7 +263,7 @@
263263
},
264264
{
265265
"cell_type": "code",
266-
"execution_count": 13,
266+
"execution_count": 56,
267267
"metadata": {
268268
"collapsed": true
269269
},
@@ -276,7 +276,7 @@
276276
},
277277
{
278278
"cell_type": "code",
279-
"execution_count": 14,
279+
"execution_count": 57,
280280
"metadata": {
281281
"collapsed": true
282282
},
@@ -294,7 +294,7 @@
294294
},
295295
{
296296
"cell_type": "code",
297-
"execution_count": 15,
297+
"execution_count": 58,
298298
"metadata": {
299299
"collapsed": true
300300
},
@@ -313,7 +313,7 @@
313313
},
314314
{
315315
"cell_type": "code",
316-
"execution_count": 16,
316+
"execution_count": 59,
317317
"metadata": {
318318
"collapsed": true
319319
},
@@ -335,7 +335,7 @@
335335
},
336336
{
337337
"cell_type": "code",
338-
"execution_count": 17,
338+
"execution_count": 60,
339339
"metadata": {
340340
"collapsed": true
341341
},
@@ -366,13 +366,61 @@
366366
},
367367
{
368368
"cell_type": "code",
369-
"execution_count": null,
369+
"execution_count": 61,
370370
"metadata": {
371-
"collapsed": true
371+
"collapsed": false
372372
},
373-
"outputs": [],
373+
"outputs": [
374+
{
375+
"name": "stdout",
376+
"output_type": "stream",
377+
"text": [
378+
"('Start of iteration', 0)\n",
379+
"('Current loss value:', 6.0200903e+10)\n",
380+
"('Image saved as', 'results/im_at_iteration_0.png')\n",
381+
"Iteration 0 completed in 23s\n",
382+
"('Start of iteration', 1)\n",
383+
"('Current loss value:', 2.8211651e+10)\n",
384+
"('Image saved as', 'results/im_at_iteration_1.png')\n",
385+
"Iteration 1 completed in 23s\n",
386+
"('Start of iteration', 2)\n",
387+
"('Current loss value:', 2.2322983e+10)\n",
388+
"('Image saved as', 'results/im_at_iteration_2.png')\n",
389+
"Iteration 2 completed in 23s\n",
390+
"('Start of iteration', 3)\n",
391+
"('Current loss value:', 2.0141793e+10)\n",
392+
"('Image saved as', 'results/im_at_iteration_3.png')\n",
393+
"Iteration 3 completed in 23s\n",
394+
"('Start of iteration', 4)\n",
395+
"('Current loss value:', 1.9059913e+10)\n",
396+
"('Image saved as', 'results/im_at_iteration_4.png')\n",
397+
"Iteration 4 completed in 23s\n",
398+
"('Start of iteration', 5)\n",
399+
"('Current loss value:', 1.8409126e+10)\n",
400+
"('Image saved as', 'results/im_at_iteration_5.png')\n",
401+
"Iteration 5 completed in 23s\n",
402+
"('Start of iteration', 6)\n",
403+
"('Current loss value:', 1.7965795e+10)\n",
404+
"('Image saved as', 'results/im_at_iteration_6.png')\n",
405+
"Iteration 6 completed in 23s\n",
406+
"('Start of iteration', 7)\n",
407+
"('Current loss value:', 1.7639055e+10)\n",
408+
"('Image saved as', 'results/im_at_iteration_7.png')\n",
409+
"Iteration 7 completed in 23s\n",
410+
"('Start of iteration', 8)\n",
411+
"('Current loss value:', 1.738588e+10)\n",
412+
"('Image saved as', 'results/im_at_iteration_8.png')\n",
413+
"Iteration 8 completed in 26s\n",
414+
"('Start of iteration', 9)\n",
415+
"('Current loss value:', 1.7179054e+10)\n",
416+
"('Image saved as', 'results/im_at_iteration_9.png')\n",
417+
"Iteration 9 completed in 24s\n"
418+
]
419+
}
420+
],
374421
"source": [
375-
"x = np.random.uniform(0, 255, (1, img_nrows, img_ncols, 3)) - 128.\n",
422+
"# x = np.random.uniform(0, 255, (1, img_nrows, img_ncols, 3)) - 128.\n",
423+
"x = np.zeros((1, img_nrows, img_ncols, 3))\n",
376424
"\n",
377425
"for i in range(iterations):\n",
378426
" print('Start of iteration', i)\n",
@@ -388,6 +436,15 @@
388436
" print('Image saved as', fname)\n",
389437
" print('Iteration %d completed in %ds' % (i, end_time - start_time))"
390438
]
439+
},
440+
{
441+
"cell_type": "code",
442+
"execution_count": null,
443+
"metadata": {
444+
"collapsed": true
445+
},
446+
"outputs": [],
447+
"source": []
391448
}
392449
],
393450
"metadata": {

0 commit comments

Comments
 (0)