Spaces:
Sleeping
Sleeping
Soham Chandratre
commited on
Commit
·
b388354
1
Parent(s):
c4e1faf
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
@@ -34,39 +34,28 @@ def load_image_model(image):
|
|
34 |
np.set_printoptions(suppress=True)
|
35 |
|
36 |
# Load the model from the URL
|
37 |
-
model_url = "https://huggingface.co/spaces/Soham0708/pothole_detect/
|
38 |
-
|
39 |
-
response.raise_for_status() # Raise an exception if the download fails
|
40 |
-
model_data = BytesIO(response.content)
|
41 |
|
42 |
-
# Load the model
|
43 |
-
model = tf.keras.models.load_model(
|
44 |
|
45 |
# Load the labels
|
46 |
class_names = open("labels.txt", "r").readlines()
|
47 |
|
48 |
# Create the array of the right shape to feed into the keras model
|
49 |
-
# The 'length' or number of images you can put into the array is
|
50 |
-
# determined by the first position in the shape tuple, in this case 1
|
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 |
-
#
|
57 |
-
|
58 |
-
image = ImageOps.fit(image, size, Image.Resampling.LANCZOS)
|
59 |
-
|
60 |
-
# turn the image into a numpy array
|
61 |
image_array = np.asarray(image)
|
62 |
-
|
63 |
-
# Normalize the image
|
64 |
normalized_image_array = (image_array.astype(np.float32) / 127.5) - 1
|
65 |
-
|
66 |
-
# Load the image into the array
|
67 |
data[0] = normalized_image_array
|
68 |
|
69 |
-
#
|
70 |
prediction = model.predict(data)
|
71 |
index = np.argmax(prediction)
|
72 |
class_name = class_names[index]
|
|
|
34 |
np.set_printoptions(suppress=True)
|
35 |
|
36 |
# Load the model from the URL
|
37 |
+
model_url = "https://huggingface.co/spaces/Soham0708/pothole_detect/resolve/main/keras_model.h5"
|
38 |
+
model_path = tf.keras.utils.get_file("keras_model.h5", model_url)
|
|
|
|
|
39 |
|
40 |
+
# Load the model
|
41 |
+
model = tf.keras.models.load_model(model_path)
|
42 |
|
43 |
# Load the labels
|
44 |
class_names = open("labels.txt", "r").readlines()
|
45 |
|
46 |
# Create the array of the right shape to feed into the keras model
|
|
|
|
|
47 |
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
|
48 |
|
49 |
# Replace this with the path to your image
|
50 |
image = Image.open(image).convert("RGB")
|
51 |
|
52 |
+
# Resize and preprocess the image
|
53 |
+
image = ImageOps.fit(image, (224, 224), Image.ANTIALIAS)
|
|
|
|
|
|
|
54 |
image_array = np.asarray(image)
|
|
|
|
|
55 |
normalized_image_array = (image_array.astype(np.float32) / 127.5) - 1
|
|
|
|
|
56 |
data[0] = normalized_image_array
|
57 |
|
58 |
+
# Make prediction
|
59 |
prediction = model.predict(data)
|
60 |
index = np.argmax(prediction)
|
61 |
class_name = class_names[index]
|