Spaces:
Runtime error
Runtime error
Soham Chandratre
commited on
Commit
·
6750185
1
Parent(s):
59442d5
minor changes
Browse files
model/__pycache__/pothole_model.cpython-311.pyc
CHANGED
|
Binary files a/model/__pycache__/pothole_model.cpython-311.pyc and b/model/__pycache__/pothole_model.cpython-311.pyc differ
|
|
|
model/pothole_model.py
CHANGED
|
@@ -23,22 +23,30 @@
|
|
| 23 |
# return predicted_class
|
| 24 |
|
| 25 |
|
| 26 |
-
|
| 27 |
-
from
|
|
|
|
| 28 |
import numpy as np
|
| 29 |
-
from io import BytesIO
|
| 30 |
import requests
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
def load_image_model(image):
|
| 34 |
# Disable scientific notation for clarity
|
| 35 |
np.set_printoptions(suppress=True)
|
| 36 |
|
| 37 |
-
# Load the model
|
| 38 |
model_url = "https://huggingface.co/spaces/Soham0708/pothole_detect/blob/main/keras_model.h5"
|
| 39 |
response = requests.get(model_url)
|
| 40 |
response.raise_for_status() # Raise an exception if the download fails
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
# Load the labels
|
| 44 |
class_names = open("labels.txt", "r").readlines()
|
|
@@ -49,7 +57,7 @@ def load_image_model(image):
|
|
| 49 |
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
|
| 50 |
|
| 51 |
# Replace this with the path to your image
|
| 52 |
-
image = Image.open(
|
| 53 |
|
| 54 |
# resizing the image to be at least 224x224 and then cropping from the center
|
| 55 |
size = (224, 224)
|
|
@@ -74,3 +82,5 @@ def load_image_model(image):
|
|
| 74 |
print("Class:", class_name[2:], end="")
|
| 75 |
print("Confidence Score:", confidence_score)
|
| 76 |
|
|
|
|
|
|
|
|
|
| 23 |
# return predicted_class
|
| 24 |
|
| 25 |
|
| 26 |
+
|
| 27 |
+
from keras.models import load_model
|
| 28 |
+
from PIL import Image, ImageOps
|
| 29 |
import numpy as np
|
|
|
|
| 30 |
import requests
|
| 31 |
+
import tempfile
|
| 32 |
+
import os
|
| 33 |
|
| 34 |
def load_image_model(image):
|
| 35 |
# Disable scientific notation for clarity
|
| 36 |
np.set_printoptions(suppress=True)
|
| 37 |
|
| 38 |
+
# Load the model from the URL
|
| 39 |
model_url = "https://huggingface.co/spaces/Soham0708/pothole_detect/blob/main/keras_model.h5"
|
| 40 |
response = requests.get(model_url)
|
| 41 |
response.raise_for_status() # Raise an exception if the download fails
|
| 42 |
+
|
| 43 |
+
# Save the model to a temporary file
|
| 44 |
+
with tempfile.NamedTemporaryFile(suffix=".h5", delete=False) as tmp_file:
|
| 45 |
+
tmp_file.write(response.content)
|
| 46 |
+
tmp_file_path = tmp_file.name
|
| 47 |
+
|
| 48 |
+
# Load the model from the temporary file
|
| 49 |
+
model = load_model(tmp_file_path)
|
| 50 |
|
| 51 |
# Load the labels
|
| 52 |
class_names = open("labels.txt", "r").readlines()
|
|
|
|
| 57 |
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
|
| 58 |
|
| 59 |
# Replace this with the path to your image
|
| 60 |
+
image = Image.open(by(image)).convert("RGB")
|
| 61 |
|
| 62 |
# resizing the image to be at least 224x224 and then cropping from the center
|
| 63 |
size = (224, 224)
|
|
|
|
| 82 |
print("Class:", class_name[2:], end="")
|
| 83 |
print("Confidence Score:", confidence_score)
|
| 84 |
|
| 85 |
+
# Clean up temporary file
|
| 86 |
+
os.remove(tmp_file_path)
|