Spaces:
Sleeping
Sleeping
Soham Chandratre
commited on
Commit
·
de600c4
1
Parent(s):
b388354
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
@@ -29,33 +29,44 @@ 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
|
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 |
-
|
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 |
-
#
|
53 |
-
|
|
|
|
|
|
|
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 |
-
#
|
59 |
prediction = model.predict(data)
|
60 |
index = np.argmax(prediction)
|
61 |
class_name = class_names[index]
|
|
|
29 |
import requests
|
30 |
from io import BytesIO
|
31 |
|
32 |
+
def load_image_model(image):
|
33 |
+
import tensorflow as tf
|
34 |
+
from PIL import Image, ImageOps
|
35 |
+
import numpy as np
|
36 |
+
|
37 |
def load_image_model(image):
|
38 |
# Disable scientific notation for clarity
|
39 |
np.set_printoptions(suppress=True)
|
40 |
|
41 |
# Load the model from the URL
|
42 |
+
model_url = "https://huggingface.co/spaces/Soham0708/pothole_detect/blob/main/keras_model.h5"
|
43 |
+
model = tf.keras.models.load_model(model_url, compile=False)
|
|
|
|
|
|
|
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 |
+
# resizing the image to be at least 224x224 and then cropping from the center
|
57 |
+
size = (224, 224)
|
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 |
+
# Predicts the model
|
70 |
prediction = model.predict(data)
|
71 |
index = np.argmax(prediction)
|
72 |
class_name = class_names[index]
|