Code Monkey home page Code Monkey logo

neural-style's Introduction

neural-style Build Status

An implementation of neural style in TensorFlow.

This implementation is a lot simpler than a lot of the other ones out there, thanks to TensorFlow's really nice API and automatic differentiation.

TensorFlow doesn't support L-BFGS (which is what the original authors used), so we use Adam. This may require a little bit more hyperparameter tuning to get nice results.

Running

python neural_style.py --content <content file> --styles <style file> --output <output file>

Run python neural_style.py --help to see a list of all options.

Use --checkpoint-output and --checkpoint-iterations to save checkpoint images.

Use --iterations to change the number of iterations (default 1000). For a 512×512 pixel content file, 1000 iterations take 60 seconds on a GTX 1080 Ti, 90 seconds on a Maxwell Titan X, or 60 minutes on an Intel Core i7-5930K. Using a GPU is highly recommended due to the huge speedup.

Example 1

Running it for 500-2000 iterations seems to produce nice results. With certain images or output sizes, you might need some hyperparameter tuning (especially --content-weight, --style-weight, and --learning-rate).

The following example was run for 1000 iterations to produce the result (with default parameters):

output

These were the input images used (me sleeping at a hackathon and Starry Night):

input-content

input-style

Example 2

The following example demonstrates style blending, and was run for 1000 iterations to produce the result (with style blend weight parameters 0.8 and 0.2):

output

The content input image was a picture of the Stata Center at MIT:

input-content

The style input images were Picasso's "Dora Maar" and Starry Night, with the Picasso image having a style blend weight of 0.8 and Starry Night having a style blend weight of 0.2:

input-style input-style

Tweaking

--style-layer-weight-exp command line argument could be used to tweak how "abstract" the style transfer should be. Lower values mean that style transfer of a finer features will be favored over style transfer of a more coarse features, and vice versa. Default value is 1.0 - all layers treated equally. Somewhat extreme examples of what you can achieve:

--style-layer-weight-exp 0.2 --style-layer-weight-exp 2.0

(left: 0.2 - finer features style transfer; right: 2.0 - coarser features style transfer)

--content-weight-blend specifies the coefficient of content transfer layers. Default value - 1.0, style transfer tries to preserve finer grain content details. The value should be in range [0.0; 1.0].

--content-weight-blend 1.0 --content-weight-blend 0.1

(left: 1.0 - default value; right: 0.1 - more abstract picture)

--pooling allows to select which pooling layers to use (specify either max or avg). Original VGG topology uses max pooling, but the style transfer paper suggests replacing it with average pooling. The outputs are perceptually different, max pool in general tends to have finer detail style transfer, but could have troubles at lower-freqency detail level:

--pooling max --pooling avg

(left: max pooling; right: average pooling)

--preserve-colors boolean command line argument adds post-processing step, which combines colors from the original image and luma from the stylized image (YCbCr color space), thus producing color-preserving style transfer:

--pooling max --pooling max

(left: original stylized image; right: color-preserving style transfer)

Requirements

Data Files

  • Pre-trained VGG network (MD5 106118b7cf60435e6d8e04f6a6dc3657) - put it in the top level of this repository, or specify its location using the --network option.

Dependencies

You can install Python dependencies using pip install -r requirements.txt, and it should just work. If you want to install the packages manually, here's a list:

Related Projects

See here for an implementation of fast (feed-forward) neural style in TensorFlow.

Try neural style client-side in your web browser without installing any software (using TensorFire).

Citation

If you use this implementation in your work, please cite the following:

