Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,28 +8,27 @@ import numpy as np
|
|
| 8 |
|
| 9 |
# Load the PT model
|
| 10 |
model = YOLO("Model_IV.pt")
|
| 11 |
-
checkpoint = torch.load("Model_IV.pt")
|
| 12 |
|
| 13 |
-
# Define preprocessing
|
| 14 |
-
transform = T.Compose([
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
])
|
| 18 |
|
| 19 |
def predict(image):
|
| 20 |
-
#
|
| 21 |
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
| 22 |
-
print("converted the colour to RGB.")
|
| 23 |
|
| 24 |
-
#
|
| 25 |
results = model(image)
|
| 26 |
-
print("ran the model")
|
| 27 |
-
annotated_img = results[0].plot()
|
| 28 |
-
print("got annotated img")
|
| 29 |
-
print("type annotated img:", type(annotated_img))
|
| 30 |
|
|
|
|
|
|
|
| 31 |
annotated_img = cv2.cvtColor(annotated_img, cv2.COLOR_RGB2BGR)
|
| 32 |
-
print("converted the colour to BGR.")
|
| 33 |
|
| 34 |
return annotated_img
|
| 35 |
|
|
|
|
| 8 |
|
| 9 |
# Load the PT model
|
| 10 |
model = YOLO("Model_IV.pt")
|
| 11 |
+
# checkpoint = torch.load("Model_IV.pt")
|
| 12 |
|
| 13 |
+
# # Define preprocessing
|
| 14 |
+
# transform = T.Compose([
|
| 15 |
+
# T.Resize((224, 224)), # Adjust to your model's input size
|
| 16 |
+
# T.ToTensor(),
|
| 17 |
+
# ])
|
| 18 |
|
| 19 |
def predict(image):
|
| 20 |
+
# Preprocessing: Convert the colour space to RGB
|
| 21 |
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
| 22 |
+
# print("converted the colour to RGB.")
|
| 23 |
|
| 24 |
+
# Make prediction
|
| 25 |
results = model(image)
|
| 26 |
+
#print("ran the model")
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
# Postprocessing: Convert the colour space back to BGR
|
| 29 |
+
annotated_img = results[0].plot()
|
| 30 |
annotated_img = cv2.cvtColor(annotated_img, cv2.COLOR_RGB2BGR)
|
| 31 |
+
# print("converted the colour to BGR.")
|
| 32 |
|
| 33 |
return annotated_img
|
| 34 |
|