Views
No views yet
import keras
from keras.src.utils import load_img
from keras.src.applications.densenet import preprocess_input
import numpy as np
pokedex = keras.saving.load_model("pokedex.keras")
image = load_img('image.png', target_size=(224, 224))
x = keras.utils.img_to_array(image)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
preds = pokedex.predict(x)
# Important: You must ensure that the Pokémon are ordered alphabetically, as the model was trained using this sequence. You can obtain the .txt file from the following link: https://huggingface.co/spaces/RogerKoala/Pokedex/blob/main/Pokemons.txt
with open('Pokemons.txt', 'r') as f:
class_labels = f.read().splitlines()
top_indices = preds[0].argsort()[-3:][::-1]
for i in top_indices:
print(f"{class_labels[i]}: {preds[0][i]*100:.2f}%")| Layer (type) | Output Shape | Param # |
|---|---|---|
| densenet121 (Functional) | (None, 7, 7, 1024) | 7,037,504 |
| global_average_pooling2d (GlobalAveragePooling2D) | (None, 1024) | 0 |
| dense (Dense) | (None, 128) | 131,200 |
| dropout (Dropout) | (None, 128) | 0 |
| dense_1 (Dense) | (None, 151) | 19,479 |