@misc{athalye2015neuralstyle,
  author = {Anish Athalye},
  title = {Neural Style},
  year = {2015},
  howpublished = {\url{https://github.com/anishathalye/neural-style}},
}

License

Copyright (c) Anish Athalye. Released under GPLv3. See LICENSE.txt for details.

neural-style's People

Contributors

akx avatar anishathalye avatar avoroshilov avatar daj avatar elcorto avatar emergencytemporalshift avatar fatalchemist avatar jason-cooke avatar jwrubel avatar kararyougi avatar khughitt avatar martinligabue avatar naelsondouglas avatar neilsh avatar supertobi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neural-style's Issues

KeyError from data['normalization'] in vgg

KeyError                                  Traceback (most recent call last)
/Users/diego/src/neural-style/vgg.py in <module>()
----> 1 data['normalization']

KeyError: 'normalization'

What version of scipy should I install? I also downloaded imagenet-vgg-verydeep-19.mat from http://www.vlfeat.org/matconvnet/pretrained/. Hoping that's correct. Looks like your code loads that file from the neural-style directory yet it's not part of the repo. I only downloaded it after I tried running neural-style and it errored saying it couldn't load that file. Then I placed it in the neural-style directory and it worked up until the data['normalization'] line.

When I debug data I get a huge structure with these keys:

data.keys()
dict_keys(['__globals__', 'meta', 'layers', '__header__', '__version__'])

The __version__ key returns '1.0'

my scipy version is 0.16.1

program killed

I just run the program on my VPS ubuntu14.04 with 1G RAM
This program just run 1 iteration and be killed?
here is the report:

'Optimization started...
Iteration 1/1000
Killed'

what's problem?Is about the computation power?

Install error

➜  neural-style git:(master) ✗ python neural_style.py --content /Users/zhengzhongzhao/Desktop/IMG_0200.jpg --output 1.jpg --styles STYLE
Traceback (most recent call last):
  File "neural_style.py", line 122, in <module>
    main()
  File "neural_style.py", line 75, in main
    content_image = imread(options.content)
  File "neural_style.py", line 113, in imread
    return scipy.misc.imread(path).astype(np.float)
AttributeError: 'module' object has no attribute 'imread'

Thanks!

key error ''

Hi!

I got this error end of the iterations. It prints content, style, tv and total loss then this error appears. I'm not a good Python coder so I didn't get any idea about it. By the way I'm using TF 1.0 on the Windows 7 with Anaconda3.

Traceback (most recent call last): File "neural_style.py", line 156, in <module> main() File "neural_style.py", line 139, in main imsave(output_file, image) File "neural_style.py", line 152, in imsave scipy.misc.imsave(path, img) File "C:\Program Files\Anaconda3\lib\site-packages\scipy\misc\pilutil.py", line 197, in imsave im.save(name) File "C:\Program Files\Anaconda3\lib\site-packages\PIL\Image.py", line 1713, in save format = EXTENSION[ext] KeyError: ''

Initialize update

In stylize.py: 113 , changing

            sess.run(tf.initialize_all_variables())

To

            sess.run(tf.global_variables_initializer())

About extracting frames for video files

This is beside the neural-style project, but I wonder how you extract frames for your video processing.
I also wonder if jpeg or png make a different in quality of the algorithm. I play around with ffmpeg and see varying results with frame extraction (sometimes the result just isn't very fluid)

Problems with the code for texture synthesis

Hi,

First, thanks a lot for your code!

I tried this code for texture synthesis by setting the content weight to zero. The result is much worse than that by the torch code: https://github.com/jcjohnson/neural-style

I finally figure out the issues. In the vgg network, the max pooling should be replaced by the average pooling. This helps a lot! Also, the TV loss should be L1 norm of the gradients instead of L2 norm. It improves the quality.

Thanks!

Validity of arguments should be checked before running

When one mistypes the value for the --output parameter, the program will run for a possibly long time and then, upon trying to save the image, crash. It would be better to check before if the output file is actually writable.

Download a wrong imagenet vgg

I use python3 to run your script, and it shows the following error:

File "neural_style.py", line 152, in
main()
File "neural_style.py", line 130, in main
checkpoint_iterations=options.checkpoint_iterations
File "/DeepLearn/neural-style-master/stylize.py", line 41, in stylize
net, mean_pixel = vgg.net(network, image)
File "
/DeepLearn/neural-style-master/vgg.py", line 25, in net
mean = data['normalization'][0][0][0]
KeyError: 'normalization'

thank for help me

Only 26 iterations within 10 hours on CPU CORE i5

I am now using my laptop, Core i5 CPU only and TensorFlow 0.9, to train a photo, and waited for 10 hours it only gets to iteration 26. Is it an expected performance on CPU ? It seems for full 1000 iteration it'll take more than a week for a single image.

Is there a possibility to improve the speed ?

Expecting matrix error

Hello
When runing the script i get this error.

MacBook-Pro-de-Gonzalo:deepstyle Gonz$ python neural_style.py --content /Users/Gonz/Desktop/rigoOriginal.jpg --styles /Users/Gonz/Desktop/textura.jpg --output /Users/Gonz/Desktop/chida.jpg
Traceback (most recent call last):
File "neural_style.py", line 206, in
main()
File "neural_style.py", line 177, in main
checkpoint_iterations=options.checkpoint_iterations
File "/Users/Gonz/Desktop/deepstyle/stylize.py", line 39, in stylize
vgg_weights, vgg_mean_pixel = vgg.load_net(network)
File "/Users/Gonz/Desktop/deepstyle/vgg.py", line 23, in load_net
data = scipy.io.loadmat(data_path)
File "/usr/local/lib/python2.7/site-packages/scipy/io/matlab/mio.py", line 136, in loadmat
matfile_dict = MR.get_variables(variable_names)
File "/usr/local/lib/python2.7/site-packages/scipy/io/matlab/mio5.py", line 292, in get_variables
res = self.read_var_array(hdr, process)
File "/usr/local/lib/python2.7/site-packages/scipy/io/matlab/mio5.py", line 252, in read_var_array
return self._matrix_reader.array_from_header(header, process)
File "scipy/io/matlab/mio5_utils.pyx", line 673, in scipy.io.matlab.mio5_utils.VarReader5.array_from_header (/private/var/folders/gw/_2jq29095y7b__wtby9dg_5h0000gn/T/pip-8Za6y9-build/scipy/io/matlab/mio5_utils.c:7119)
File "scipy/io/matlab/mio5_utils.pyx", line 719, in scipy.io.matlab.mio5_utils.VarReader5.array_from_header (/private/var/folders/gw/_2jq29095y7b__wtby9dg_5h0000gn/T/pip-8Za6y9-build/scipy/io/matlab/mio5_utils.c:6517)
File "scipy/io/matlab/mio5_utils.pyx", line 892, in scipy.io.matlab.mio5_utils.VarReader5.read_cells (/private/var/folders/gw/_2jq29095y7b__wtby9dg_5h0000gn/T/pip-8Za6y9-build/scipy/io/matlab/mio5_utils.c:8922)
File "scipy/io/matlab/mio5_utils.pyx", line 671, in scipy.io.matlab.mio5_utils.VarReader5.read_mi_matrix (/private/var/folders/gw/_2jq29095y7b__wtby9dg_5h0000gn/T/pip-8Za6y9-build/scipy/io/matlab/mio5_utils.c:6027)
File "scipy/io/matlab/mio5_utils.pyx", line 721, in scipy.io.matlab.mio5_utils.VarReader5.array_from_header (/private/var/folders/gw/_2jq29095y7b__wtby9dg_5h0000gn/T/pip-8Za6y9-build/scipy/io/matlab/mio5_utils.c:6547)
File "scipy/io/matlab/mio5_utils.pyx", line 967, in scipy.io.matlab.mio5_utils.VarReader5.read_struct (/private/var/folders/gw/_2jq29095y7b__wtby9dg_5h0000gn/T/pip-8Za6y9-build/scipy/io/matlab/mio5_utils.c:9877)
File "scipy/io/matlab/mio5_utils.pyx", line 671, in scipy.io.matlab.mio5_utils.VarReader5.read_mi_matrix (/private/var/folders/gw/_2jq29095y7b__wtby9dg_5h0000gn/T/pip-8Za6y9-build/scipy/io/matlab/mio5_utils.c:6027)
File "scipy/io/matlab/mio5_utils.pyx", line 719, in scipy.io.matlab.mio5_utils.VarReader5.array_from_header (/private/var/folders/gw/_2jq29095y7b__wtby9dg_5h0000gn/T/pip-8Za6y9-build/scipy/io/matlab/mio5_utils.c:6517)
File "scipy/io/matlab/mio5_utils.pyx", line 892, in scipy.io.matlab.mio5_utils.VarReader5.read_cells (/private/var/folders/gw/_2jq29095y7b__wtby9dg_5h0000gn/T/pip-8Za6y9-build/scipy/io/matlab/mio5_utils.c:8922)
File "scipy/io/matlab/mio5_utils.pyx", line 664, in scipy.io.matlab.mio5_utils.VarReader5.read_mi_matrix (/private/var/folders/gw/_2jq29095y7b__wtby9dg_5h0000gn/T/pip-8Za6y9-build/scipy/io/matlab/mio5_utils.c:5851)
TypeError: Expecting matrix here

Don't know where it comes from.
Thank you @anishathalye for this great implementation!!

UPDATE!
I know for shure the error comes when loading the vgg model in scipy.io.loadmat

Aborted (core dumped)

Hi,could you give me some advice to solve this problem?
``
CUDA_VISIBLE_DEVICES=1` python neural_style.py --content examples/1-content.jpg --styles examples/1-style.jpg --output examples/TF1.jpg
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcurand.so locally
E tensorflow/stream_executor/cuda/cuda_driver.cc:491] failed call to cuInit: CUDA_ERROR_NO_DEVICE
I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:153] retrieving CUDA diagnostic information for host: icra-All-Series
I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:160] hostname: icra-All-Series
I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:185] libcuda reported version is: 367.48.0
I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:356] driver version file contents: """NVRM version: NVIDIA UNIX x86_64 Kernel Module 367.48 Sat Sep 3 18:21:08 PDT 2016
GCC version: gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
"""
I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:189] kernel reported version is: 367.48.0
I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:293] kernel version seems to match DSO: 367.48.0
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted (core dumped)

ran out of memory

Hello Anish Athalye,

Thanks for sharing such great repo.
I met 'ran out of memory' issue when using TensorFLow 0.9 + Cuda 7.5 on a single Titan X card (12GB memory).

However, when I reduce the input image to size 100 pixel * 100 pixel, it works well, but as you can imagine, the output image is too small to see.

Any suggestions ?

Cheers,
Dorje

Error runing

Got this error message:

neural_style.py: error: Network imagenet-vgg-verydeep-19.mat does not exist. (Did you forget to download it?)

System Freeze

First, thank you for this amazing work.
I'm using GTX 1080.
I can run your example pictures very well.
But when I use my own picture which I had already reduce the image to 764x615, the system freeze.
The program went well at first, but when the iterations is about 300 times, the system broke down.
The screen went black and the graphic card's fan runs loudly.
And the computer won't respond to anything that I had to shut it down.

Any suggestions ?
Thank you.

Required Arguments Error: --content, --styles, --output BUT I TYPED THEM

This must be some simple thing I'm over looking cause I've tried this within and without anaconda2 in python2.7 and python3.5. I tried to figure this out myself but this is always what I get for the first "argument" written in terminal.
Everything is in it's right place, the wheights are loaded and listed in the .py file. All requirements are installed. My photos are where the paths say they are.

$
$
$ python3.5 ~/path_to/neural_style.py -—content ~/anaconda2/envs/gnar/neural-style-master/A.jpg -—styles ~/anaconda2/envs/gnar/neural-style-master/S.jpg -—output /anaconda2/envs/gnar/neural-style-master/000.jpg
usage: neural_style.py [-h] --content CONTENT --styles STYLE [STYLE ...]
--output OUTPUT [--checkpoint-output OUTPUT]
[--iterations ITERATIONS] [--width WIDTH]
[--style-scales STYLE_SCALE [STYLE_SCALE ...]]
[--network VGG_PATH] [--content-weight CONTENT_WEIGHT]
[--style-weight STYLE_WEIGHT]
[--style-blend-weights STYLE_BLEND_WEIGHT [STYLE_BLEND_WEIGHT ...]]
[--tv-weight TV_WEIGHT] [--learning-rate LEARNING_RATE]
[--initial INITIAL]
[--print-iterations PRINT_ITERATIONS]
[--checkpoint-iterations CHECKPOINT_ITERATIONS]
neural_style.py: error: the following arguments are required: --content, --styles, --output
$

VGG16-face

I have a dumb question, could I use the vgg.py to load vgg-face.mat model to creating face style?

I have changed the vgg.py network description as following:

Original VGG19 layer
` VGG19_LAYERS = (
'conv1_1', 'relu1_1', 'conv1_2', 'relu1_2', 'pool1',

'conv2_1', 'relu2_1', 'conv2_2', 'relu2_2', 'pool2',

'conv3_1', 'relu3_1', 'conv3_2', 'relu3_2', 'conv3_3',
'relu3_3', 'conv3_4', 'relu3_4', 'pool3',

'conv4_1', 'relu4_1', 'conv4_2', 'relu4_2', 'conv4_3',
'relu4_3', 'conv4_4', 'relu4_4', 'pool4',

'conv5_1', 'relu5_1', 'conv5_2', 'relu5_2', 'conv5_3',
'relu5_3', 'conv5_4', 'relu5_4'

)`

Change to VGG-16 layer
`VGG16_LAYERS = (
'conv1_1', 'relu1_1', 'conv1_2', 'relu1_2', 'pool1',

'conv2_1', 'relu2_1', 'conv2_2', 'relu2_2', 'pool2',

'conv3_1', 'relu3_1', 'conv3_2', 'relu3_2', 'conv3_3',
'relu3_3', 'pool3',

'conv4_1', 'relu4_1', 'conv4_2', 'relu4_2', 'conv4_3',
'relu4_3', 'pool4',

'conv5_1', 'relu5_1', 'conv5_2', 'relu5_2', 'conv5_3',
'relu5_3'

)`
After download the imagenet-vgg-verydeep-16
, it's work to use vgg16 model.
When I change the model to vgg-face
, it will print error message as following:

File "neural_style.py", line 177, in main checkpoint_iterations=options.checkpoint_iterations File "/neural-style/stylize.py", line 58, in stylize net = vgg.net_preloaded(vgg_weights, image, pooling) File "/neural-style/vgg.py", line 52, in net_preloaded kernels, bias = weights[i][0][0][0][0] ValueError: too many values to unpack

Can anyone give me some idea to fix it?

How do you make the imagenet-vgg-verydeep-19.mat

I'm working on a project and I need only part of vgg16 in my work. So I want to look at your code and figure out how to do that. But it seems like you didn't share your code for making imagenet-vgg-verydeep-19.mat.
Can I know more about how do you get the imagenet-vgg-verydeep-19.mat file

--output cann`t support *.jpg

Iteration 1499/1500
Iteration 1500/1500
  content loss: 1.16644e+06
    style loss: 348997
       tv loss: 83460.1
    total loss: 1.59889e+06
Traceback (most recent call last):
  File "neural_style.py", line 206, in <module>
    main()
  File "neural_style.py", line 187, in main
    imsave(output_file, combined_rgb)
  File "neural_style.py", line 203, in imsave
    Image.fromarray(img).save(path, quality=95)
  File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 1713, in save
    format = EXTENSION[ext]
KeyError: '.jgp'

I do not have a video card, use i5 6500 cpu, I spent 7 hours running a case, because I used the --output * .jpg,Please increase the friendliness of this question, thank you!

Distributed computing

Newbie in machine learning here.

Any suggestions/directions where one would go in terms of making the process distributed?

KeyError: 'normalization'

python neural_style.py --content examples/1-content.jpg --styles examples/1-style.jpg --output output0.jpg

Traceback (most recent call last):
  File "neural_style.py", line 152, in <module>
    main()
  File "neural_style.py", line 130, in main
    checkpoint_iterations=options.checkpoint_iterations
  File "/home/markb/Dev/neural-style/stylize.py", line 41, in stylize
    net, mean_pixel = vgg.net(network, image)
  File "/home/markb/Dev/neural-style/vgg.py", line 26, in net
    mean = data['normalization'][0][0][0]
KeyError: 'normalization'

Where and How do you find the description of .mat file?

Your code makes sense. I learned quick a lot.

One biggest confusion is how can you know what all these .mat matrices means?

Is there any web pages that describe what each axis/dimension of .mat matrices means?

Because I am trying to re-implement neural-style to fit my needs, I need to know the original network data in detail.

Thank you

Default configuration

Hi Anish,

I'm trying to reproduce the results of your example and am not producing great results. I'm using the current configuration as provided (1000 iterations).

Inputs

content
style

Output

output1

Expected

1-output

As you can see, my result looks noisy and doesn't have smooth color blends.

Do you know the configuration you had to make your example output (and can we make that configuration the default)? Maybe I should try increasing STYLE_WEIGHT.

Cheers,
Grant

ValueError: Shape (1, 199, 153) must have rank 4

Hi, the example 1 in the Readme.md is OK on my laptop. It is interesting!
but, when I try this code with my picture, it raises the following error:

$ python neural_style.py --content LiX.jpg --styles 1-style.jpg --output 2-output.jpg
Traceback (most recent call last):
File "neural_style.py", line 152, in
main()
File "neural_style.py", line 130, in main
checkpoint_iterations=options.checkpoint_iterations
File "/Users/ldl/Documents/neural-style/stylize.py", line 41, in stylize
net, mean_pixel = vgg.net(network, image)
File "/Users/ldl/Documents/neural-style/vgg.py", line 39, in net
current = _conv_layer(current, kernels, bias)
File "/Users/ldl/Documents/neural-style/vgg.py", line 52, in _conv_layer
padding='SAME')
File "/Users/ldl/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/gen_nn_ops.py", line 394, in conv2d
data_format=data_format, name=name)
File "/Users/ldl/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 703, in apply_op
op_def=op_def)
File "/Users/ldl/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2319, in create_op
set_shapes_for_outputs(ret)
File "/Users/ldl/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1711, in set_shapes_for_outputs
shapes = shape_func(op)
File "/Users/ldl/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 209, in conv2d_shape
input_shape = op.inputs[0].get_shape().with_rank(4)
File "/Users/ldl/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/tensor_shape.py", line 641, in with_rank
raise ValueError("Shape %s must have rank %d" % (self, rank))
ValueError: Shape (1, 199, 153) must have rank 4

