huggingface / huggingface/optimum-amd
'RyzenAIModelForImageClassification' object has no attribute 'device'
- Dominant language
- Jupyter Notebook
- Stars
- 101
- Forks
- 21
- Avg merge
- 58m
- Merged PRs (30d)
- 1
Description
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'
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.