Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,12 +14,17 @@ def predict_regression(image):
|
|
14 |
# Preprocess image
|
15 |
image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
|
16 |
image = image.resize((150, 150)).convert('RGB') # Resize the image to 150x150 and convert it to RGB
|
17 |
-
image = np.array(image)
|
18 |
-
image = image / 255.0 # Normalize image to [0, 1] range
|
19 |
image = np.expand_dims(image, axis=0) # Add batch dimension
|
20 |
|
|
|
|
|
|
|
|
|
21 |
# Predict
|
22 |
prediction = model.predict(image) # Assuming single regression value
|
|
|
|
|
23 |
confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
|
24 |
return confidences
|
25 |
|
|
|
14 |
# Preprocess image
|
15 |
image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
|
16 |
image = image.resize((150, 150)).convert('RGB') # Resize the image to 150x150 and convert it to RGB
|
17 |
+
image = np.array(image) / 255.0 # Normalize image to [0, 1] range
|
|
|
18 |
image = np.expand_dims(image, axis=0) # Add batch dimension
|
19 |
|
20 |
+
# Print statements for debugging
|
21 |
+
print(f"Image shape (after preprocessing): {image.shape}")
|
22 |
+
print(f"Image data (sample): {image[0, :5, :5, 0]}") # Print a small sample of the data for inspection
|
23 |
+
|
24 |
# Predict
|
25 |
prediction = model.predict(image) # Assuming single regression value
|
26 |
+
print(f"Raw model prediction: {prediction}")
|
27 |
+
|
28 |
confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
|
29 |
return confidences
|
30 |
|