Spaces:
Sleeping
Sleeping
okeowo1014
commited on
Commit
•
679e114
1
Parent(s):
3cbe74d
Create predictor.py
Browse files- predictor.py +26 -0
predictor.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
from tensorflow.keras.preprocessing import image
|
3 |
+
import numpy as np
|
4 |
+
from huggingface_hub import from_pretrained_keras
|
5 |
+
model = from_pretrained_keras("okeowo1014/catsanddogs")
|
6 |
+
|
7 |
+
# Load the saved model
|
8 |
+
loaded_model = tf.keras.models.load_model('fingerprint_recognition_model.keras')
|
9 |
+
|
10 |
+
# Define the image path for the new image you want to predict
|
11 |
+
image_path = 'path_to_your_new_image.jpg'
|
12 |
+
|
13 |
+
# Load and preprocess the image
|
14 |
+
img = image.load_img(image_path, target_size=(224, 224), color_mode='grayscale')
|
15 |
+
img_array = image.img_to_array(img)
|
16 |
+
img_array = np.expand_dims(img_array, axis=0)
|
17 |
+
img_array /= 255. # Normalize the image data
|
18 |
+
|
19 |
+
# Make predictions
|
20 |
+
predictions = loaded_model.predict(img_array)
|
21 |
+
|
22 |
+
# Get the predicted class label
|
23 |
+
predicted_class = np.argmax(predictions[0])
|
24 |
+
|
25 |
+
# Print the predicted class label
|
26 |
+
print(f'Predicted class label: {predicted_class}')
|