Unable to create tensor, you should probably activate padding with 'padding=True' to have batched tensors with the same length
Hi Team,Good day.I am new to the Image object detection. I was trying to implement the Object detection usingDetrFeatureExtractor. 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, DetrModelfrom PIL import Imageimport requestsObject_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 thereturn_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.2Is there any way to resolve the issue? any help would be appreciated.
2024-11-06T06:18:11Z
Ran into this error - frustration was that I had actually set padding=True with my tokenizer. What gave me a clue was an error I got earlier when actually importing the transformers package, it was complaining about numpy version mismatches, but it wasn’t a breaking error, more of a wanring. Want to implore huggingface to improve their error catching - since this just raises a ValueError in the try catch in feature_extraction_utils, whereas the error that actually occurred was a RuntimeError when attempting to do the torch.from_numpy when converting the array of values to a tensor in the convert_to_tensors method. Long story short, check your numpy version - transformers only works with numpy<2.0 as at time of writing, so a quickpip install "numpy<2.0"fixed it for me - and I see you’re running numpy=2.0, so hopefully this helps.