Spaces:
Runtime error
Runtime error
Commit
·
fefbab6
1
Parent(s):
7d9ec1b
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import numpy as np
|
|
3 |
import cv2
|
4 |
from PIL import Image
|
5 |
from ultralytics import YOLO
|
|
|
6 |
|
7 |
# Define available YOLO models
|
8 |
available_models = {
|
@@ -12,6 +13,8 @@ available_models = {
|
|
12 |
# Add more models as needed
|
13 |
}
|
14 |
|
|
|
|
|
15 |
# Create a function to perform image segmentation using the selected model
|
16 |
def segment_image(input_image, selected_model):
|
17 |
# Resize the input image to 255x255
|
@@ -33,7 +36,7 @@ def segment_image(input_image, selected_model):
|
|
33 |
overlay_image = img.copy()
|
34 |
|
35 |
# Apply the resized mask to the overlay image
|
36 |
-
overlay_image[resized_mask > 0] = [
|
37 |
|
38 |
# Convert the overlay image to PIL format
|
39 |
overlay_pil = Image.fromarray(overlay_image)
|
|
|
3 |
import cv2
|
4 |
from PIL import Image
|
5 |
from ultralytics import YOLO
|
6 |
+
import torch
|
7 |
|
8 |
# Define available YOLO models
|
9 |
available_models = {
|
|
|
13 |
# Add more models as needed
|
14 |
}
|
15 |
|
16 |
+
|
17 |
+
|
18 |
# Create a function to perform image segmentation using the selected model
|
19 |
def segment_image(input_image, selected_model):
|
20 |
# Resize the input image to 255x255
|
|
|
36 |
overlay_image = img.copy()
|
37 |
|
38 |
# Apply the resized mask to the overlay image
|
39 |
+
overlay_image[resized_mask > 0] = [50, 0, 0] # Overlay in green
|
40 |
|
41 |
# Convert the overlay image to PIL format
|
42 |
overlay_pil = Image.fromarray(overlay_image)
|