In my laptop
tensorflow: version 0.10

I don't know how to modify it to get it work.

Error in reading the image

Hi,
I face the following error,
I added some printing in order to debug it.
def imread(path):
print "path is ", path
img = scipy.misc.imread(path)
print "img is ", img
return scipy.misc.imread(path).astype(np.float)

The reading of the image is working manually in a ipython notebook, but not with the script.
Any ideas?

python neural_style.py --content /home/antgr/input-image.jpg --styles /home/antgr/style.jpg --output /home/antgr/output.jpg
path is /home/antgr/input-image.jpg
img is < PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=1600x1200 at 0x7FF3CA714710 >
Traceback (most recent call last):
File "neural_style.py", line 153, in
main()
File "neural_style.py", line 83, in main
content_image = imread(options.content)
File "neural_style.py", line 144, in imread
return scipy.misc.imread(path).astype(np.float)
TypeError: float() argument must be a string or a number

KeyError: 'normalization'

hello, I get an error when I run the command. I check the imagenet-vgg-verydeep-19.mat, it's md5sum is same of the offical's.
I don't get some idea. Could I get some help, thanks.

$ python neural_style.py --content ./1-content.jpg --styles ./1-style.jpg --output ./out.jpeg
Traceback (most recent call last):
File "neural_style.py", line 152, in
main()
File "neural_style.py", line 130, in main
checkpoint_iterations=options.checkpoint_iterations
File "/root/neural-style/stylize.py", line 41, in stylize
net, mean_pixel = vgg.net(network, image)
File "/root/neural-style/vgg.py", line 25, in net
mean = data['normalization'][0][0][0]
KeyError: 'normalization'

