Keras: Fix json serialization in Lambda layer broken for windows + python3

Created on 21 Oct 2016  路  3Comments  路  Source: keras-team/keras

here: https://github.com/fchollet/keras/pull/3012 serialization was fixed for lambda layer by adding: .decode('raw_unicode_escape')

however if the code is in a folder or filename starting with the letter u or U, you get \u in the string due to windows notation. for example:
<code object <lambda> at 0x0000000014BEBD20, file "C:\Users\python\u_is_first_letter.py", line 10>

the decode then gives an error as:
UnicodeDecodeError: 'rawunicodeescape' codec can't decode bytes in position ..-..: truncated \uXXXX

apparently this is a python 3 issue. see here: https://bugs.python.org/issue19539

this is on latest master of theano and keras

stale

Most helpful comment

a quick patch i am using in generic_utils.py/func_dump(func) is:

code = marshal.dumps(func.__code__).replace(b'\\',b'/').decode('raw_unicode_escape')

All 3 comments

a quick patch i am using in generic_utils.py/func_dump(func) is:

code = marshal.dumps(func.__code__).replace(b'\\',b'/').decode('raw_unicode_escape')

please reopen. this is still an issue. i missed the stale tag.

I have the same issue when trying to save best weights during training. Please reopen the issue!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anjishnu picture anjishnu  路  3Comments

braingineer picture braingineer  路  3Comments

LuCeHe picture LuCeHe  路  3Comments

snakeztc picture snakeztc  路  3Comments

Imorton-zd picture Imorton-zd  路  3Comments