gopichandra commited on
Commit
3d7689c
·
verified ·
1 Parent(s): b691e58

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -3
app.py CHANGED
@@ -18,8 +18,7 @@ def predict_image(image: Image.Image):
18
  outputs = model(**inputs)
19
 
20
  # Step 3: Post-process the outputs
21
- # Convert image size to (height, width)
22
- target_sizes = torch.tensor([image.size[::-1]])
23
  results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.5)[0]
24
 
25
  # Step 4: Draw bounding boxes on the image
@@ -29,7 +28,7 @@ def predict_image(image: Image.Image):
29
  draw.rectangle(box, outline="red", width=2)
30
  draw.text((box[0], box[1]), f"{model.config.id2label[label.item()]}: {round(score.item(), 3)}", fill="red")
31
 
32
- # Step 5: Return the processed image with status
33
  return image, "Object detection complete."
34
 
35
  except Exception as e:
 
18
  outputs = model(**inputs)
19
 
20
  # Step 3: Post-process the outputs
21
+ target_sizes = torch.tensor([image.size[::-1]]) # image size needs to be reversed
 
22
  results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.5)[0]
23
 
24
  # Step 4: Draw bounding boxes on the image
 
28
  draw.rectangle(box, outline="red", width=2)
29
  draw.text((box[0], box[1]), f"{model.config.id2label[label.item()]}: {round(score.item(), 3)}", fill="red")
30
 
31
+ # Step 5: Return the processed image and a success message
32
  return image, "Object detection complete."
33
 
34
  except Exception as e: