问题解决:AttributeError: module 'paddle.fluid' has no attribute 'EndStepEvent'

Rohana ·
更新时间:2024-09-20
· 812 次阅读

问题解决:AttributeError: module 'paddle.fluid' has no attribute 'EndStepEvent'问题描述解决思路问题解决 问题描述

在使用paddle.fluid导入EndStepEvent过程中

global step if isinstance(event, fluid.EndStepEvent): if event.step % 10 == 0: plot_cost.append('Train Cost', step, event.metrics[0]) plot_cost.plot()

其中if isinstance(event, fluid.EndStepEvent):报错
在这里插入图片描述

Traceback (most recent call last): File "D:/xxx.py", line 160, in trainer.train(reader=train_reader, num_epochs=200, event_handler=event_handler_plot, feed_order=feed_order) File "C:trainer.py", line 405, in train feed_order) File "C:trainer.py", line 483, in _train_by_executor self._train_by_any_executor(event_handler, exe, num_epochs, reader) File "C:trainer.py", line 495, in _train_by_any_executor event_handler(BeginEpochEvent(epoch_id)) File "D:xxx.py", line 138, in event_handler_plot if isinstance(event, fluid.EndStepEvent): AttributeError: module 'paddle.fluid' has no attribute 'EndStepEvent' 解决思路

在对于高层API,PaddlePaddle在版本1.0之后做了很大的改动,比如就修改了高层API所在的位置。同时也完善了高层API的很多功能。高层API虽然没有底层API灵活,但高层API使用更简单,非常适合初学者使用。

PaddlePaddle 1.0以上的版本,高级API已经迁移到paddle.fluid.contrib目录下,所以在导包的是应该要使用from paddle.fluid.contrib.trainer import *的导包方式。也就是说在PaddlePaddle 1.0以上的版本,EndStepEvent并不存在于fluid中,而是存在于fluid.contrib.trainer中。

问题解决

PaddlePaddle 1.0以上的版本,高级API已经迁移到paddle.fluid.contrib目录下,所以在导包的是应该要使用from paddle.fluid.contrib.trainer import *的导包方式。

导入资源方法:

from paddle.fluid.contrib.trainer import EndStepEvent

同时将if isinstance(event, fluid.EndStepEvent):改为

if isinstance(event, EndStepEvent): ywsydwsbn 原创文章 58获赞 115访问量 1万+ 关注 私信 展开阅读全文
作者:ywsydwsbn



module has paddle

需要 登录 后方可回复, 如果你还没有账号请 注册新账号
相关文章