Update app.py
Browse files
app.py
CHANGED
|
@@ -33,8 +33,13 @@ model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.001),
|
|
| 33 |
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
|
| 34 |
metrics=['accuracy'])
|
| 35 |
|
|
|
|
| 36 |
# Using saved weights
|
| 37 |
model.load_weights('model_weights .h5')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
def classify_image(image):
|
| 39 |
# Convert Gradio Image to numpy array
|
| 40 |
image = np.array(image)
|
|
@@ -42,9 +47,7 @@ def classify_image(image):
|
|
| 42 |
image = cv2.resize(image, (180, 180))
|
| 43 |
# Make prediction
|
| 44 |
preds = model.predict(image[np.newaxis, ...]).squeeze()
|
| 45 |
-
y_pred = preds.argmax(axis = 0)
|
| 46 |
-
# return preds
|
| 47 |
-
# # Decode prediction
|
| 48 |
label = class_names[int(y_pred)]
|
| 49 |
return label
|
| 50 |
|
|
@@ -56,4 +59,4 @@ app = gr.Interface(
|
|
| 56 |
)
|
| 57 |
|
| 58 |
|
| 59 |
-
app.launch()
|
|
|
|
| 33 |
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
|
| 34 |
metrics=['accuracy'])
|
| 35 |
|
| 36 |
+
|
| 37 |
# Using saved weights
|
| 38 |
model.load_weights('model_weights .h5')
|
| 39 |
+
class_names = {
|
| 40 |
+
1: 'Female',
|
| 41 |
+
0: 'Male'
|
| 42 |
+
}
|
| 43 |
def classify_image(image):
|
| 44 |
# Convert Gradio Image to numpy array
|
| 45 |
image = np.array(image)
|
|
|
|
| 47 |
image = cv2.resize(image, (180, 180))
|
| 48 |
# Make prediction
|
| 49 |
preds = model.predict(image[np.newaxis, ...]).squeeze()
|
| 50 |
+
y_pred = preds.argmax(axis = 0) # Decode prediction
|
|
|
|
|
|
|
| 51 |
label = class_names[int(y_pred)]
|
| 52 |
return label
|
| 53 |
|
|
|
|
| 59 |
)
|
| 60 |
|
| 61 |
|
| 62 |
+
app.launch(share = True)
|