Keras model.to_json () error: "rawunicodeescape" codec cannot decode bytes at positions 94-98: truncated \ uXXXX

model.to_json() 

for model

_____________________________________________________________________________________________________ Layer (type) Output Form Form #
Connected to ================================================ == ================================================= == lambda_1 (Lambda) (None, 3, 160, 320) 0
lambda_input_1 [0] [0]
____________________________________________________________________________________________________ convolution2d_1 (Convolution2D) (None, 1, 40, 16) 327696
lambda_1 [0] [0]
____________________________________________________________________________________________________ elu_1 (ELU) (None, 1, 40, 16) 0
convolution2d_1 [0] [0]
____________________________________________________________________________________________________ convolution2d_2 (Convolution2D) (None, 1, 20, 32) 12832
elu_1 [0] [0]
____________________________________________________________________________________________________ elu_2 (ELU) (None, 1, 20, 32) 0
convolution2d_2 [0] [0]
____________________________________________________________________________________________________ convolution2d_3 (Convolution2D) (None, 1, 10, 64) 51264
elu_2 [0] [0]
_____________________________________________________________________________________________________ flatten_1 (Flatten) (None, 640) 0
convolution2d_3 [0] [0]
_____________________________________________________________________________________________________ dropout_1 (exception) (None, 640) 0
flatten_1 [0] [0]
____________________________________________________________________________________________________ elu_3 (ELU) (None, 640) 0
dropout_1 [0] [0]
____________________________________________________________________________________________________ dense_1 (Tight) (None, 512) 328192
elu_3 [0] [0]
_____________________________________________________________________________________________________ dropout_2 (exception) (none, 512) 0
dense_1 [0] [0]
____________________________________________________________________________________________________ elu_4 (ELU) (None, 512) 0
dropout_2 [0] [0]
____________________________________________________________________________________________________ dense_2 (Tight) (None, 1) 513
elu_4 [0] [0]
=================================================== =================================================== Total parameters: 720,497 Training parameters: 720,497 Non-learning parameters: 0 ____________________________________________________________________________________________________ None

throws an exception

'rawunicodeescape' codec cannot decode bytes at positions 94-98: truncated \ uXXXX

What could be the problem and how can I solve it?

+6
source share
3 answers

I ran into a similar problem when using keras 1.2.1 using tensorflow-gpu backend.

I found out that this was because the 10th edition of Windows had problems with the encoding of the forward slash character.

Using the Lambda layer makes the to_json() call complete, but switching to batch normalization works just fine.

 model = Sequential() # model.add(Lambda(lambda x: x / 255. - .5, input_shape=INPUT_DIMENSIONS)) model.add(BatchNormalization(input_shape=INPUT_DIMENSIONS, axis=1)) . . . # POST PROCESSING, SAVE MODEL TO DISK with open('model.json', 'w') as json_file: json_file.write(model.to_json()) 

Not an ideal solution, but hopefully it works for those looking at it in the future.

+5
source

It seems that your code is in the directory: "C: \ Users \ python \ u {...}. Py". This error is related to the version of python 3, where we get the special character \ u and cannot decode it on Windows machines. You can change the file name or the full path to the file so that it does not contain special characters or makes a patch for the func_dump function from the generic_utils.py file (it can be achieved by specifying the path "keras / utils / generic_utils.py"), you must replace line code = marshal.dumps(func.__code__).decode('raw_unicode_escape') to line code = marshal.dumps(func.__code__).replace(b'\\',b'/').decode('raw_unicode_escape')

+16
source

I believe that this is actually due to a bug in Keras and, fortunately, the Keras pull request # 8572 has been fixed . However, this PR was merged recently, and although it is included in the latest version of pypi, it is not in the latest version of conda, so I get this error.

Installing Keras via pip install keras instead of conda install keras made everything work for me (although I also had to precede it with conda install pip to get pip to work correctly).

0
source

Source: https://habr.com/ru/post/1014407/


All Articles