ValueError:在启用了急切模式的情况下构造“Model"实例时,不支持在图形模式下调用“Model.fit" [英] ValueError: Calling `Model.fit` in graph mode is not supported when the `Model` instance was constructed with eager mode enabled

查看:51
本文介绍了ValueError:在启用了急切模式的情况下构造“Model"实例时,不支持在图形模式下调用“Model.fit"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

for i in range(epochs):gen = data_generator(train_descriptions,encoding_train,word_to_idx,max_len,batch_size)model.fit(gen,epochs=1,steps_per_epoch=steps,verbose=1)模型.保存(best_model.h5")

<块引用>

ValueError: 不支持在图形模式下调用 Model.fit模型实例是在启用急切模式的情况下构建的.请在图形模式下构建您的模型实例或调用 Model.fit启用急切模式.

我该如何解决这个错误?

解决方案

尝试

model.compile(run_eagerly=True)

如果这不起作用,您可以尝试在模型编译后强制执行:

model.compile()model.run_eagerly = True

for i in range(epochs):
  gen = data_generator(train_descriptions,encoding_train,word_to_idx,max_len,batch_size)
  model.fit(gen,epochs=1,steps_per_epoch=steps,verbose=1)
  model.save("best_model.h5")

ValueError: Calling Model.fit in graph mode is not supported when the Model instance was constructed with eager mode enabled. Please construct your Model instance in graph mode or call Model.fit with eager mode enabled.

How do I solve this error?

解决方案

Try

model.compile(run_eagerly=True)

If that doesn't work, you can try to force it after the model compiles:

model.compile()
model.run_eagerly = True

这篇关于ValueError:在启用了急切模式的情况下构造“Model"实例时,不支持在图形模式下调用“Model.fit"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