File size: 1,195 Bytes
731fcb3
 
 
 
 
 
99443e8
731fcb3
 
99443e8
731fcb3
 
 
 
 
2c96251
731fcb3
 
 
 
 
2c96251
731fcb3
 
 
 
2c96251
 
731fcb3
99443e8
4e83195
 
731fcb3
4e83195
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import gradio as gr
import tensorflow as tf
from PIL import Image
import numpy as np

# Lade dein Modell (hier als Beispiel die Keras .h5 Datei)
model = tf.keras.models.load_model('gym_equipment_transferlearning.keras')

# Klassennamen, sollten deinem Dataset entsprechen
class_names = ['benchPress', 'dumbBell', 'kettleBell', 'treadMill']

def classify_image(image):
    image = Image.fromarray(image.astype('uint8'), 'RGB')
    img = image.resize((150, 150))
    img_array = tf.keras.preprocessing.image.img_to_array(img)
    img_array = tf.expand_dims(img_array, 0)  # Erstelle einen Batch
    predictions = model.predict(img_array)
    predicted_class = class_names[np.argmax(predictions[0])]
    confidence = np.max(predictions[0])
    return {predicted_class: float(confidence)}


image_input = gr.Image()  # Entferne den `shape` Parameter
label = gr.Label(num_top_classes=3)

iface = gr.Interface(
    fn=classify_image, 
    inputs=image_input, 
    outputs=label,
    title='Gym Equipment Classifier',
    description='Upload an image of gym equipment and the classifier will tell you which one it is and the confidence level of the prediction.'
)

# Launch the interface
iface.launch()