Update app.py
Browse files
app.py
CHANGED
@@ -5,23 +5,15 @@ from keras.models import load_model
|
|
5 |
from sklearn.preprocessing import LabelEncoder
|
6 |
import pickle
|
7 |
|
8 |
-
#
|
9 |
-
model = load_model('
|
10 |
-
with open('
|
11 |
label_encoder = pickle.load(f)
|
12 |
|
13 |
|
14 |
def predict_breed(image, model, label_encoder):
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
:param image: Das Bild des Hundes als numpy Array
|
19 |
-
:param model: Das geladene Keras Modell
|
20 |
-
:param label_encoder: Der LabelEncoder für die Hunderassen
|
21 |
-
:return: Die vorhergesagte Hunderasse
|
22 |
-
"""
|
23 |
-
image = image.resize((128, 128)) # Ändere die Bildgröße entsprechend der Modellanforderungen
|
24 |
-
image = np.expand_dims(np.array(image), axis=0) # Füge Batch-Dimension hinzu
|
25 |
predictions = model.predict(image)
|
26 |
predicted_breed = label_encoder.inverse_transform([np.argmax(predictions)])
|
27 |
return predicted_breed[0]
|
|
|
5 |
from sklearn.preprocessing import LabelEncoder
|
6 |
import pickle
|
7 |
|
8 |
+
# das trainierte Modell und den LabelEncoder laden
|
9 |
+
model = load_model('dog_breed_classifier.h5')
|
10 |
+
with open('label_encoder.pkl', 'rb') as f:
|
11 |
label_encoder = pickle.load(f)
|
12 |
|
13 |
|
14 |
def predict_breed(image, model, label_encoder):
|
15 |
+
image = image.resize((128, 128))
|
16 |
+
image = np.expand_dims(np.array(image), axis=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
predictions = model.predict(image)
|
18 |
predicted_breed = label_encoder.inverse_transform([np.argmax(predictions)])
|
19 |
return predicted_breed[0]
|