python version:

$ python --version
Python 2.7.5

list of dir:

$ ll
total 523236
-rw-r--r--. 1 root root 245099 Oct 26 19:20 1-content.jpg
-rw-r--r--. 1 root root 562577 Oct 26 19:22 1-style.jpg
-rw-r--r--. 1 root root 35147 Oct 26 19:25 LICENSE.txt
-rw-r--r--. 1 root root 3030 Oct 26 19:25 README.md
drwxr-xr-x. 2 root root 4096 Oct 26 19:25 examples
-rw-r--r--. 1 root root 534904783 Oct 27 02:17 imagenet-vgg-verydeep-19.mat
-rw-r--r--. 1 root root 5820 Oct 26 19:25 neural_style.py
-rw-r--r--. 1 root root 5357 Oct 26 19:25 stylize.py
-rw-r--r--. 1 root root 5035 Oct 26 20:20 stylize.pyc
-rw-r--r--. 1 root root 1964 Oct 27 02:40 vgg.py
-rw-r--r--. 1 root root 2653 Oct 27 02:40 vgg.pyc

os version:

$ cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

CPU 0?

Why is the coding using CPU 0?
Any specific reason?

Dataset

How many style images did you need to learn just one style?

Why max pooling instead of average pooling as per paper?

Hi Anish Athalye,

I am not sure if this is the appropriate way of communication, but I don't know what else to do. In your code you seem to use max pooling while in the neural style paper you referenced the authors claim that better results are obtained by using average pooling. I tried it out myself and there is a very noticeable difference in using one or the other. Average pooling makes the images look much smoother and more like the original content image. While max pooling makes the images more painting like.

I wondered if this was a deliberate choice of yours and if so, why did you choose max pooling over average pooling? I am just curious to know :)

Greetings!

PS Below attached two pictures, one generated with avg pooling, the other with max pooling, such that you can see it for yourself.

Average pooling:
result-avg-pool

Max pooling:
result-max-pool

Original content:
face

Style:
woman-with-hat-matisse

imagenet--vgg-verydeep-19.mat

I want to know what's the structure of imagenet-vgg-verydeep-19.mat. Of course,I can get the detail structure with the help of scipy.io.loadmat(). But,I think it's not convenient . where can i get the detail description of imagenet--vgg-verydeep-19.mat. Can you give me a exact link?
Thanks.

Why should the style layer weights be normalized?

The style loss in the older version which has no "tweak" simply add the loss of different style layers together. But in the latest version even when the style_layer_weight_exp is 1 all the loss will be 1/5 compare to the older version. Is it reasonable? Or the style_weight is correspondingly modified?

