iis服务器助手广告
返回顶部
首页 > 资讯 > 后端开发 > Python >解决OSError: Error no file named pytorch_model.bin, tf_model.h5 found in directory
  • 123
分享到

解决OSError: Error no file named pytorch_model.bin, tf_model.h5 found in directory

pytorch深度学习人工智能bertpython 2023-08-31 17:08:31 123人浏览 泡泡鱼

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文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作