Pulling from 2 different places to get this to work and not updating variable names
Browse files
app.py
CHANGED
|
@@ -32,12 +32,12 @@ def detect_objects(model_name,url_input,image_input,threshold):
|
|
| 32 |
model = MaskFormerForInstanceSegmentation.from_pretrained(model_name)
|
| 33 |
|
| 34 |
target_size = (image.size[0], image.size[1])
|
| 35 |
-
inputs =
|
| 36 |
with torch.no_grad():
|
| 37 |
outputs = model(**inputs)
|
| 38 |
outputs.class_queries_logits = outputs.class_queries_logits.cpu()
|
| 39 |
outputs.masks_queries_logits = outputs.masks_queries_logits.cpu()
|
| 40 |
-
results =
|
| 41 |
results = torch.argmax(results, dim=0).numpy()
|
| 42 |
results = visualize_instance_seg_mask(results)
|
| 43 |
return results, "EMPTY"
|
|
|
|
| 32 |
model = MaskFormerForInstanceSegmentation.from_pretrained(model_name)
|
| 33 |
|
| 34 |
target_size = (image.size[0], image.size[1])
|
| 35 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 36 |
with torch.no_grad():
|
| 37 |
outputs = model(**inputs)
|
| 38 |
outputs.class_queries_logits = outputs.class_queries_logits.cpu()
|
| 39 |
outputs.masks_queries_logits = outputs.masks_queries_logits.cpu()
|
| 40 |
+
results = processor.post_process_segmentation(outputs=outputs, target_size=target_size)[0].cpu().detach()
|
| 41 |
results = torch.argmax(results, dim=0).numpy()
|
| 42 |
results = visualize_instance_seg_mask(results)
|
| 43 |
return results, "EMPTY"
|