Views
No views yet
1import tensorflow as tf
2from tensorflow.keras.models import load_model
3import numpy as np
4from tensorflow.keras.preprocessing import image
5
6# Load the pre-trained model
7model = tf.keras.models.load_model("path_to_model")
8
9# Example image preprocessing
10img_path = "path_to_image.jpg"
11img = image.load_img(img_path, target_size=(128, 128)) # Resize to 128x128
12img_array = image.img_to_array(img)
13img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
14img_array /= 255.0 # Normalize to [0, 1]
15
16# Predict the cat breed
17predictions = model.predict(img_array)
18
19# Predict the cat breed
20predictions = model.predict(img_array)
21class_labels = ["Bengal", "Domestic Shorthair", "Maine Coon", "Ragdoll", "Siamese"]
22predicted_breed = class_labels[np.argmax(predictions)]
23
24
25predicted_breed = class_labels[np.argmax(predictions)]
26
27print(f"Predicted Cat Breed: {predicted_breed}")
28