Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -210,7 +210,7 @@ from ultralytics import YOLO
|
|
| 210 |
model = YOLO("Model_IV.pt")
|
| 211 |
# model = torch.load("Model_IV.pt")
|
| 212 |
# model.eval()
|
| 213 |
-
|
| 214 |
# model.load_state_dict(checkpoint) # Load the saved weights
|
| 215 |
# model.eval() # Set the model to evaluation mode
|
| 216 |
|
|
@@ -238,18 +238,18 @@ model = YOLO("Model_IV.pt")
|
|
| 238 |
# print(checkpoint.keys())
|
| 239 |
|
| 240 |
# Define preprocessing
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
|
| 246 |
def predict(image):
|
| 247 |
-
#
|
| 248 |
-
|
| 249 |
|
| 250 |
-
#
|
| 251 |
-
|
| 252 |
-
|
| 253 |
|
| 254 |
# Process output (adjust based on your model's format)
|
| 255 |
# return output # or post-process the results as needed
|
|
|
|
| 210 |
model = YOLO("Model_IV.pt")
|
| 211 |
# model = torch.load("Model_IV.pt")
|
| 212 |
# model.eval()
|
| 213 |
+
checkpoint = torch.load("Model_IV.pt")
|
| 214 |
# model.load_state_dict(checkpoint) # Load the saved weights
|
| 215 |
# model.eval() # Set the model to evaluation mode
|
| 216 |
|
|
|
|
| 238 |
# print(checkpoint.keys())
|
| 239 |
|
| 240 |
# Define preprocessing
|
| 241 |
+
transform = T.Compose([
|
| 242 |
+
T.Resize((224, 224)), # Adjust to your model's input size
|
| 243 |
+
T.ToTensor(),
|
| 244 |
+
])
|
| 245 |
|
| 246 |
def predict(image):
|
| 247 |
+
# Preprocess the image
|
| 248 |
+
img_tensor = transform(image).unsqueeze(0) # Add batch dimension
|
| 249 |
|
| 250 |
+
# Make prediction
|
| 251 |
+
with torch.no_grad():
|
| 252 |
+
output = model(img_tensor)
|
| 253 |
|
| 254 |
# Process output (adjust based on your model's format)
|
| 255 |
# return output # or post-process the results as needed
|