Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'RyzenAIModelForImageClassification' object has no attribute 'device' #143

Open
dancrab17 opened this issue Jun 10, 2024 · 1 comment
Open

Comments

@dancrab17
Copy link

I followed the instructions and run the code below provided by the example:
import requests
from PIL import Image

  • from transformers import AutoModelForImageClassification
  • from optimum.amd.ryzenai import RyzenAIModelForImageClassification
    from transformers import AutoFeatureExtractor, pipeline

url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)

model_id =

  • model = AutoModelForImageClassification.from_pretrained(model_id)
  • model = RyzenAIModelForImageClassification.from_pretrained(model_id)
    feature_extractor = AutoFeatureExtractor.from_pretrained(model_id)
    cls_pipe = pipeline("image-classification", model=model, feature_extractor=feature_extractor)
    outputs = cls_pipe(image)

but I got error below:
AttributeError Traceback (most recent call last)
Cell In[3], line 3
1 model = RyzenAIModelForImageClassification.from_pretrained(model_id)
2 feature_extractor = AutoFeatureExtractor.from_pretrained(model_id)
----> 3 cls_pipe = pipeline("image-classification", model=model, feature_extractor=feature_extractor, token=token1)
4 outputs = cls_pipe(image)

File ~\anaconda3\envs\ryzenai-1.1-20240608-152949\lib\site-packages\transformers\pipelines_init_.py:1108, in pipeline(task, model, config, tokenizer, feature_extractor, image_processor, framework, revision, use_fast, token, device, device_map, torch_dtype, trust_remote_code, model_kwargs, pipeline_class, **kwargs)
1105 if device is not None:
1106 kwargs["device"] = device
-> 1108 return pipeline_class(model=model, framework=framework, task=task, **kwargs)

File ~\anaconda3\envs\ryzenai-1.1-20240608-152949\lib\site-packages\transformers\pipelines\image_classification.py:89, in ImageClassificationPipeline.init(self, *args, **kwargs)
88 def init(self, *args, **kwargs):
---> 89 super().init(*args, **kwargs)
90 requires_backends(self, "vision")
91 self.check_model_type(
92 TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES
93 if self.framework == "tf"
94 else MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES
95 )

File ~\anaconda3\envs\ryzenai-1.1-20240608-152949\lib\site-packages\transformers\pipelines\base.py:848, in Pipeline.init(self, model, tokenizer, feature_extractor, image_processor, modelcard, framework, task, args_parser, device, torch_dtype, binary_output, **kwargs)
845 device = -1
847 if is_torch_available() and self.framework == "pt":
--> 848 if device == -1 and self.model.device is not None:
849 device = self.model.device
850 if isinstance(device, torch.device):

AttributeError: 'RyzenAIModelForImageClassification' object has no attribute 'device'

@joshuachris2001
Copy link

Same error.
I am using the example codes from [https://huggingface.co/docs/optimum/main/en/amd/ryzenai/overview] yet I'm still getting errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants