macanv / BERT-BiLSTM-CRF-NER

Tensorflow solution of NER task Using BiLSTM-CRF model with Google BERT Fine-tuning And private Server services
https://github.com/macanv/BERT-BiLSMT-CRF-NER
4.67k stars 1.25k forks source link

terminal_predict.py 错误:无法restore模型 #377

Closed Tian14267 closed 3 years ago

Tian14267 commented 3 years ago

作者你好,我现在训练出了NER模型,但是在用terminal_predict.py进行预测的时候,模型无法导入,报错如下: Traceback (most recent call last): File "D:\Soft\Python\lib\site-packages\tensorflow_core\python\client\session.py", line 1365, in _do_call return fn(*args) File "D:\Soft\Python\lib\site-packages\tensorflow_core\python\client\session.py", line 1350, in _run_fn target_list, run_metadata) File "D:\Soft\Python\lib\site-packages\tensorflow_core\python\client\session.py", line 1443, in _call_tf_sessionrun run_metadata) tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [768,8] rhs shape= [768,9] [[{{node save/Assign_200}}]] During handling of the above exception, another exception occurred: Traceback (most recent call last): File "D:\Soft\Python\lib\contextlib.py", line 130, in exit self.gen.throw(type, value, traceback) File "D:\Soft\Python\lib\site-packages\tensorflow_core\python\framework\ops.py", line 5480, in get_controller yield g File "F:/fffan/DeepLearning/BERT-BiLSTM-CRF-NER-master/terminal_predict.py", line 65, in saver.restore(sess, save_path=model_path) File "D:\Soft\Python\lib\site-packages\tensorflow_core\python\training\saver.py", line 1326, in restore err, "a mismatch between the current graph and the graph") tensorflow.python.framework.errors_impl.InvalidArgumentError: Restoring from checkpoint failed. This is most likely due to a mismatch between the current graph and the graph from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:

Assign requires shapes of both tensors to match. lhs shape= [768,8] rhs shape= [768,9] [[node save/Assign_200 (defined at D:\Soft\Python\lib\site-packages\tensorflow_core\python\framework\ops.py:1748) ]]

请问这个是什么情况?