CuDNN version

Hi I got the following error message:

Loaded runtime CuDNN library: 5103 (compatibility version 5100) but source was compiled with 4007 (compatibility version 4000). If using a binary install, upgrade your CuDNN library to match. If building from sources, make sure the library loaded at runtime matches a compatible version specified during compile configuration.

I'm using CUDA 7.5 and cuDNN 5.1. Am I supposed to downgrade cuDNN to 4.x? Thanks!

choose GPU device

hi there, great one!

one question, I got 3 GPUs to work with, how to choose which GPU to use?

I mean, I dont want to use gpu_0 cause my monitors are connected with it.
I wish to use GPU_1 instead...

THanks!

problem loading mat file

Hi, I get the following error in vgg.py:

Traceback (most recent call last):
File "/Users/cuongwilliams/Packages/neural-style/neural_style.py", line 122, in
main()
File "/Users/cuongwilliams/Packages/neural-style/neural_style.py", line 108, in main
checkpoint_iterations=options.checkpoint_iterations)
File "/Users/cuongwilliams/Packages/neural-style/stylize.py", line 24, in stylize
net, mean_pixel = vgg.net(network, image)
File "/Users/cuongwilliams/Packages/neural-style/vgg.py", line 24, in net
mean = data['normalization'][0][0][0]
KeyError: 'normalization'

Any thoughts what I might be doing wrong ? I do use the --network parameter to specify the location of the mat file.

Program crashes when using png with alpha channel

When using an srgba image like this one:
brain2
the program crashes with

