New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike' #231
Comments
你的意思是keras2.3.1 + tf 1.14还是报同样的错误? |
我把tensorflow升级到2.3.1 |
|
感谢,真是神奇,终于可以在kaggle上用gpu训练了23333 |
把TensorFlow降级到2.0.0可以解决这个问题 |
tensorflow == 2.4.0rc0 from bert4keras.models import build_transformer_model
from bert4keras.tokenizers import Tokenizer
import numpy as np
import os
os.environ["TF_KERAS"] = '1'
config_path = '/home/xiaoguzai/下载/chinese_L-12_H-768_A-12/bert_config.json'
checkpoint_path = '/home/xiaoguzai/下载/chinese_L-12_H-768_A-12/bert_model.ckpt'
dict_path = '/home/xiaoguzai/下载/chinese_L-12_H-768_A-12/vocab.txt'
tokenizer = Tokenizer(dict_path, do_lower_case=True) # 建立分词器
model = build_transformer_model(config_path, checkpoint_path) # 建立模型,加载权重
token_ids, segment_ids = tokenizer.encode(u'语言模型')
print('\n ===== predicting =====\n')
print(model.predict([np.array([token_ids]), np.array([segment_ids])])) 另外我将layers以及models中的keras改变为tensorflow.keras
|
应该是keras 版本太低了 更新到2.4.3版本上试试 |
查看了源码,应该在导入之前就设置TF_KERAS=1。所以代码改成: import os
os.environ["TF_KERAS"] = '1'
from bert4keras.models import build_transformer_model
from bert4keras.tokenizers import Tokenizer
import numpy as np
config_path = '/home/xiaoguzai/下载/chinese_L-12_H-768_A-12/bert_config.json'
checkpoint_path = '/home/xiaoguzai/下载/chinese_L-12_H-768_A-12/bert_model.ckpt'
dict_path = '/home/xiaoguzai/下载/chinese_L-12_H-768_A-12/vocab.txt'
tokenizer = Tokenizer(dict_path, do_lower_case=True) # 建立分词器
model = build_transformer_model(config_path, checkpoint_path) # 建立模型,加载权重
token_ids, segment_ids = tokenizer.encode(u'语言模型')
print('\n ===== predicting =====\n')
print(model.predict([np.array([token_ids]), np.array([segment_ids])])) |
很棒,我有了一些思路,我不过还在整理当中 |
手动将TF_KERAS设成‘1’就行了。 |
环境:3.6.13,TF2.3.0,使用tf.keras |
提问时请尽可能提供如下信息:
基本信息
核心代码
from bert4keras.models import build_transformer_model
from bert4keras.tokenizers import Tokenizer
import numpy as np
config_path = '/content/drive/My Drive/roberta_zh_L-6-H-768_A-12.zip (Unzipped Files)/bert_config.json'
checkpoint_path = '/content/drive/My Drive/roberta_zh_L-6-H-768_A-12.zip (Unzipped Files)/bert_model.ckpt.data-00000-of-00001'
dict_path = '/content/drive/My Drive/roberta_zh_L-6-H-768_A-12.zip (Unzipped Files)/vocab.txt'
tokenizer = Tokenizer(dict_path, do_lower_case=True) # 建立分詞器
model = build_transformer_model(config_path, checkpoint_path) # 建立模型,加載權重
输出信息
# 请在此处贴上你的调试输出
AttributeError Traceback (most recent call last)
in ()
8
9 tokenizer = Tokenizer(dict_path, do_lower_case=True) # 建立分詞器
---> 10 model = build_transformer_model(config_path, checkpoint_path) # 建立模型,加載權重
11
9 frames
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in is_tensor(x)
AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'
自我尝试
不管什么问题,请先尝试自行解决,“万般努力”之下仍然无法解决再来提问。此处请贴上你的努力过程。
網路上,解決問題的方法有二:
The text was updated successfully, but these errors were encountered: