Open tian231825 opened 5 years ago
这个modeling就是BERT的源码,请到 https://github.com/google-research/bert 后面我把modeling目录补充更新上去下。
modeling.py文件已经补充更新。
后续在python freeze_graph的过程中设置num——labels后 UnboundLocalError: local variable 'num_labels' referenced before assignment
E:CLASSIFICATION_MODEL, Lodding...:[fre:opt:200]:fail to optimize the graph! local variable 'num_labels' referenced before assignment Traceback (most recent call last): File "freeze_graph.py", line 176, in optimize_class_model input_ids=input_ids, input_mask=input_mask, segment_ids=None, labels=None, num_labels=num_labels) UnboundLocalError: local variable 'num_labels' referenced before assignment 想请教一下这个怎么改
如果num——labels使用默认则会出现 E:CLASSIFICATION_MODEL, Lodding...:[fre:opt:200]:fail to optimize the graph! init_predict_var() missing 1 required positional argument: 'path' Traceback (most recent call last): File "freeze_graph.py", line 164, in optimize_class_model num_labels, label2id, id2label = init_predict_var() TypeError: init_predict_var() missing 1 required positional argument: 'path'
是label2id.pkl的路径?但是在参数里也无法进行设置啊难道是直接在函数里面改吗
未指定num_labels参数时报错的bug已经处理,会从model_dir目录下的”label2id.pkl"文件读取
NotFoundError (see above for traceback): Restoring from checkpoint failed. This is most likely due to a Variable name or other graph key that is missing from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:
Key output_bias not found in checkpoint
Key output_bias 具体是指什么找不到呢
检查下各个参数是否指定正确:
bert_model_dir
参数是BERT预训练模型model_dir
就是训练好的.ckpt文件所在的目录model_pb_dir
参数是转换完成的pb文件保存的目录,默认为model_dirmax_seq_len
要与原来一致;num_labels
是分类标签的个数,本例中是3个,如果省略这个参数,会自动从model_dir指定的目录下寻找"label2id.pkl"文件读取2019-05-24 15:07:48.180114: W tensorflow/core/framework/op_kernel.cc:1401] OP_REQUIRES failed at save_restore_v2_ops.cc:184 : Not found: Key output_bias not found in checkpoint E:CLASSIFICATION_MODEL, Lodding...:[fre:opt:207]:fail to optimize the graph! Restoring from checkpoint failed. This is most likely due to a Variable name or other graph key that is missing from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:
Key output_bias not found in checkpoint [[node save/RestoreV2 (defined at freeze_graph.py:189) ]]
Caused by op 'save/RestoreV2', defined at:
File "freeze_graph.py", line 240, in
NotFoundError (see above for traceback): Restoring from checkpoint failed. This is most likely due to a Variable name or other graph key that is missing from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:
Key output_bias not found in checkpoint [[node save/RestoreV2 (defined at freeze_graph.py:189) ]] Traceback (most recent call last): File "/home/junruit/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1334, in _do_call return fn(*args) File "/home/junruit/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1319, in _run_fn options, feed_dict, fetch_list, target_list, run_metadata) File "/home/junruit/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1407, in _call_tf_sessionrun run_metadata) tensorflow.python.framework.errors_impl.NotFoundError: Key output_bias not found in checkpoint [[{{node save/RestoreV2}}]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/home/junruit/.local/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1276, in restore {self.saver_def.filename_tensor_name: save_path}) File "/home/junruit/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 929, in run run_metadata_ptr) File "/home/junruit/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1152, in _run feed_dict_tensor, options, run_metadata) File "/home/junruit/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1328, in _do_run run_metadata) File "/home/junruit/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1348, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.NotFoundError: Key output_bias not found in checkpoint [[node save/RestoreV2 (defined at freeze_graph.py:189) ]]
Caused by op 'save/RestoreV2', defined at:
File "freeze_graph.py", line 240, in
NotFoundError (see above for traceback): Key output_bias not found in checkpoint [[node save/RestoreV2 (defined at freeze_graph.py:189) ]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/home/junruit/.local/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1286, in restore names_to_keys = object_graph_key_mapping(save_path) File "/home/junruit/.local/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1591, in object_graph_key_mapping checkpointable.OBJECT_GRAPH_PROTO_KEY) File "/home/junruit/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 370, in get_tensor status) File "/home/junruit/.local/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 528, in exit c_api.TF_GetCode(self.status.status)) tensorflow.python.framework.errors_impl.NotFoundError: Key _CHECKPOINTABLE_OBJECT_GRAPH not found in checkpoint
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "freeze_graph.py", line 195, in optimize_class_model saver.restore(sess,latest_checkpoint ) File "/home/junruit/.local/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1292, in restore err, "a Variable name or other graph key that is missing") tensorflow.python.framework.errors_impl.NotFoundError: Restoring from checkpoint failed. This is most likely due to a Variable name or other graph key that is missing from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:
Key output_bias not found in checkpoint [[node save/RestoreV2 (defined at freeze_graph.py:189) ]]
Caused by op 'save/RestoreV2', defined at:
File "freeze_graph.py", line 240, in
NotFoundError (see above for traceback): Restoring from checkpoint failed. This is most likely due to a Variable name or other graph key that is missing from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:
Key output_bias not found in checkpoint [[node save/RestoreV2 (defined at freeze_graph.py:189) ]]
是不是freeze.graph 第193行那个路径是不是应该是bert-model_dir预训练模型路径?而不是model_dir(output_dir)
既然用了freeze_graph,把tensorflow的optimize_for_inference也用一下吧
@tian231825 我遇到了和你一样的问题,请问您最后是怎么解决的呢
您好,在freeze_graph那一步中,您的line17 使用了import modeling,请问这个是项目提供的吗?为什么一直报找不到modeling