Update app.py
Browse files
app.py
CHANGED
@@ -4,29 +4,40 @@ from tensorflow.keras.preprocessing import image
|
|
4 |
import numpy as np
|
5 |
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
def predict_age_gender(image):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
json_file = open('xception.json', 'r')
|
13 |
loaded_file_json = json_file.read()
|
14 |
json_file.close()
|
15 |
-
|
16 |
model = model_from_json(loaded_file_json)
|
17 |
model.load_weights('xception_modelv2.h5')
|
|
|
|
|
18 |
|
19 |
images = np.resize(image, new_shape=(1, 128, 128, 3))
|
20 |
img_pixels = np.expand_dims(images, axis=0)
|
21 |
-
img_pixels =
|
22 |
img_pixels = img_pixels.reshape((1, 128, 128, 3))
|
23 |
img_pixels /= 255
|
24 |
|
|
|
|
|
25 |
predict = model.predict(img_pixels)
|
26 |
-
|
27 |
-
|
28 |
-
return {'Gender': ['Fmale' if gender_predict > 0.5 else 'Male'], 'Age': age_predict[0][0]}
|
29 |
|
|
|
30 |
|
31 |
-
|
32 |
-
|
|
|
|
|
|
4 |
import numpy as np
|
5 |
|
6 |
|
|
|
|
|
|
|
|
|
7 |
def predict_age_gender(image):
|
8 |
+
|
9 |
+
json_file_2 = open('model_gender_2.json', 'r')
|
10 |
+
loaded_file_json_2 = json_file_2.read()
|
11 |
+
json_file_2.close()
|
12 |
+
|
13 |
+
model_2 = model_from_json(loaded_file_json_2)
|
14 |
+
model_2.load_weights('model_gender_2.h5')
|
15 |
+
|
16 |
+
|
17 |
json_file = open('xception.json', 'r')
|
18 |
loaded_file_json = json_file.read()
|
19 |
json_file.close()
|
20 |
+
|
21 |
model = model_from_json(loaded_file_json)
|
22 |
model.load_weights('xception_modelv2.h5')
|
23 |
+
|
24 |
+
|
25 |
|
26 |
images = np.resize(image, new_shape=(1, 128, 128, 3))
|
27 |
img_pixels = np.expand_dims(images, axis=0)
|
28 |
+
img_pixels = img_pixels.astype('float64')
|
29 |
img_pixels = img_pixels.reshape((1, 128, 128, 3))
|
30 |
img_pixels /= 255
|
31 |
|
32 |
+
class_names_gender = ['Fmale', 'Male']
|
33 |
+
gender_predict = model_2.predict(img_pixels)
|
34 |
predict = model.predict(img_pixels)
|
35 |
+
age_result = predict[1][0].round()
|
36 |
+
|
|
|
37 |
|
38 |
+
return 'Female' if gender_predict<0.5 else 'Male', age_result
|
39 |
|
40 |
+
|
41 |
+
|
42 |
+
iface = gr.Interface(predict_age_gender, gr.Image(), [gr.Label(label='Gender'), gr.Number(label='Age')],)
|
43 |
+
iface.launch()
|