Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -240,12 +240,16 @@ def predict(image):
|
|
| 240 |
# annotated_img = results[0].plot()
|
| 241 |
# return annotated_img
|
| 242 |
|
| 243 |
-
# Preprocess the image
|
|
|
|
|
|
|
| 244 |
input_name = model.get_inputs()[0].name
|
| 245 |
input_shape = model.get_inputs()[0].shape
|
| 246 |
|
| 247 |
# Resize the image to the model's input shape
|
| 248 |
image = cv2.resize(image, (input_shape[2], input_shape[3]))
|
|
|
|
|
|
|
| 249 |
image = image.reshape(3, 640, 640)
|
| 250 |
|
| 251 |
# Normalize the image
|
|
@@ -260,14 +264,17 @@ def predict(image):
|
|
| 260 |
# Convert the image to a numpy array and add a batch dimension
|
| 261 |
if len(input_shape) == 4 and input_shape[0] == 1:
|
| 262 |
image = np.expand_dims(image, axis=0)
|
|
|
|
| 263 |
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
# Perform inference
|
| 267 |
output = model.run(None, {input_name: image})
|
|
|
|
|
|
|
| 268 |
print("type output:", type(output))
|
| 269 |
print(output)
|
| 270 |
|
|
|
|
|
|
|
| 271 |
annotated_img = output[0]
|
| 272 |
# annotated_img = (output[0] / 255.0 - mean)/std
|
| 273 |
# annotated_img = classes[output[0][0].argmax(0)]
|
|
|
|
| 240 |
# annotated_img = results[0].plot()
|
| 241 |
# return annotated_img
|
| 242 |
|
| 243 |
+
# Preprocess the image
|
| 244 |
+
|
| 245 |
+
# Get name and shape of the model's inputs
|
| 246 |
input_name = model.get_inputs()[0].name
|
| 247 |
input_shape = model.get_inputs()[0].shape
|
| 248 |
|
| 249 |
# Resize the image to the model's input shape
|
| 250 |
image = cv2.resize(image, (input_shape[2], input_shape[3]))
|
| 251 |
+
|
| 252 |
+
# Reshape the image to match the model's input shape
|
| 253 |
image = image.reshape(3, 640, 640)
|
| 254 |
|
| 255 |
# Normalize the image
|
|
|
|
| 264 |
# Convert the image to a numpy array and add a batch dimension
|
| 265 |
if len(input_shape) == 4 and input_shape[0] == 1:
|
| 266 |
image = np.expand_dims(image, axis=0)
|
| 267 |
+
image = image.astype(np.float32)
|
| 268 |
|
| 269 |
+
# Make prediction
|
|
|
|
|
|
|
| 270 |
output = model.run(None, {input_name: image})
|
| 271 |
+
|
| 272 |
+
|
| 273 |
print("type output:", type(output))
|
| 274 |
print(output)
|
| 275 |
|
| 276 |
+
# Postprocess output image
|
| 277 |
+
|
| 278 |
annotated_img = output[0]
|
| 279 |
# annotated_img = (output[0] / 255.0 - mean)/std
|
| 280 |
# annotated_img = classes[output[0][0].argmax(0)]
|