nklimov commited on
Commit
880ed12
β€’
1 Parent(s): a758518

Face Detection and Age Regression Demo

Browse files
Files changed (3) hide show
  1. README.md +5 -5
  2. app.py +54 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
- title: Face Age
3
- emoji: 😻
4
- colorFrom: gray
5
- colorTo: green
6
  sdk: streamlit
7
- sdk_version: 1.30.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
1
  ---
2
+ title: Face Detection and Age Regression
3
+ emoji: πŸ“ˆ
4
+ colorFrom: blue
5
+ colorTo: red
6
  sdk: streamlit
7
+ sdk_version: 1.28.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import degirum as dg
3
+ from PIL import Image
4
+ import degirum_tools
5
+
6
+ # hw_location: Where you want to run inference.
7
+ # Use "@cloud" to use DeGirum cloud.
8
+ # Use "@local" to run on local machine.
9
+ # Use an IP address for AI server inference.
10
+ hw_location = "@cloud"
11
+
12
+ # face_model_zoo_url: URL/path for the face model zoo.
13
+ # Use cloud_zoo_url for @cloud, @local, and AI server inference options.
14
+ # Use '' for an AI server serving models from a local folder.
15
+ # Use a path to a JSON file for a single model zoo in case of @local inference.
16
+ face_model_zoo_url = "https://cs.degirum.com/degirum/ultralytics_v6"
17
+
18
+ # face_model_name: Name of the model for face detection.
19
+ face_model_name = "yolov8n_relu6_face--640x640_quant_n2x_orca1_1"
20
+
21
+ # age_model_zoo_url: URL/path for the age model zoo.
22
+ age_model_zoo_url = "https://cs.degirum.com/degirum/sandbox"
23
+
24
+ # age_model_name: Name of the model for age detection.
25
+ age_model_name = "yolov8s_regress_age_silu_utkface--256x256_float_openvino_cpu_1"
26
+
27
+ # Connect to AI inference engine getting token from env.ini file
28
+ face_zoo = dg.connect(hw_location, face_model_zoo_url, token=st.secrets["DG_TOKEN"])
29
+ age_zoo = dg.connect(hw_location, age_model_zoo_url, token=st.secrets["DG_TOKEN"])
30
+
31
+ # Load models
32
+ face_model = face_zoo.load_model(face_model_name,
33
+ image_backend='pil',
34
+ overlay_color=(255,0,0),
35
+ overlay_line_width=2,
36
+ overlay_font_scale=1.5
37
+ )
38
+ age_model= age_zoo.load_model(age_model_name, image_backend='pil')
39
+ # Create a compound cropping model with 50% crop extent
40
+ crop_model = degirum_tools.CroppingAndClassifyingCompoundModel(
41
+ face_model, age_model, 50.0
42
+ )
43
+
44
+ st.title('DeGirum Cloud Platform Demo of Face Detection and Age Regression Models')
45
+
46
+ st.text('Upload an image. Then click on the submit button')
47
+ with st.form("model_form"):
48
+ uploaded_file=st.file_uploader('input image')
49
+ submitted = st.form_submit_button("Submit")
50
+ if submitted:
51
+ image = Image.open(uploaded_file)
52
+ image.thumbnail((640,640), Image.Resampling.LANCZOS)
53
+ inference_results=crop_model(image)
54
+ st.image(inference_results.image_overlay,caption='Image with Bounding Boxes')
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ degirum
2
+ degirum_tools
3
+ altair<5