最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - How to solve "AttributeError: 'dict' object has no attribute 'seek'. You can o

programmeradmin3浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论