|
import streamlit as st |
|
import numpy as np |
|
from tensorflow.keras.preprocessing import image |
|
import tensorflow as tf |
|
|
|
|
|
model = tf.keras.models.load_model("pokemon_model_fahrnphi_transferlearning.keras") |
|
|
|
|
|
img_height, img_width = 299, 299 |
|
|
|
|
|
def predict_label_and_probability(image_path): |
|
|
|
img = image.load_img(image_path, target_size=(img_height, img_width)) |
|
x = image.img_to_array(img) |
|
x = np.expand_dims(x, axis=0) |
|
x /= 255. |
|
|
|
|
|
preds = model.predict(x) |
|
class_idx = np.argmax(preds[0]) |
|
|
|
|
|
class_labels = {0: 'Charizard', 1: 'Lapras', 2: 'Machamp'} |
|
predicted_class = class_labels[class_idx] |
|
|
|
|
|
probability = preds[0][class_idx] |
|
return predicted_class, probability |
|
|
|
|
|
st.title("Pokémon Classification") |
|
|
|
uploaded_file = st.file_uploader("Choose a Pokémon image...", type="jpg") |
|
|
|
if uploaded_file is not None: |
|
|
|
st.image(uploaded_file, caption='Uploaded Pokémon Image.', use_column_width=True) |
|
|
|
|
|
label, probability = predict_label_and_probability(uploaded_file) |
|
st.write("Prediction:", label) |
|
st.write("Probability:", probability) |
|
|