Traceback (most recent call last):
  File "neural_style.py", line 156, in <module>
    main()
  File "neural_style.py", line 130, in main
    checkpoint_iterations=options.checkpoint_iterations
  File "/home/ubuntu/neural-style/stylize.py", line 51, in stylize
    net, _ = vgg.net(network, image)
  File "/home/ubuntu/neural-style/vgg.py", line 39, in net
    current = _conv_layer(current, kernels, bias)
  File "/home/ubuntu/neural-style/vgg.py", line 52, in _conv_layer
    padding='SAME')
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_nn_ops.py", line 394, in conv2d
    data_format=data_format, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 703, in apply_op
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2319, in create_op
    set_shapes_for_outputs(ret)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1711, in set_shapes_for_outputs
    shapes = shape_func(op)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/common_shapes.py", line 230, in conv2d_shape
    input_shape[3].assert_is_compatible_with(filter_shape[2])
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_shape.py", line 108, in assert_is_compatible_with
    % (self, other))
ValueError: Dimensions 4 and 3 are not compatible

CUDA_ERROR_OUT_OF_MEMORY

when I try to run
python neural_style.py --styles art.jpg --content panther-400x200.jpg --output var/log/pictures/result.png --checkpoint-iterations 10
I got the following error

I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcublas.so locally I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcudnn.so locally I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcufft.so locally I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcuda.so.1 locally I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcurand.so locally I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:925] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero I tensorflow/core/common_runtime/gpu/gpu_device.cc:951] Found device 0 with properties: name: GeForce GTX 960 major: 5 minor: 2 memoryClockRate (GHz) 1.304 pciBusID 0000:01:00.0 Total memory: 3.94GiB Free memory: 184.38MiB I tensorflow/core/common_runtime/gpu/gpu_device.cc:972] DMA: 0 I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] 0: Y I tensorflow/core/common_runtime/gpu/gpu_device.cc:1041] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 960, pci bus id: 0000:01:00.0) E tensorflow/stream_executor/cuda/cuda_driver.cc:965] failed to allocate 184.38M (193331200 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY Traceback (most recent call last): File "neural_style.py", line 152, in <module> main() File "neural_style.py", line 130, in main checkpoint_iterations=options.checkpoint_iterations File "/home/a.mirandi/neural-style/stylize.py", line 41, in stylize net, mean_pixel = vgg.net(network, image) File "/home/a.mirandi/neural-style/vgg.py", line 25, in net mean = data['normalization'][0][0][0] KeyError: 'normalization'

what could be wrong ? the memory total memory is large enough but the available memory is small

KeyError: 'normalization'

I run the command

python neural_style.py --content ./examples/1-content.jpg --styles ./examples/1-style.jpg --output ./examples/1-output.jpg

but got this error

Traceback (most recent call last):
  File "neural_style.py", line 156, in <module>
    main()
  File "neural_style.py", line 130, in main
    checkpoint_iterations=options.checkpoint_iterations
  File "/home/shelly/gitProjects/neural-style/stylize.py", line 41, in stylize
    net, mean_pixel = vgg.net(network, image)
  File "/home/shelly/gitProjects/neural-style/vgg.py", line 25, in net
    mean = data['normalization'][0][0][0]
KeyError: 'normalization'

maybe a bug ?

W tensorflow/core/common_runtime/bfc_allocator.cc:274] ****************************************************************************************xxxxxxxxxxxx

tensorflow/core/common_runtime/bfc_allocator.cc:696] 3 Chunks of size 6860800 totalling 19.63MiB
I tensorflow/core/common_runtime/bfc_allocator.cc:696] 13 Chunks of size 9437184 totalling 117.00MiB
I tensorflow/core/common_runtime/bfc_allocator.cc:696] 1 Chunks of size 59686400 totalling 56.92MiB
I tensorflow/core/common_runtime/bfc_allocator.cc:696] 1 Chunks of size 103601920 totalling 98.80MiB
I tensorflow/core/common_runtime/bfc_allocator.cc:700] Sum Total of in-use chunks: 369.92MiB
I tensorflow/core/common_runtime/bfc_allocator.cc:702] Stats:
Limit: 387907584
InUse: 387890944
MaxInUse: 387907584
NumAllocs: 622
MaxAllocSize: 147177472

W tensorflow/core/common_runtime/bfc_allocator.cc:274] ****************************************************************************************xxxxxxxxxxxx
W tensorflow/core/common_runtime/bfc_allocator.cc:275] Ran out of memory trying to allocate 2.44MiB. See logs for memory state.
W tensorflow/core/framework/op_kernel.cc:993] Resource exhausted: OOM when allocating tensor with shape[1,533,400,3]

this is why?

IOError: could not read bytes

According your introduction , I execute it in shell, here I met a problem:

