Alyetama / label-studio-yolov5-backend

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for local file storage

Mekcyed opened this issue · comments

Hi @Alyetama,
my goal is to use the yolo predictions on images which are located in local storage and not in S3. I am currently struggling to even get it running with the existing code.:

image_url = task['data']['image']
img = Path(image_url)
with tempfile.NamedTemporaryFile() as f:
if image_url.startswith('http'):
r = requests.get(image_url)
if r.status_code == 200:
f.write(r.content)
else:
return JSONResponse(content=r.text, status_code=404)
else:
image_data = s3.get_object(img.parent.name, img.name)
f.write(image_data.read())
f.seek(0)
model_preds = model(f.name)

When I just import an image from the web with a http image path and using the code above, I get this error:

File "/root/.cache/torch/hub/ultralytics_yolov5_master/models/common.py", line 508, in forward
    b, ch, h, w = im.shape  # batch, channel, height, width
AttributeError: 'str' object has no attribute 'shape'

My attempts on changing the code to accept images with a local path like /mnt/c/Users/John/Pictures/image.jpg failed so far :(

From the error message I see, it seem like this is happening because you're passing the path to the image rather than the image object. Are you using local storage (a folder on your device with images) or are you importing into the project from the GUI (drag and drop)?

I used the GUI in the first place with drag and drop. Just tested it with the local storage and received the same Error. This ist the Task file with one image in the local storage:

{
   "id":3,
   "data":{
      "image":"/data/local-files/?d=Screenshots/chicken.png"
   },
   "meta":{
      
   },
   "created_at":"2022-11-16T07:24:35.015919Z",
   "updated_at":"2022-11-16T07:24:35.015947Z",
   "is_labeled":false,
   "overlap":1,
   "inner_id":1,
   "total_annotations":0,
   "cancelled_annotations":0,
   "total_predictions":0,
   "comment_count":0,
   "unresolved_comment_count":0,
   "last_comment_updated_at":"None",
   "project":2,
   "updated_by":"None",
   "file_upload":"None",
   "comment_authors":[
      
   ],
   "annotations":[
      
   ],
   "predictions":[
      
   ]
}