Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
retinaface_demo/app/app.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
39 lines (28 sloc)
1013 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Streamlit web app""" | |
import numpy as np | |
import streamlit as st | |
from PIL import Image | |
from retinaface.pre_trained_models import get_model | |
from retinaface.utils import vis_annotations | |
import torch | |
st.set_option("deprecation.showfileUploaderEncoding", False) | |
@st.cache | |
def cached_model(): | |
m = get_model("resnet50_2020-07-20", max_size=1048, device="cpu") | |
m.eval() | |
return m | |
model = cached_model() | |
st.title("Detect faces and key points") | |
uploaded_file = st.file_uploader("Choose an image...", type="jpg") | |
if uploaded_file is not None: | |
image = np.array(Image.open(uploaded_file)) | |
st.image(image, caption="Before", use_column_width=True) | |
st.write("") | |
st.write("Detecting faces...") | |
with torch.no_grad(): | |
annotations = model.predict_jsons(image) | |
if not annotations[0]["bbox"]: | |
st.write("No faces detected") | |
else: | |
visualized_image = vis_annotations(image, annotations) | |
st.image(visualized_image, caption="After", use_column_width=True) |