小编tej*_*567的帖子

TypeError: 'Not JSON Serializable' 在执行 tf.keras.Model.save 并在 tf.keras.Model.compile 的 loss_weights 中使用 keras 变量时

系统信息   

操作系统平台和发行版:Ubuntu 16.04 LTS  

从(源代码或二进制文件)安装的 TensorFlow:二进制文件  

TensorFlow 版本(使用下面的命令):1.12.0  

Python版本:3.5.2  

CUDA/cuDNN 版本:发布 9.0,V9.0.176  

GPU 型号和内存:Tesla K80,12 GB  

描述当前行为  

当我尝试使用model.save()where 模型是一个tf.keras.Model实例来保存我的模型时,它会抛出一个TypeError: ('Not JSON Serializable:', <tf.Variable 'Variable:0' shape=() dtype=float32>).

tf.keras.backend.variable()在 loss_weights 中使用 a model.compile。  

优化器: tf.keras.optimizers.Adam  

有趣的是,当我尝试仅使用model.save_weights模型是tf.keras.Model实例的地方保存模型权重时,它工作正常,没有错误。

重现问题的代码  

alpha = tf.keras.backend.variable(0.25)
Run Code Online (Sandbox Code Playgroud)

使用 tf.keras 编写任何模型  

model= get_model() 

model.compile(optimizer=optimizer,loss={"softmax1":generalized_dice_loss,"softmax2":generalized_dice_loss}, loss_weights=[1.0,alpha]) 
Run Code Online (Sandbox Code Playgroud)

使用model.fit()- 进行培训

model.save()
Run Code Online (Sandbox Code Playgroud)

其他信息/日志  

Traceback (most recent call last):  

File "main_latest.py", line 45, in 

max_queue_size=10)  

File "/home/tejal/.local/lib/python3.5/site-packages/tensorflow/python/keras/engine/training.py", line 2177, in …
Run Code Online (Sandbox Code Playgroud)

python-3.x deep-learning keras tensorflow tf.keras

5
推荐指数
1
解决办法
866
查看次数

标签 统计

deep-learning ×1

keras ×1

python-3.x ×1

tensorflow ×1

tf.keras ×1