alex@alex-ubuntu1604:~/myprivate/github/neural-style$ python neural_style.py --content ./examples/1-content.jpg --styles ./examples/1-style.jpg --output ./examples/hello.jpg
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcurand.so locally
I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties: 
name: GeForce GTX 1080
major: 6 minor: 1 memoryClockRate (GHz) 1.797
pciBusID 0000:01:00.0
Total memory: 7.92GiB
Free memory: 7.34GiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0:   Y 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:01:00.0)
Traceback (most recent call last):
  File "neural_style.py", line 156, in <module>
    main()
  File "neural_style.py", line 130, in main
    checkpoint_iterations=options.checkpoint_iterations
  File "/home/alex/myprivate/github/neural-style/stylize.py", line 41, in stylize
    net, mean_pixel = vgg.net(network, image)
  File "/home/alex/myprivate/github/neural-style/vgg.py", line 24, in net
    data = scipy.io.loadmat(data_path)
  File "/usr/local/lib/python2.7/dist-packages/scipy/io/matlab/mio.py", line 136, in loadmat
    matfile_dict = MR.get_variables(variable_names)
  File "/usr/local/lib/python2.7/dist-packages/scipy/io/matlab/mio5.py", line 292, in get_variables
    res = self.read_var_array(hdr, process)
  File "/usr/local/lib/python2.7/dist-packages/scipy/io/matlab/mio5.py", line 252, in read_var_array
    return self._matrix_reader.array_from_header(header, process)
  File "scipy/io/matlab/mio5_utils.pyx", line 673, in scipy.io.matlab.mio5_utils.VarReader5.array_from_header (scipy/io/matlab/mio5_utils.c:7119)
  File "scipy/io/matlab/mio5_utils.pyx", line 719, in scipy.io.matlab.mio5_utils.VarReader5.array_from_header (scipy/io/matlab/mio5_utils.c:6517)
  File "scipy/io/matlab/mio5_utils.pyx", line 892, in scipy.io.matlab.mio5_utils.VarReader5.read_cells (scipy/io/matlab/mio5_utils.c:8922)
  File "scipy/io/matlab/mio5_utils.pyx", line 671, in scipy.io.matlab.mio5_utils.VarReader5.read_mi_matrix (scipy/io/matlab/mio5_utils.c:6027)
  File "scipy/io/matlab/mio5_utils.pyx", line 721, in scipy.io.matlab.mio5_utils.VarReader5.array_from_header (scipy/io/matlab/mio5_utils.c:6547)
  File "scipy/io/matlab/mio5_utils.pyx", line 967, in scipy.io.matlab.mio5_utils.VarReader5.read_struct (scipy/io/matlab/mio5_utils.c:9877)
  File "scipy/io/matlab/mio5_utils.pyx", line 671, in scipy.io.matlab.mio5_utils.VarReader5.read_mi_matrix (scipy/io/matlab/mio5_utils.c:6027)
  File "scipy/io/matlab/mio5_utils.pyx", line 719, in scipy.io.matlab.mio5_utils.VarReader5.array_from_header (scipy/io/matlab/mio5_utils.c:6517)
  File "scipy/io/matlab/mio5_utils.pyx", line 892, in scipy.io.matlab.mio5_utils.VarReader5.read_cells (scipy/io/matlab/mio5_utils.c:8922)
  File "scipy/io/matlab/mio5_utils.pyx", line 671, in scipy.io.matlab.mio5_utils.VarReader5.read_mi_matrix (scipy/io/matlab/mio5_utils.c:6027)
  File "scipy/io/matlab/mio5_utils.pyx", line 703, in scipy.io.matlab.mio5_utils.VarReader5.array_from_header (scipy/io/matlab/mio5_utils.c:6244)
  File "scipy/io/matlab/mio5_utils.pyx", line 776, in scipy.io.matlab.mio5_utils.VarReader5.read_real_complex (scipy/io/matlab/mio5_utils.c:7572)
  File "scipy/io/matlab/mio5_utils.pyx", line 448, in scipy.io.matlab.mio5_utils.VarReader5.read_numeric (scipy/io/matlab/mio5_utils.c:4323)
  File "scipy/io/matlab/mio5_utils.pyx", line 353, in scipy.io.matlab.mio5_utils.VarReader5.read_element (scipy/io/matlab/mio5_utils.c:3913)
  File "scipy/io/matlab/streams.pyx", line 327, in scipy.io.matlab.streams.FileStream.read_string (scipy/io/matlab/streams.c:4992)
IOError: could not read bytes
alex@alex-ubuntu1604:~/myprivate/github/neural-style$ 

Document how to run this in AWS

It would be great if there were instructions on how to run this in AWS, using an existing AMI (e.g. this). This would avoid people needing to configure all the dependencies, which was a real pain for me. The instructions would need to explain how to save the images that are created - presumably you'd need to configure it to save them into S3 or somewhere you can retrieve them from.

Feel free to close this as it's an enhancement suggestion. :-)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.