Views
No views yet
.keras model file1from tensorflow import keras
2import huggingface_hub
3
4model_path = huggingface_hub.hf_hub_download("furkankarakuz/AnimalVision", "AnimalVisionModel.keras")
5model = keras.models.load_model(model_path)1from tensorflow import keras
2from tensorflow.keras.preprocessing import image
3import huggingface_hub
4import numpy as np
5
6
7model_path = huggingface_hub.hf_hub_download("furkankarakuz/AnimalVision", "AnimalVisionModel.keras")
8model = keras.models.load_model(model_path)
9
10
11def load_animal_labels():
12 label_path = huggingface_hub.hf_hub_download("furkankarakuz/AnimalVision", "AnimalList.txt")
13 with open(label_path, "r") as file:
14 return file.read().split("\n")
15
16
17def predict_image(img_path, model):
18 img = image.load_img(img_path, target_size=(224, 224))
19 img_array = image.img_to_array(img) / 255.0
20 img_array = np.expand_dims(img_array, axis=0)
21 predictions = model.predict(img_array, verbose=0)[0]
22 class_index = np.argmax(predictions)
23
24 animal_classes = load_animal_labels()
25 animal_name = animal_classes[class_index]
26
27 return animal_name
28
29
30image_path = "example.jpg"
31predicted_animal = predict_image(image_path, model)
32print(f"Predicted Animal: {predicted_animal}")
33