Tensorflow版本问题的⼀系列报错解决⽅案
⼀下的报错均是由于将tensorflow1版本的代码迁移到tensorflow2上产⽣的错误,主要是⼀些api的改动。
File "D:\python\paperRecurrence\CasRel\CasRel-master\model.py", line 23, in E2EModel
tokens_in = Input(shape=(None,),dtype=tf.int32)
File "E:\environment\python\lib\site-packages\keras\engine\input_layer.py", line 178, in Input
tensorflow版本选择input_tensor=tensor)
File "E:\environment\python\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "E:\environment\python\lib\site-packages\keras\engine\input_layer.py", line 39, in __init__
name = prefix + '_' + _uid(prefix))
File "E:\environment\python\lib\site-packages\keras\backend\tensorflow_backend.py", line 74, in get_uid
graph = tf.get_default_graph()
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'
将keras.layers.Input改为tf.keras.layers.Input
其他类似的改动还有:
将keras.layers.Lambda改为tf.keras.layers.Lambda
将keras.layers.Dense改为tf.keras.layers.Dense
将dels.Model改为dels.Model
将keras.layers.Add改为tf.keras.layers.Add
File "D:/python/paperRecurrence/CasRel/CasRel-master/run.py", line 47, in <module>
subject_model, object_model, hbt_model = E2EModel(bert_config_path, bert_checkpoint_path, LR, num_rels)
File "D:\python\paperRecurrence\CasRel\CasRel-master\model.py", line 63, in E2EModel
sub_tails_loss = K.binary_crossentropy(gold_sub_tails, pred_sub_tails)
File "E:\environment\python\lib\site-packages\keras\backend\tensorflow_backend.py", line 3376, in binary_crossentropy
output = tf.log(output / (1 - output))
AttributeError: module 'tensorflow' has no attribute 'log'
将K.binary_crossentropy(K是keras.backend)改为tf.keras.losses.binary_crossentropy
ValueError: ('Could not interpret optimizer identifier:', <keras.optimizers.Adam object at 0x000001CCA47E7CF8>)将keras.optimizers.Adam改为tf.keras.optimizers.Adam
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论