在使用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万+
关注
私信
展开阅读全文