Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting an error when trying to run #1

Closed
aaronjolson opened this issue Jun 8, 2018 · 4 comments
Closed

Getting an error when trying to run #1

aaronjolson opened this issue Jun 8, 2018 · 4 comments

Comments

@aaronjolson
Copy link

All of the dependencies seemed to install correctly with pip. Any idea what might fix this?

C:\Users\aaols\Documents\large_neural_style>python large_neural_style.py --content eagle.jpg --style lock.jpg --output leagle.jpg

WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
Content image shape:  (2426, 2066, 3)
Pyramid sizes: [(240, 204, 3), (480, 408, 3), (960, 817, 3), (1920, 1635, 3)]
shape: (240, 204, 3)
C:\Python36\lib\site-packages\skimage\transform\_warps.py:105: UserWarning: The default mode, 'constant', will be changed to 'reflect' in skimage 0.15.
  warn("The default mode, 'constant', will be changed to 'reflect' in "
C:\Python36\lib\site-packages\skimage\transform\_warps.py:110: UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images.
  warn("Anti-aliasing will be enabled by default in skimage 0.15 to "
resized_content_image.shape:  (304, 268, 3)
content.shape: (1, 3, 304, 268)
style.shape: (1, 3, 152, 240)
after image_to_shape(), style.shape: (1, 3, 240, 204)
Traceback (most recent call last):
  File "large_neural_style.py", line 193, in <module>
    sys.exit(main())
  File "large_neural_style.py", line 129, in main
    args.print_loss)
  File "C:\Users\aaols\Documents\large_neural_style\stylize.py", line 30, in generate_stylized_image
    stylize = Stylize(content, True, style, content_weight, style_weight, style_layer_weight_factor, total_variation_weight, print_loss, print_progress=True)
  File "C:\Users\aaols\Documents\large_neural_style\stylize.py", line 92, in __init__
    self.net.load_params('vgg19_normalized.pkl')
  File "C:\Users\aaols\Documents\large_neural_style\vgg19.py", line 37, in load_params
    values = pickle.load(open(weights_filename))['param values']
  File "C:\Python36\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 3634: character maps to <undefined>
@aaronjolson
Copy link
Author

aaronjolson commented Jun 8, 2018

I tried changing https://github.com/dnuffer/large_neural_style/blob/master/vgg19.py#L37 to values = pickle.load(open(weights_filename, encoding="utf8"))['param values'] and I get a slightly different error

Traceback (most recent call last):
  File "large_neural_style.py", line 193, in <module>
    sys.exit(main())
  File "large_neural_style.py", line 129, in main
    args.print_loss)
  File "C:\Users\aaols\Documents\large_neural_style\stylize.py", line 30, in generate_stylized_image
    stylize = Stylize(content, True, style, content_weight, style_weight, style_layer_weight_factor, total_variation_weight, print_loss, print_progress=True)
  File "C:\Users\aaols\Documents\large_neural_style\stylize.py", line 92, in __init__
    self.net.load_params('vgg19_normalized.pkl')
  File "C:\Users\aaols\Documents\large_neural_style\vgg19.py", line 37, in load_params
    values = pickle.load(open(weights_filename, encoding="utf8"))['param values']
  File "C:\Python36\lib\codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte

So I am assuming this is some kind of encoding error.

@dnuffer
Copy link
Owner

dnuffer commented Jun 8, 2018

The error is because the weights were pickled with python 2.7 and you're using 3.6. Apparently there's potential incompatibilities. Reading https://stackoverflow.com/questions/28218466/unpickling-a-python-2-object-with-python-3 it seems you can try passing encoding="latin1" to pickle.load(), and if that doesn't work, I'd suggest using python 2.7.

@dnuffer
Copy link
Owner

dnuffer commented Jun 8, 2018

Also you can try using encoding='bytes'

@aaronjolson
Copy link
Author

Ah, I see, thank you!
I changed line 37 to values = pickle.load(open(weights_filename, 'rb'), encoding='latin-1')['param values'] and that has moved me forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants