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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -10,15 +10,15 @@ model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
10
  # Prediction function
11
  def predict_image(image: Image.Image):
12
  try:
13
- # Step 1: Preprocess the image with padding enabled
14
  inputs = processor(images=image, return_tensors="pt", padding=True)
15
 
16
- # Step 2: Run inference without gradients
17
  with torch.no_grad():
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
 
10
  # Prediction function
11
  def predict_image(image: Image.Image):
12
  try:
13
+ # Step 1: Preprocess the image with padding and ensure it is batched
14
  inputs = processor(images=image, return_tensors="pt", padding=True)
15
 
16
+ # Step 2: Run inference (no gradients)
17
  with torch.no_grad():
18
  outputs = model(**inputs)
19
 
20
  # Step 3: Post-process the outputs
21
+ target_sizes = torch.tensor([image.size[::-1]]) # image size reversed to match model format
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