|
|
|
|
|
|
|
|
import streamlit as st
|
|
|
import numpy as np
|
|
|
import pandas as pd
|
|
|
from keras.models import load_model
|
|
|
from PIL import Image, ImageDraw
|
|
|
import io
|
|
|
|
|
|
|
|
|
model = load_model('keypoint_model.h5')
|
|
|
|
|
|
def load_image(image):
|
|
|
image = Image.open(image).convert('RGB')
|
|
|
image = image.resize((96, 96))
|
|
|
image_array = np.array(image)
|
|
|
image_array = image_array / 255.0
|
|
|
return image_array.reshape(-1, 96, 96, 3)
|
|
|
|
|
|
def draw_keypoints(image, keypoints):
|
|
|
|
|
|
draw = ImageDraw.Draw(image)
|
|
|
for (x, y) in keypoints:
|
|
|
draw.ellipse((x - 3, y - 3, x + 3, y + 3), fill='red')
|
|
|
return image
|
|
|
|
|
|
|
|
|
st.title("Keypoint Prediction App")
|
|
|
|
|
|
|
|
|
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
|
|
|
|
|
if uploaded_file is not None:
|
|
|
|
|
|
image = load_image(uploaded_file)
|
|
|
|
|
|
|
|
|
original_image = Image.open(uploaded_file).convert('RGB').resize((96, 96))
|
|
|
st.image(original_image, caption='Uploaded Image.', use_column_width=True)
|
|
|
|
|
|
|
|
|
if st.button("Predict"):
|
|
|
predictions = model.predict(image)
|
|
|
|
|
|
keypoints = predictions.reshape(-1, 2)
|
|
|
|
|
|
|
|
|
keypoint_image = draw_keypoints(original_image.copy(), keypoints)
|
|
|
|
|
|
|
|
|
st.image(keypoint_image, caption='Image with Predicted Keypoints', use_column_width=True)
|
|
|
|
|
|
|
|
|
st.write("Predicted Keypoints:")
|
|
|
for i, (x, y) in enumerate(keypoints):
|
|
|
st.write(f"Keypoint {i+1}: (X: {x:.2f}, Y: {y:.2f})") |