本文介绍了Keras model.to_json()错误:"rawunicodeescape"编解码器无法解码位置94-98中的字节:截断的\ uXXXX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

model.to_json()

用于模型

引发异常

可能是什么问题,我该如何解决?

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

推荐答案

在使用带有tensorflow-gpu后端的keras 1.2.1时,我遇到了类似的问题.

I came across a similar problem when using keras 1.2.1 with a tensorflow-gpu backend.

我发现这是由于Windows 10周年纪念版在编码正斜杠字符时遇到问题.

I found out it was caused because windows 10 anniversary edition was having problems encoding the forward slash character.

使用Lambda层会使to_json()调用失败,但是切换到批处理规范化就可以了.

Using the Lambda layer makes the to_json() call fail 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 someone looking at this in the future.

这篇关于Keras model.to_json()错误:"rawunicodeescape"编解码器无法解码位置94-98中的字节:截断的\ uXXXX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 04:48