File size: 2,320 Bytes
3215154
 
 
e5bf98c
3215154
e5bf98c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a03474b
 
 
a645fec
a03474b
 
85ef282
e5bf98c
 
 
 
 
 
 
 
3215154
 
 
 
 
e5bf98c
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import streamlit as st
import degirum as dg
from PIL import Image
import degirum_tools

# hw_location: Where you want to run inference.
#     Use "@cloud" to use DeGirum cloud.
#     Use "@local" to run on local machine.
#     Use an IP address for AI server inference.
hw_location = "@cloud"

# face_model_zoo_url: URL/path for the face model zoo.
#     Use cloud_zoo_url for @cloud, @local, and AI server inference options.
#     Use '' for an AI server serving models from a local folder.
#     Use a path to a JSON file for a single model zoo in case of @local inference.
face_model_zoo_url = "https://cs.degirum.com/degirum/ultralytics_v6"

# face_model_name: Name of the model for face detection.
face_model_name = "yolov8n_relu6_face--640x640_quant_n2x_orca1_1"

# gender_model_zoo_url: URL/path for the gender model zoo.
gender_model_zoo_url = "https://cs.degirum.com/degirum/openvino"

# gender_model_name: Name of the model for gender detection.
gender_model_name = "mobilenet_v2_gender--160x160_float_openvino_cpu_1"

# Connect to AI inference engine getting token from env.ini file
face_zoo = dg.connect(hw_location, face_model_zoo_url, token=st.secrets["DG_TOKEN"])
gender_zoo = dg.connect(hw_location, gender_model_zoo_url, token=st.secrets["DG_TOKEN"])

# Load models
face_model = face_zoo.load_model(face_model_name, 
                                 image_backend='pil',
                                 overlay_color=(255,0,0),
                                 overlay_line_width=2,
                                 overlay_font_scale=2.0                                
                                )
gender_model= gender_zoo.load_model(gender_model_name, image_backend='pil')
# Create a compound cropping model with 50% crop extent
crop_model = degirum_tools.CroppingAndClassifyingCompoundModel(
    face_model, gender_model, 50.0
    )

st.title('DeGirum Cloud Platform Demo of Face and Gender Detection Model')

st.text('Upload an image. Then click on the submit button')
with st.form("model_form"):
    uploaded_file=st.file_uploader('input image')
    submitted = st.form_submit_button("Submit")
    if submitted:
        image = Image.open(uploaded_file)
        inference_results=crop_model(image)
        st.image(inference_results.image_overlay,caption='Image with Bounding Boxes')