From d7474266672176c8994858555bec8c4e40cbb662 Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 16 Nov 2016 01:12:31 -0700 Subject: Update neural_style.py --- neural_style.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neural_style.py b/neural_style.py index 62875f6..8164b2c 100644 --- a/neural_style.py +++ b/neural_style.py @@ -479,9 +479,9 @@ def sum_total_variation_losses(sess, net, input_img): x = net['input'] tv_y_size = b * (h-1) * w * d tv_x_size = b * h * (w-1) * d - loss_y = tf.nn.l2_loss(x[:,1:,:,:] - x[:,:h-1,:,:]) + loss_y = tf.nn.l2_loss(x[:,1:,:,:] - x[:,:-1,:,:]) loss_y /= tv_y_size - loss_x = tf.nn.l2_loss(x[:,:,1:,:] - x[:,:,:w-1,:]) + loss_x = tf.nn.l2_loss(x[:,:,1:,:] - x[:,:,:-1,:]) loss_x /= tv_x_size loss = 2 * (loss_y + loss_x) loss = tf.cast(loss, tf.float32) -- cgit v1.2.3-70-g09d2 From 160d9aff117a9542f4c27e342f3549359218b675 Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 16 Nov 2016 16:08:36 -0700 Subject: Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 644a3ac..f209f81 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ by Leon A. Gatys, Matthias Bethge, Aaron Hertzmann, Eli Shechtman Additionally, techniques are presented for semantic segmentation and multiple style transfer. -The Neural Style algorithm combines the content of one image with the style of another image using convolutional neural networks (CNN). Below is an example of transferring the artistic style of [The Starry Night](https://en.wikipedia.org/wiki/The_Starry_Night) onto a photograph of an African lion: +The Neural Style algorithm synthesizes a [pastiche](https://en.wikipedia.org/wiki/Pastiche) by separating and combining the content of one image with the style of another image using convolutional neural networks (CNN). Below is an example of transferring the artistic style of [The Starry Night](https://en.wikipedia.org/wiki/The_Starry_Night) onto a photograph of an African lion:

-- cgit v1.2.3-70-g09d2 From 4b79b2fb188cc980ac9596af888445d8d7fdb0ea Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 16 Nov 2016 17:18:43 -0700 Subject: Update neural_style.py --- neural_style.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/neural_style.py b/neural_style.py index 8164b2c..5373e5e 100644 --- a/neural_style.py +++ b/neural_style.py @@ -551,7 +551,7 @@ def normalize(weights): denom = sum(weights) if denom > 0.: return [float(i) / denom for i in weights] - else: return [0. for _ in weights] + else: return [0.] * len(weights) def maybe_make_directory(dir_path): if not os.path.exists(dir_path): @@ -568,29 +568,30 @@ def stylize(content_img, style_imgs, init_img, frame=None): with tf.device(args.device), tf.Session() as sess: # setup network net = build_vgg19(content_img) - + # style loss if args.style_mask: L_style = sum_masked_style_losses(sess, net, style_imgs) else: L_style = sum_style_losses(sess, net, style_imgs) - + # content loss L_content = sum_content_losses(sess, net, content_img) - + # denoising loss L_tv = sum_total_variation_losses(sess, net, init_img) - + # loss weights alpha = args.content_weight beta = args.style_weight - theta = args.tv_weight + theta = args.tv_weight # total loss L_total = alpha * L_content L_total += beta * L_style L_total += theta * L_tv - + + # video temporal loss if args.video and frame > 1: gamma = args.temporal_weight L_temporal = sum_shortterm_temporal_losses(sess, net, frame, init_img) -- cgit v1.2.3-70-g09d2 From 5d7b81c52b2d41a6c852609a9ffc6214d164b3a9 Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 24 Nov 2016 17:44:34 -0700 Subject: Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f209f81..ada34e5 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,8 @@ Multiple styles can be transferred to the foreground and background of the conte

*Left to right*: content image, foreground style, background style, foreground mask, background mask, stylized image +*Note*: The masking is done during synthesis and not as a post-processing step. + ### Video Animations can be rendered by applying the algorithm to each source frame. For the best results, the network is initialized with the previously stylized frame warped to the current frame according to the optical flow between the pair of frames. Loss functions for temporal consistency are used to penalize pixels excluding disoccluded regions and motion boundaries. -- cgit v1.2.3-70-g09d2 From a78bc7a19b26c368a727da8fcc434e8e1c4b6af0 Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 24 Nov 2016 20:22:40 -0700 Subject: Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ada34e5..6cb1a3f 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ Multiple styles can be transferred to the foreground and background of the conte

*Left to right*: content image, foreground style, background style, foreground mask, background mask, stylized image -*Note*: The masking is done during synthesis and not as a post-processing step. +*Note*: The masking is done during synthesis; not as a post-processing step. ### Video Animations can be rendered by applying the algorithm to each source frame. For the best results, the network is initialized with the previously stylized frame warped to the current frame according to the optical flow between the pair of frames. Loss functions for temporal consistency are used to penalize pixels excluding disoccluded regions and motion boundaries. -- cgit v1.2.3-70-g09d2 From 2bfea25d4c31a767dfd5b8c85e7001fee5c94a96 Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 25 Nov 2016 23:07:06 -0700 Subject: Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6cb1a3f..5fcc649 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ Multiple styles can be transferred to the foreground and background of the conte *Note*: The masking is done during synthesis; not as a post-processing step. ### Video -Animations can be rendered by applying the algorithm to each source frame. For the best results, the network is initialized with the previously stylized frame warped to the current frame according to the optical flow between the pair of frames. Loss functions for temporal consistency are used to penalize pixels excluding disoccluded regions and motion boundaries. +Animations can be rendered by applying the algorithm to each source frame. For the best results, the gradient descent is initialized with the previously stylized frame warped to the current frame according to the optical flow between the pair of frames. Loss functions for temporal consistency are used to penalize pixels excluding disoccluded regions and motion boundaries.

-- cgit v1.2.3-70-g09d2 From 82c672cf92587817877bc5fc2f9fb98dfd24a318 Mon Sep 17 00:00:00 2001 From: Cameron Date: Sun, 27 Nov 2016 18:59:54 -0700 Subject: Update README.md --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 5fcc649..c50fc3f 100644 --- a/README.md +++ b/README.md @@ -410,9 +410,6 @@ The implementation is based on the projects: Source video frames were obtained from: * [MPI Sintel Flow Dataset](http://sintel.is.tue.mpg.de/) -Souce images and corresponding segmentation masks were obtained from: -* [Automatic Portrait Segmentation for Image Stylization](http://xiaoyongshen.me/webpage_portrait/index.html) - Artistic images were created by the modern artists: * [Alex Grey](http://alexgrey.com/) * [Minjae Lee](http://www.grenomj.com/) -- cgit v1.2.3-70-g09d2 From 6ff2d3aec356560d84ecb207075107393ff9a762 Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 29 Nov 2016 21:14:51 -0700 Subject: Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c50fc3f..40915a6 100644 --- a/README.md +++ b/README.md @@ -344,7 +344,7 @@ python neural_style.py --video \ * `--model_weights`: Weights and biases of the VGG-19 network. Download [here](http://www.vlfeat.org/matconvnet/pretrained/). *Default*:`imagenet-vgg-verydeep-19.mat` * `--pooling_type`: Type of pooling in convolutional neural network. *Choices*: `avg`, `max`. *Default*: `avg` * `--device`: GPU or CPU device. GPU mode highly recommended but requires NVIDIA CUDA. *Choices*: `/gpu:0` `/cpu:0`. *Default*: `/gpu:0` -* `--image_output_dir`: Directory to write output to. *Default*: `./image_output` +* `--img_output_dir`: Directory to write output to. *Default*: `./image_output` * `--img_name`: Filename of the output image. *Default*: `result` * `--verbose`: Boolean flag indicating if statements should be printed to the console. -- cgit v1.2.3-70-g09d2 From 939faca825404d24556742b26b202c293964bae7 Mon Sep 17 00:00:00 2001 From: Jonathan Böcker Date: Sun, 4 Dec 2016 17:13:54 +0100 Subject: Python 3 compatibility Map objects is not subscriptable in Python 3 --- neural_style.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/neural_style.py b/neural_style.py index 5373e5e..8d40e1b 100644 --- a/neural_style.py +++ b/neural_style.py @@ -535,14 +535,14 @@ def read_flow_file(path): def read_weights_file(path): lines = open(path).readlines() - header = map(int, lines[0].split(' ')) + header = list(map(int, lines[0].split(' '))) w = header[0] h = header[1] vals = np.zeros((h, w), dtype=np.float32) for i in range(1, len(lines)): line = lines[i].rstrip().split(' ') - vals[i-1] = np.array(map(np.float32, line)) - vals[i-1] = map(lambda x: 0. if x < 255. else 1., vals[i-1]) + vals[i-1] = np.array(list(map(np.float32, line))) + vals[i-1] = list(map(lambda x: 0. if x < 255. else 1., vals[i-1])) # expand to 3 channels weights = np.dstack([vals.astype(np.float32)] * 3) return weights -- cgit v1.2.3-70-g09d2 From c3cccf4574caf7b9b8eb7832b65554f4efdf688c Mon Sep 17 00:00:00 2001 From: Cameron Date: Sun, 4 Dec 2016 16:12:05 -0700 Subject: Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 40915a6..53c8b46 100644 --- a/README.md +++ b/README.md @@ -153,8 +153,6 @@ Multiple styles can be transferred to the foreground and background of the conte

*Left to right*: content image, foreground style, background style, foreground mask, background mask, stylized image -*Note*: The masking is done during synthesis; not as a post-processing step. - ### Video Animations can be rendered by applying the algorithm to each source frame. For the best results, the gradient descent is initialized with the previously stylized frame warped to the current frame according to the optical flow between the pair of frames. Loss functions for temporal consistency are used to penalize pixels excluding disoccluded regions and motion boundaries. -- cgit v1.2.3-70-g09d2 From 4ad6137fcac0f486165ea5d74ee97b091bdd0e51 Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 12 Dec 2016 02:04:56 -0700 Subject: Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 53c8b46..3c2196f 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Here we reproduce Figure 3 from the first paper, which renders a photograph of t

- + -- cgit v1.2.3-70-g09d2