admin管理员组文章数量:1356509
I am working on building a CNN architecture model. After training it, I've uploaded it to Huggingface to make it deployable.
But I cannot use it as an interface because of this error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
File c:\Users\HP\OneDrive\Desktop\fine_tuning\.venv\Lib\site-packages\torch\serialization.py:851, in _check_seekable(f)
850 try:
--> 851 f.seek(f.tell())
852 return True
AttributeError: 'dict' object has no attribute 'seek'
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
Cell In[51], line 23
21 # Load the trained model
22 device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
---> 23 model = AutoModelForImageClassification.from_pretrained("shahad-alh/Arabichar_Model-V1", trust_remote_code=True,
24 id2label=id2label, label2id=label2id
25 )
26 model.to(device)
27 model.eval() # Set model to evaluation mode
File c:\Users\HP\OneDrive\Desktop\fine_tuning\.venv\Lib\site-packages\transformers\models\auto\auto_factory.py:568, in _BaseAutoModelClass.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
566 cls.register(config.__class__, model_class, exist_ok=True)
567 model_class = add_generation_mixin_to_remote_model(model_class)
--> 568 return model_class.from_pretrained(
...
846 )
--> 847 raise type(e)(msg)
848 raise e
AttributeError: 'dict' object has no attribute 'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead.
I believe that it's all because of the load_state_dict function
def load_state_dict(self, model_name,strict = False, assign = False):
self.model.load_state_dict(torch.load(model_name))
I'm happy to share more information if needed, hope someone knows what the problem is and how to solve it correctly.
本文标签:
版权声明:本文标题:python - How to solve "AttributeError: 'dict' object has no attribute 'seek'. You can o 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744068614a2585474.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论