shashichilappagari commited on
Commit
e5bf98c
1 Parent(s): 76647cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -41
app.py CHANGED
@@ -1,50 +1,48 @@
1
  import streamlit as st
2
  import degirum as dg
3
  from PIL import Image
 
4
 
5
- zoo=dg.connect(dg.CLOUD,zoo_url='https://cs.degirum.com/degirum/ultralytics_v6',token=st.secrets["DG_TOKEN"])
6
-
7
- st.title('DeGirum Cloud Platform Demo')
8
-
9
- with st.sidebar:
10
- st.header('Specify Model Options Below')
11
- runtime_agent_device=st.radio("Choose runtime agent device combo",("N2X-ORCA1","TFLite-EdgeTPU","OpenVINO-CPU"),index=0,horizontal=True)
12
- activation_option=st.radio( 'Select activation function', ['relu6', 'silu'],horizontal=True)
13
- dataset_option=st.radio( 'Select a dataset option', ['coco', 'face','lp','car','hand'],horizontal=True)
14
- show_labels=st.toggle('Show labels in output',value=True)
15
- show_probabilities=st.toggle('Show probabilities in output',value=False)
16
- runtime_agent,device=runtime_agent_device.split('-')[0],runtime_agent_device.split('-')[1]
17
- model_options=zoo.list_models(device=device,runtime=runtime_agent)
18
- st.header('Choose and Run a Model')
19
- st.text('Select a model and upload an image. Then click on the submit button')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  with st.form("model_form"):
21
- filtered_model_list=[]
22
- for model in model_options:
23
- if activation_option in model and dataset_option in model:
24
- filtered_model_list.append(model)
25
- st.write('Number of models found = ', len(filtered_model_list))
26
- model_name=st.selectbox("Choose a Model from the list", filtered_model_list)
27
  uploaded_file=st.file_uploader('input image')
28
  submitted = st.form_submit_button("Submit")
29
  if submitted:
30
- model=zoo.load_model(model_name,
31
- overlay_show_labels=show_labels,
32
- overlay_show_probabilities=show_probabilities,
33
- overlay_font_scale=3,
34
- overlay_line_width=6,
35
- image_backend='pil'
36
- )
37
- if model.output_postprocess_type=='PoseDetection':
38
- model.overlay_show_labels=False
39
- st.write("Model loaded successfully")
40
  image = Image.open(uploaded_file)
41
- predictions=model(image)
42
- if model.output_postprocess_type=='Classification' or model.output_postprocess_type=='DetectionYoloPlates':
43
- st.image(predictions.image,caption='Original Image')
44
- st.write(predictions.results)
45
- else:
46
- st.image(predictions.image_overlay,caption='Image with Bounding Boxes/Keypoints')
47
- model.measure_time=True
48
- predictions=model(image)
49
- stats=model.time_stats()
50
- st.write('Expected Frames per second for the model= ', 1000.0/stats["CoreInferenceDuration_ms"].avg)
 
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
+ # gender_model_zoo_url: URL/path for the gender model zoo.
22
+ gender_model_zoo_url = "https://cs.degirum.com/degirum/openvino"
23
+
24
+ # gender_model_name: Name of the model for gender detection.
25
+ gender_model_name = "mobilenet_v2_gender--160x160_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
+ gender_zoo = dg.connect(hw_location, gender_model_zoo_url, token=st.secrets["DG_TOKEN"])
30
+
31
+ # Load models
32
+ face_model = face_zoo.load_model(face_model_name)
33
+ gender_model= gender_zoo.load_model(gender_model_name)
34
+ # Create a compound cropping model with 50% crop extent
35
+ crop_model = degirum_tools.CroppingAndClassifyingCompoundModel(
36
+ face_model, gender_model, 50.0
37
+ )
38
+
39
+ st.title('DeGirum Cloud Platform Demo of Face and Gender Detection Model')
40
+
41
+ st.text('Upload an image. Then click on the submit button')
42
  with st.form("model_form"):
 
 
 
 
 
 
43
  uploaded_file=st.file_uploader('input image')
44
  submitted = st.form_submit_button("Submit")
45
  if submitted:
 
 
 
 
 
 
 
 
 
 
46
  image = Image.open(uploaded_file)
47
+ inference_results=crop_model(image)
48
+ st.image(inference_results.image_overlay,caption='Image with Bounding Boxes')