Spaces:
Sleeping
Sleeping
Soham Chandratre
commited on
Commit
·
c4e1faf
1
Parent(s):
6750185
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,13 +23,11 @@
|
|
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
|
32 |
-
import os
|
33 |
|
34 |
def load_image_model(image):
|
35 |
# Disable scientific notation for clarity
|
@@ -39,14 +37,10 @@ def load_image_model(image):
|
|
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
|
49 |
-
model = load_model(
|
50 |
|
51 |
# Load the labels
|
52 |
class_names = open("labels.txt", "r").readlines()
|
@@ -57,7 +51,7 @@ def load_image_model(image):
|
|
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(
|
61 |
|
62 |
# resizing the image to be at least 224x224 and then cropping from the center
|
63 |
size = (224, 224)
|
@@ -80,7 +74,4 @@ def load_image_model(image):
|
|
80 |
|
81 |
# Print prediction and confidence score
|
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)
|
|
|
23 |
# return predicted_class
|
24 |
|
25 |
|
26 |
+
import tensorflow as tf
|
|
|
27 |
from PIL import Image, ImageOps
|
28 |
import numpy as np
|
29 |
import requests
|
30 |
+
from io import BytesIO
|
|
|
31 |
|
32 |
def load_image_model(image):
|
33 |
# Disable scientific notation for clarity
|
|
|
37 |
model_url = "https://huggingface.co/spaces/Soham0708/pothole_detect/blob/main/keras_model.h5"
|
38 |
response = requests.get(model_url)
|
39 |
response.raise_for_status() # Raise an exception if the download fails
|
40 |
+
model_data = BytesIO(response.content)
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
# Load the model from the in-memory bytes
|
43 |
+
model = tf.keras.models.load_model(model_data)
|
44 |
|
45 |
# Load the labels
|
46 |
class_names = open("labels.txt", "r").readlines()
|
|
|
51 |
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
|
52 |
|
53 |
# Replace this with the path to your image
|
54 |
+
image = Image.open(image).convert("RGB")
|
55 |
|
56 |
# resizing the image to be at least 224x224 and then cropping from the center
|
57 |
size = (224, 224)
|
|
|
74 |
|
75 |
# Print prediction and confidence score
|
76 |
print("Class:", class_name[2:], end="")
|
77 |
+
print("Confidence Score:", confidence_score)
|
|
|
|
|
|