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

UnicodeDecodeError: 'rawunicodeescape' codec can't decode bytes #17

Closed
williamwongys opened this issue Jul 19, 2017 · 6 comments
Closed

Comments

@williamwongys
Copy link

williamwongys commented Jul 19, 2017

I encountered the above error. I have done some research and found the following:

"Typical error on Windows because the default user directory is C:\user<your_user>, so when you want to use this path as an string parameter into a Python function, you get a Unicode error, just because the \u is a Unicode escape. Any character not numeric after this produces an error.To solve it, just double the backslashes: C:\\user\<\your_user>..."

I checked the codes it is because of the lambda function in the generated model and the system tries to do a func_dump of modelgen.py in my c:\users\anaconda3\lib\site-packages\mcfly directory.

Any suggestion how to get around it?

Here is the detail trace:
File "C:\Users\pactera\Anaconda3\lib\site-packages\mcfly\storage.py", line 33, in savemodel
json_string = model.to_json() # save architecture to json string
File "C:\Users\pactera\Anaconda3\lib\site-packages\keras\engine\topology.py", line 2541, in to_json
model_config = self._updated_config()
File "C:\Users\pactera\Anaconda3\lib\site-packages\keras\engine\topology.py", line 2508, in _updated_config
config = self.get_config()
File "C:\Users\pactera\Anaconda3\lib\site-packages\keras\models.py", line 1179, in get_config
'config': layer.get_config()})
File "C:\Users\pactera\Anaconda3\lib\site-packages\keras\layers\core.py", line 668, in get_config
function = func_dump(self.function)
File "C:\Users\pactera\Anaconda3\lib\site-packages\keras\utils\generic_utils.py", line 177, in func_dump
code = marshal.dumps(func.code).decode('raw_unicode_escape')
UnicodeDecodeError: 'rawunicodeescape' codec can't decode bytes in position 82-83: truncated \UXXXXXXXX escape

@dafnevk
Copy link

dafnevk commented Jul 19, 2017

This is a Keras issue, see keras-team/keras#2582.
It seems to be solved in Keras 2, but can still fail on Windows with Python 3, see: keras-team/keras#4135

Unfortunately, it seems like the only real solution is to fix this in Keras and make a pull request to the Keras repository (see: keras-team/keras#6628).

Another possibility would be to use Python 2.

@williamwongys
Copy link
Author

Are there other alternatives to save the weights? for example, using model.save_weights? pickle?

@williamwongys
Copy link
Author

By making one change to generic_utils.py as suggested in one of your articles links, I managed to save the model, thanks a lot.
#code = marshal.dumps(func.code).decode('raw_unicode_escape')
code = marshal.dumps(func.code).replace(b'\',b'/').decode('raw_unicode_escape')

@zyavrik
Copy link

zyavrik commented Oct 8, 2017

Will the issue be fixed in the repository? I still get it!

@zyavrik
Copy link

zyavrik commented Oct 8, 2017

The following pull request fixes the issue: keras-team/keras#6628 (review)

@hgtavakoli
Copy link

It is RESOLVED for me by replacing this line
code = marshal.dumps(func.code).decode('raw_unicode_escape')
with this line:
code = marshal.dumps(func.code).decode("windows-1252")

In this file: keras\utils\generic_utils.py" ;

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

4 participants