kiki7555 commited on
Commit
1ea602b
1 Parent(s): c5102c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -17
app.py CHANGED
@@ -2,40 +2,33 @@ import gradio as gr
2
  import tensorflow as tf
3
  from PIL import Image
4
  import numpy as np
5
- from tensorflow.keras.preprocessing.image import ImageDataGenerator
6
 
7
- # Load the car brand classifier model
8
- model_path = "car_brand_classifier_finetuned.keras"
9
  model = tf.keras.models.load_model(model_path)
 
10
 
11
- labels = ['Hyundai', 'Lexus', 'Mazda', 'Mercedes', 'Opel', 'Skoda', 'Toyota', 'Volkswagen']
12
-
13
- # Define function for car brand classification with data augmentation
14
  def preprocess_image(image):
15
  image = Image.fromarray(image.astype('uint8'), 'RGB')
16
- image = image.resize((224, 224))
17
  image = np.array(image)
18
- image = image / 255.0 # Normalize pixel values
19
  return image
20
 
21
-
22
  # Prediction function
23
- def predict_car_brand(image):
24
  image = preprocess_image(image)
25
  prediction = model.predict(np.expand_dims(image, axis=0))
26
  predicted_class = labels[np.argmax(prediction)]
27
  confidence = np.round(np.max(prediction) * 100, 2)
28
- result = f"Label: {predicted_class}, Confidence: {confidence}%"
29
  return result
30
 
31
  # Create Gradio interface
32
  input_image = gr.Image()
33
- output_text = gr.Textbox(label="Car Brand")
34
- interface = gr.Interface(fn=predict_car_brand,
35
- inputs=input_image,
36
- outputs=output_text,
37
- description="A car brand classifier using transfer learning and fine-tuning with EfficientNetB0.",
38
- theme="default")
39
 
40
  if __name__ == "__main__":
41
  interface.launch()
 
2
  import tensorflow as tf
3
  from PIL import Image
4
  import numpy as np
 
5
 
6
+ # Load the dog breed classifier model
7
+ model_path = "dog_breed_classifier_trained.keras"
8
  model = tf.keras.models.load_model(model_path)
9
+ labels = ['Rasse 1', 'Rasse 2', 'Rasse 3', 'Rasse 4', 'Rasse 5'] # Ersetzen Sie dies durch Ihre tatsächlichen Rassennamen
10
 
11
+ # Define function for dog breed classification with data augmentation
 
 
12
  def preprocess_image(image):
13
  image = Image.fromarray(image.astype('uint8'), 'RGB')
14
+ image = image.resize((128, 128)) # Entspricht der Größe aus Ihrem Notebook
15
  image = np.array(image)
16
+ image = image / 255.0 # Normalisierung der Pixelwerte
17
  return image
18
 
 
19
  # Prediction function
20
+ def predict_dog_breed(image):
21
  image = preprocess_image(image)
22
  prediction = model.predict(np.expand_dims(image, axis=0))
23
  predicted_class = labels[np.argmax(prediction)]
24
  confidence = np.round(np.max(prediction) * 100, 2)
25
+ result = f"Breed: {predicted_class}, Confidence: {confidence}%"
26
  return result
27
 
28
  # Create Gradio interface
29
  input_image = gr.Image()
30
+ output_text = gr.Textbox(label="Dog Breed")
31
+ interface = gr.Interface(fn=predict_dog_breed, inputs=input_image, outputs=output_text, description="A dog breed classifier using transfer learning and fine-tuning with EfficientNetB0.", theme="default")
 
 
 
 
32
 
33
  if __name__ == "__main__":
34
  interface.launch()