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

Unable to create tensor, you should probably activate padding with 'padding=True' to have batched tensors with the same length. #453

Open
code-amalps opened this issue Jul 18, 2024 · 1 comment

Comments

@code-amalps
Copy link

code-amalps commented Jul 18, 2024

Hi Team,

Good day.

I am new to the Image object detection. I was trying to implement the Object detection using DetrFeatureExtractor. When I try I am getting an error like " Unable to create tensor, you should probably activate padding with 'padding=True' to have batched tensors with the same length. ". Previously it was working fine and few days ago it is getting break with this error.

The code I have been using :

` from transformers import DetrFeatureExtractor, DetrModel
from PIL import Image
import requests

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

  feature_extractor = DetrFeatureExtractor.from_pretrained(Object_detection,  local_files_only=True)
  model = DetrForObjectDetection.from_pretrained(Object_detection )
  inputs = feature_extractor(images=image, return_tensors="pt")
  outputs = model(**inputs)`

To find the issue I tried various steps from the raised tickets, what I found was when the return_tensors="pt" it is raising the error. As suggested in the error, I tried with Padding = True, but the response was the same. When I try with None it is not throwing any error instead I got an error in the output as "'list' object has no attribute 'shape'".

the versions I am using for the solution:

torch==2.2.2
sentence-transformers==2.2.2
transformers==4.41.2

Is there any way to resolve the issue? any help would be appreciated.

@koga1694
Copy link

koga1694 commented Sep 10, 2024

Is the numpy version 2.0 or higher? I downgraded the numpy version to 1.26.4 and resolved the issue.
Try pip install numpy==1.26.4 and restart.

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