baumgshe commited on
Commit
435df93
·
verified ·
1 Parent(s): 8314c67

Upload 2 files

Browse files
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. app.py +59 -0
  3. pikatchu_vs_raichu_vs_snorlax.keras +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ pikatchu_vs_raichu_vs_snorlax.keras filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+ import pandas as pd
6
+ import matplotlib.pyplot as plt
7
+
8
+ # Load the trained model
9
+ model_path = "pikatchu_vs_raichu_vs_snorlax.keras"
10
+ model = tf.keras.models.load_model(model_path)
11
+
12
+ # Define the core prediction function
13
+ def predict_pokemon(image):
14
+ # Preprocess image
15
+ image = image.resize((150, 150)) # Resize the image to 150x150
16
+ image = image.convert('RGB') # Ensure image has 3 channels
17
+ image = np.array(image)
18
+ image = np.expand_dims(image, axis=0) # Add batch dimension
19
+
20
+ # Predict
21
+ prediction = model.predict(image)
22
+
23
+ # Apply softmax to get probabilities for each class
24
+ probabilities = tf.nn.softmax(prediction, axis=1)
25
+
26
+ # Map probabilities to Pokemon classes
27
+ class_names = ['Pikachu', 'Raichu', 'Snorlax']
28
+ probabilities_dict = {pokemon_class: round(float(probability), 2) for pokemon_class, probability in zip(class_names, probabilities.numpy()[0])}
29
+
30
+ return probabilities_dict
31
+
32
+ # Streamlit interface
33
+ st.title("Pokemon Classification Tool")
34
+ st.write("A basic MLP classifier for image recognition utilizing a pre-trained model.")
35
+
36
+ # Upload image
37
+ uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "png"])
38
+
39
+ if uploaded_image is not None:
40
+ image = Image.open(uploaded_image)
41
+ st.image(image, caption='Uploaded Image.', use_column_width=True)
42
+ st.write("")
43
+ st.write("Classifying...")
44
+
45
+ predictions = predict_pokemon(image)
46
+
47
+ # Display predictions as a DataFrame
48
+ st.write("### Prediction Probabilities")
49
+ df = pd.DataFrame(predictions.items(), columns=["Pokemon", "Probability"])
50
+ st.dataframe(df)
51
+
52
+ # Display predictions as a bar chart
53
+ st.write("### Prediction Chart")
54
+ fig, ax = plt.subplots()
55
+ ax.barh(df["Pokemon"], df["Probability"], color='skyblue')
56
+ ax.set_xlim(0, 1)
57
+ ax.set_xlabel('Probability')
58
+ ax.set_title('Prediction Probabilities')
59
+ st.pyplot(fig)
pikatchu_vs_raichu_vs_snorlax.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:276fca4de30a03b9e49e29f40526e93c37f8dc3b80de4df72568c2e43ca0cd05
3
+ size 250560272