Python 官方文档:入门教程 => 点击学习
问题: OSError: Error no file named PyTorch_model.bin, tf_model.h5, model.ckpt.index or flax_model.msgpack found in directo
问题:
OSError: Error no file named PyTorch_model.bin, tf_model.h5, model.ckpt.index or flax_model.msgpack found in directory
出现过程:
使用transfORMers的Bertmodel时
问题代码:
model = Bertmodel.from_pretrained('bert_model')
问题原因:
下载的模型文件夹中没有pytorch_model.bin/tf_model.h5等文件,去原网址中查找也未发现相关文件。继而查看transformers官方使用说明:
from_pretrained
(pretrained_model_name_or_path, *model_args, **kwargs)
pretrained_model_name_or_path – either: - a string with the shortcut name of a pre-trained model to load from cache or download, e.g.: bert-base-uncased
. - a string with the identifier name of a pre-trained model that was user-uploaded to our S3, e.g.: dbmdz/bert-base-german-cased
. - a path to a directory containing model weights saved using save_pretrained(), e.g.: ./my_model_directory/
. - a path or url to a PyTorch state_dict save file (e.g. ./pt_model/pytorch_model.bin). In this case, from_pt
should be set to True and a configuration object should be provided as config
argument. This loading path is slower than converting the PyTorch checkpoint in a Tensorflow model using the provided conversion scripts and loading the TensorFlow model afterwards.
即:如果是加载用save_pretrained保存过的模型,需要加入参数from_pt/from_tf和相应的config
解决方法:
# 模型文件夹中的config文件路径config = BertConfig.from_JSON_file('./tf_model/my_tf_model_config.json') # 如果下载的是tensorflow模型,则from_tf=True;如果是pytorch模型,则参数设置改为from_pt=Truemodel = BertModel.from_pretrained('./tf_model/my_tf_checkpoint.ckpt.index', from_pt=True, config=config)
来源地址:https://blog.csdn.net/weixin_44231433/article/details/128297602
--结束END--
本文标题: 解决OSError: Error no file named pytorch_model.bin, tf_model.h5 found in directory
本文链接: https://www.lsjlt.com/news/386332.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0