Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- .gitattributes +1 -0
- app.py +35 -0
- pokemon_classifier.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 |
+
pokemon_classifier.keras filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
# Modell laden
|
| 8 |
+
model = tf.keras.models.load_model('pokemon_classifier.keras')
|
| 9 |
+
|
| 10 |
+
def classify_image(image):
|
| 11 |
+
# Bild vorverarbeiten
|
| 12 |
+
image = Image.fromarray(image.astype('uint8')).convert('RGB')
|
| 13 |
+
image = image.resize((150, 150)) # Anpassung der Größe an das Modell
|
| 14 |
+
image = np.array(image) / 255.0 # Normalisieren
|
| 15 |
+
image = np.expand_dims(image, axis=0) # Hinzufügen der Batch-Dimension
|
| 16 |
+
|
| 17 |
+
# Vorhersage machen
|
| 18 |
+
prediction = model.predict(image).flatten()
|
| 19 |
+
classes = ['Abra', 'Ditto', 'Gengar'] # Namen der Klassen
|
| 20 |
+
|
| 21 |
+
# Wahrscheinlichkeiten mit Klassen verbinden und formatieren
|
| 22 |
+
return {classes[i]: float(prediction[i]) for i in range(len(classes))}
|
| 23 |
+
|
| 24 |
+
# Gradio-Interface erstellen
|
| 25 |
+
input_image = gr.Image()
|
| 26 |
+
iface = gr.Interface(
|
| 27 |
+
fn=classify_image,
|
| 28 |
+
inputs=input_image,
|
| 29 |
+
outputs=gr.Label(num_top_classes=3),
|
| 30 |
+
examples=["pokemon/Abra/00000000.png", "pokemon/Ditto/00000000.jpg", "pokemon/Gengar/00000000.png"], # Beispiele hinzufügen
|
| 31 |
+
description="Upload an image of a Pokémon to classify it as Pikachu, Charmander, or Bulbasaur."
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
# Interface starten
|
| 35 |
+
iface.launch()
|
pokemon_classifier.keras
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ff305ef1fc7eb416680885e4372882de8633b085344c62c44c2cffee9532aac3
|
| 3 |
+
size 103363188
|