本文主要是介绍keras activation 报错 ‘_OverloadedFunction‘ object has no attribute ‘__name__‘,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
今天在训练模型的时候报错如下:
详细信息如下所示:
Traceback (most recent call last):File "/usr/local/lib64/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapperreturn func(*args, **kwargs)File "/usr/local/lib64/python3.6/site-packages/keras/engine/training.py", line 1418, in fit_generatorinitial_epoch=initial_epoch)File "/usr/local/lib64/python3.6/site-packages/keras/engine/training_generator.py", line 251, in fit_generatorcallbacks.on_epoch_end(epoch, epoch_logs)File "/usr/local/lib64/python3.6/site-packages/keras/callbacks.py", line 79, in on_epoch_endcallback.on_epoch_end(epoch, logs)File "/usr/local/lib64/python3.6/site-packages/keras/callbacks.py", line 446, in on_epoch_endself.model.save(filepath, overwrite=True)File "/usr/local/lib64/python3.6/site-packages/keras/engine/network.py", line 1090, in savesave_model(self, filepath, overwrite, include_optimizer)File "/usr/local/lib64/python3.6/site-packages/keras/engine/saving.py", line 382, in save_model_serialize_model(model, f, include_optimizer)File "/usr/local/lib64/python3.6/site-packages/keras/engine/saving.py", line 83, in _serialize_modelmodel_config['config'] = model.get_config()File "/usr/local/lib64/python3.6/site-packages/keras/engine/network.py", line 860, in get_configlayer_config = layer.get_config()File "/usr/local/lib64/python3.6/site-packages/keras/layers/core.py", line 302, in get_configconfig = {'activation': activations.serialize(self.activation)}File "/usr/local/lib64/python3.6/site-packages/keras/activations.py", line 176, in serializereturn activation.__name__
AttributeError: '_OverloadedFunction' object has no attribute '__name__'
查了整整一下午的时间,感觉沾边的方法都试了一遍也没有去解决,最终打开keras源码找到了端倪,这个结合报错的含义来理解就是:重载的函数没有__name__属性,这是因为使用了自定义的激活函数,问题就出现在callback函数部分,有一个checkpoint存储的操作,我存储的是model,这里不能直接存储model,应该改成存储weight,之后就不会有这个错误了。
还有一种比较笨的方法就是去除callback部分,这个不建议使用,因为没有从根本上解决问题,记录一下,这个属实把我折腾的够呛。
贴一张顺利训练的截图:
这篇关于keras activation 报错 ‘_OverloadedFunction‘ object has no attribute ‘__name__‘的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!