File size: 808 Bytes
cd83a2a 5056ec5 |
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 |
import gradio as gr
def predict_age_gender(image):
json_file = open('final_mobilenet.json', 'r')
loaded_file_json = json_file.read()
json_file.close()
model = model_from_json(loaded_file_json)
model.load_weights('final_mobilenet.h5')
# img_pixels = image.img_to_array(image)
# img = tf.reshape(image, shape=(-1, 128, 128, 3))
img_pixels = np.expand_dims(image, axis=0)
img_pixels = image.astype('float')
img_pixels = img_pixels.reshape((1, 128, 128, 3))
img_pixels /= 255
predict = model.predict(img_pixels)
gender_predict = predict[0]
age_predict = predict[1]
return {'Gender': ['Fmale' if gender_predict > 0.5 else 'Male'], 'Age': age_predict[0][0]}
iface = gr.Interface(predict_age_gender, gr.Image(), gr.Text())
iface.launch(share=True)
|