forked from mlrun/demos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.py
More file actions
106 lines (91 loc) · 4.1 KB
/
Copy pathdashboard.py
File metadata and controls
106 lines (91 loc) · 4.1 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import streamlit as st
import cv2
from imutils import paths
import pandas as pd
import matplotlib.pyplot as plt
import v3io_frames as v3f
import os
import shutil
import datetime
from logger import Logger
def load_images(images_path):
return [f for f in paths.list_images(images_path) if '.ipynb' not in f]
@st.cache
def load_enc_df(p_kv_table_path):
return client.read(backend="kv", table=p_kv_table_path, reset_index=True, filter="label!=-1")
if __name__ == '__main__':
logger = Logger()
frames_uri = os.environ.get('FRAMES_URI')
container = os.getenv('CONTAINER', 'users')
token = os.getenv('V3IO_ACCESS_KEY')
kv_table_path = os.getenv('KV_TABLE_PATH')
logger.info(os.environ.items())
client = v3f.Client(frames_uri, token=token, container=container)
base_path = '/User/examples/faces/'
data_path = base_path + 'data/'
artifact_path = base_path+'artifacts/'
classes_path = artifact_path + 'idx2name.csv'
logger.info("classes_path: {}".format(classes_path))
classes_df = pd.read_csv(classes_path)
known_classes = [n.replace('_', ' ') for n in classes_df['name'].values]
page = st.sidebar.selectbox('Choose option', ['Label Unknown Images', 'View Collected Images'], key=1)
if page == 'Label Unknown Images':
label_path = data_path + 'label_pending'
logger.info("label_path: {}".format(data_path + 'label_pending'))
images = load_images(label_path)
st.title('Label Unknown Images')
# generates list of valid labeling options
options = ['None'] + known_classes + ['add new employee', 'not an employee']
# Are there any images left to tag?
# - Yes
if len(images) > 0:
# Show image select box
idx = st.selectbox('Choose picture to label', range(len(images)))
path = images[idx]
img = cv2.imread(path)
rgb_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
st.subheader('Do you know this person?')
plt.imshow(rgb_img)
plt.axis('off')
st.pyplot(plt)
selected_label = st.selectbox(label='Select label for the image', options=options, key=0)
# Was a label selected (in previous step) ?
# - Yes
if selected_label != "None":
tag_time = datetime.datetime.now()
date_time = tag_time.strftime("%d:%m:%Y:%H%M%S")
if selected_label == 'not an employee':
dir_name = data_path + 'unrecognized'
if not os.path.exists(dir_name):
os.mkdir(dir_name)
file_name = dir_name + '/' + date_time + '.jpg'
elif selected_label == 'add new employee':
new_name = st.text_input('Please enter name of employee')
dir_name = data_path + 'input/' + new_name.replace(' ', '_')
if not os.path.exists(dir_name):
os.mkdir(dir_name)
file_name = dir_name + '/' + date_time + '.jpg'
else:
dir_name = data_path + 'input/' + selected_label.replace(' ', '_')
if not os.path.exists(dir_name):
os.mkdir(dir_name)
file_name = dir_name + '/' + date_time + '.jpg'
if st.button('apply', key=100):
shutil.move(path, file_name)
st.empty()
else:
st.success('No more images to label')
if page == 'View Collected Images':
st.title('View Collected Images')
enc_df = load_enc_df(kv_table_path)
view_df = enc_df[['fileName', 'camera', 'time']]
view_df = view_df.rename(columns={'fileName': 'identifier'})
view_df['identifier'] = view_df['identifier']
st.dataframe(view_df)
idx = st.selectbox('Choose image to view', range(len(view_df)), key=2)
img_url = enc_df.iloc[idx]['imgUrl']
kv_img = cv2.imread(img_url)
rgb_kv_img = cv2.cvtColor(kv_img, cv2.COLOR_BGR2RGB)
plt.imshow(rgb_kv_img)
plt.axis('off')
st.pyplot(plt)