简体   繁体   English

无法加载 tensorflow BERT 预训练模型

[英]Failed to load tensorflow BERT pre-trained model

I tried to load a BERT pre-trained model to do NER task.我尝试加载一个 BERT 预训练模型来执行 NER 任务。 But the system cannot find the pretrained model file.但是系统找不到预训练的模型文件。

I used the following code in terminal, the folder contains model.ckpt-1000000, model.ckpt-1000000.index,model.ckpt-1000000.meta files.我在终端中使用了以下代码,该文件夹包含 model.ckpt-1000000、model.ckpt-1000000.index、model.ckpt-1000000.meta 文件。

python run_ner.py \
    --do_train=true \
    --do_eval=true \
    --vocab_file=vocab.txt \
    --bert_config_file=bert_config.json \
    --init_checkpoint=model.ckpt-1000000 \
    --num_train_epochs=10.0 \
    --data_dir=NCBI-disease/ \
    --output_dir=epoch1

The error message is错误信息是

2019-08-04 23:26:41.272281: W tensorflow/core/framework/op_kernel.cc:1401] OP_REQUIRES failed at save_restore_v2_ops.cc:184 : Not found: model.ckpt-1000000.data-00000-of-00001; No such file or directory

  File "/Users/anaconda/envs/BIOBERT/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1328, in _do_run
    run_metadata)
  File "/Users/anaconda/envs/BIOBERT/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: model.ckpt-1000000.data-00000-of-00001; No such file or directory
     [[node checkpoint_initializer_161 (defined at run_ner.py:422) ]]

Note: The original names of the model files are model.ckpt-1000000.data-00000-of-00001, model.ckpt-1000000.index and model.ckpt-1000000.meta.注意:模型文件的原始名称为model.ckpt-1000000.data-00000-of-00001、model.ckpt-1000000.index 和model.ckpt-1000000.meta。 I also tried我也试过

python run_ner.py \
    --do_train=true \
    --do_eval=true \
    --vocab_file=vocab.txt \
    --bert_config_file=bert_config.json \
    --init_checkpoint=model.ckpt-1000000.data-00000-of-00001 \
    --num_train_epochs=10.0 \
    --data_dir=NCBI-disease/ \
    --output_dir=epoch1

Then the error would be那么错误将是

  File "/Users/anaconda/envs/BIOBERT/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 326, in NewCheckpointReader
    return CheckpointReader(compat.as_bytes(filepattern), status)
  File "/Users/SichengZhou/anaconda/envs/BIOBERT/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.DataLossError: Unable to open table file ./model.ckpt-1000000.data-00000-of-00001: Data loss: not an sstable (bad magic number): perhaps your file is in a different file format and you need to use a different restore operator?

The original names of the model files should be model.ckpt-1000000.data-00000-of-00001, model.ckpt-1000000.index and model.ckpt-1000000.meta.模型文件的原始名称应为 model.ckpt-1000000.data-00000-of-00001、model.ckpt-1000000.index 和 model.ckpt-1000000.meta。

The error you are getting is because the ckpt files and the python file you are running(run_ner.py) are in different paths.您收到的错误是因为 ckpt 文件和您正在运行的 python 文件(run_ner.py)位于不同的路径中。

python run_ner.py \
--do_train=true \
--do_eval=true \
--vocab_file=vocab.txt \
--bert_config_file=bert_config.json \
--init_checkpoint=<path to folder where ckpt files are saved>/model.ckpt-1000000 \
--num_train_epochs=10.0 \
--data_dir=NCBI-disease/ \
--output_dir=epoch1

Don't change --init_checkpoint=model.ckpt-1000000 to --init_checkpoint=model.ckpt-1000000.data-00000-of-00001 while running run_ner.py .不要更改--init_checkpoint=model.ckpt-1000000--init_checkpoint=model.ckpt-1000000.data-00000-of-00001在运行run_ner.py

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行 run_squad.py 以微调 Google BERT 模型(官方 tensorflow 预训练模型)时无法加载(恢复)TensorFlow 检查点 - Failed to load(restore) TensorFlow checkpoint when running run_squad.py to fine-tune the Google BERT model(official tensorflow pre-trained model) 如何将预训练的张量流模型加载并预测到Java代码中? - How to load and predict a pre-trained tensorflow model into Java code? TensorFlow 2.0 C++ - 加载预训练 model - TensorFlow 2.0 C++ - Load pre-trained model 如何加载由 Google 命名为 inception 的预训练张量流模型? - How to load pre-trained tensorflow model named inception by Google? Tensorflow Python未加载预训练的模型 - Tensorflow python not loading the pre-trained model 如何在TensorFlow中使用预训练模型 - How to use pre-trained model in TensorFlow 预训练张量流模型的烧瓶 - flask with pre-trained tensorflow model 如何在 tensorflow 中使用预训练的 model 进行预测? - how to predict with pre-trained model in tensorflow? 使用预训练的 BERT 模型进行错误多类文本分类 - Error multiclass text classification with pre-trained BERT model RuntimeError,在 IA tryna 上工作使用预训练的 BERT 模型 - RuntimeError, working on IA tryna use a pre-trained BERT model
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM