IliaLarchenko
commited on
Commit
β’
3efd956
1
Parent(s):
d8b1533
bugfix
Browse files- src/app.py +9 -61
- src/utils.py +47 -0
- src/visuals.py +13 -1
src/app.py
CHANGED
@@ -2,72 +2,20 @@ import os
|
|
2 |
import streamlit as st
|
3 |
import albumentations as A
|
4 |
|
5 |
-
from utils import
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
from visuals import (
|
7 |
-
show_transform_control,
|
8 |
select_image,
|
9 |
show_credentials,
|
10 |
show_docstring,
|
|
|
11 |
)
|
12 |
|
13 |
-
|
14 |
-
def get_placeholder_params(image):
|
15 |
-
return {
|
16 |
-
"image_width": image.shape[1],
|
17 |
-
"image_height": image.shape[0],
|
18 |
-
"image_half_width": int(image.shape[1] / 2),
|
19 |
-
"image_half_height": int(image.shape[0] / 2),
|
20 |
-
}
|
21 |
-
|
22 |
-
|
23 |
-
def select_transformations(augmentations: dict, interface_type: str) -> list:
|
24 |
-
# in the Simple mode you can choose only one transform
|
25 |
-
if interface_type == "Simple":
|
26 |
-
transform_names = [
|
27 |
-
st.sidebar.selectbox(
|
28 |
-
"Select a transformation:", sorted(list(augmentations.keys()))
|
29 |
-
)
|
30 |
-
]
|
31 |
-
# in the professional mode you can choose several transforms
|
32 |
-
elif interface_type == "Professional":
|
33 |
-
transform_names = [
|
34 |
-
st.sidebar.selectbox(
|
35 |
-
"Select transformation β1:", sorted(list(augmentations.keys()))
|
36 |
-
)
|
37 |
-
]
|
38 |
-
while transform_names[-1] != "None":
|
39 |
-
transform_names.append(
|
40 |
-
st.sidebar.selectbox(
|
41 |
-
f"Select transformation β{len(transform_names) + 1}:",
|
42 |
-
["None"] + sorted(list(augmentations.keys())),
|
43 |
-
)
|
44 |
-
)
|
45 |
-
transform_names = transform_names[:-1]
|
46 |
-
return transform_names
|
47 |
-
|
48 |
-
|
49 |
-
def get_transormations_params(transform_names: list) -> list:
|
50 |
-
transforms = []
|
51 |
-
for i, transform_name in enumerate(transform_names):
|
52 |
-
# select the params values
|
53 |
-
st.sidebar.subheader("Params of the " + transform_name)
|
54 |
-
param_values = show_transform_control(augmentations[transform_name], i)
|
55 |
-
transforms.append(getattr(A, transform_name)(**param_values))
|
56 |
-
return transforms
|
57 |
-
|
58 |
-
|
59 |
-
def show_random_params(data: dict, interface_type: str = "Professional"):
|
60 |
-
"""Shows random params used for transformation (from A.ReplayCompose)"""
|
61 |
-
if interface_type == "Professional":
|
62 |
-
st.subheader("Random params used")
|
63 |
-
random_values = {}
|
64 |
-
for applied_params in data["replay"]["transforms"]:
|
65 |
-
random_values[
|
66 |
-
applied_params["__class_fullname__"].split(".")[-1]
|
67 |
-
] = applied_params["params"]
|
68 |
-
st.write(random_values)
|
69 |
-
|
70 |
-
|
71 |
# TODO: refactor all the new code
|
72 |
|
73 |
# get CLI params: the path to images and image width
|
@@ -100,7 +48,7 @@ else:
|
|
100 |
transform_names = select_transformations(augmentations, interface_type)
|
101 |
|
102 |
# get parameters for each transform
|
103 |
-
transforms = get_transormations_params(transform_names)
|
104 |
|
105 |
try:
|
106 |
# apply the transformation to the image
|
|
|
2 |
import streamlit as st
|
3 |
import albumentations as A
|
4 |
|
5 |
+
from utils import (
|
6 |
+
load_augmentations_config,
|
7 |
+
get_arguments,
|
8 |
+
get_placeholder_params,
|
9 |
+
select_transformations,
|
10 |
+
show_random_params,
|
11 |
+
)
|
12 |
from visuals import (
|
|
|
13 |
select_image,
|
14 |
show_credentials,
|
15 |
show_docstring,
|
16 |
+
get_transormations_params,
|
17 |
)
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
# TODO: refactor all the new code
|
20 |
|
21 |
# get CLI params: the path to images and image width
|
|
|
48 |
transform_names = select_transformations(augmentations, interface_type)
|
49 |
|
50 |
# get parameters for each transform
|
51 |
+
transforms = get_transormations_params(transform_names, augmentations)
|
52 |
|
53 |
try:
|
54 |
# apply the transformation to the image
|
src/utils.py
CHANGED
@@ -109,3 +109,50 @@ def get_params_string(param_values: dict) -> str:
|
|
109 |
[k + "=" + str(param_values[k]) for k in param_values.keys()]
|
110 |
)
|
111 |
return params_string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
[k + "=" + str(param_values[k]) for k in param_values.keys()]
|
110 |
)
|
111 |
return params_string
|
112 |
+
|
113 |
+
|
114 |
+
def get_placeholder_params(image):
|
115 |
+
return {
|
116 |
+
"image_width": image.shape[1],
|
117 |
+
"image_height": image.shape[0],
|
118 |
+
"image_half_width": int(image.shape[1] / 2),
|
119 |
+
"image_half_height": int(image.shape[0] / 2),
|
120 |
+
}
|
121 |
+
|
122 |
+
|
123 |
+
def select_transformations(augmentations: dict, interface_type: str) -> list:
|
124 |
+
# in the Simple mode you can choose only one transform
|
125 |
+
if interface_type == "Simple":
|
126 |
+
transform_names = [
|
127 |
+
st.sidebar.selectbox(
|
128 |
+
"Select a transformation:", sorted(list(augmentations.keys()))
|
129 |
+
)
|
130 |
+
]
|
131 |
+
# in the professional mode you can choose several transforms
|
132 |
+
elif interface_type == "Professional":
|
133 |
+
transform_names = [
|
134 |
+
st.sidebar.selectbox(
|
135 |
+
"Select transformation β1:", sorted(list(augmentations.keys()))
|
136 |
+
)
|
137 |
+
]
|
138 |
+
while transform_names[-1] != "None":
|
139 |
+
transform_names.append(
|
140 |
+
st.sidebar.selectbox(
|
141 |
+
f"Select transformation β{len(transform_names) + 1}:",
|
142 |
+
["None"] + sorted(list(augmentations.keys())),
|
143 |
+
)
|
144 |
+
)
|
145 |
+
transform_names = transform_names[:-1]
|
146 |
+
return transform_names
|
147 |
+
|
148 |
+
|
149 |
+
def show_random_params(data: dict, interface_type: str = "Professional"):
|
150 |
+
"""Shows random params used for transformation (from A.ReplayCompose)"""
|
151 |
+
if interface_type == "Professional":
|
152 |
+
st.subheader("Random params used")
|
153 |
+
random_values = {}
|
154 |
+
for applied_params in data["replay"]["transforms"]:
|
155 |
+
random_values[
|
156 |
+
applied_params["__class_fullname__"].split(".")[-1]
|
157 |
+
] = applied_params["params"]
|
158 |
+
st.write(random_values)
|
src/visuals.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
import cv2
|
2 |
import streamlit as st
|
3 |
|
|
|
|
|
4 |
from control import param2func
|
5 |
from utils import get_images_list, load_image, upload_image
|
6 |
|
@@ -35,7 +37,7 @@ def select_image(path_to_images: str, interface_type: str = "Simple"):
|
|
35 |
if image_name != "Upload my image":
|
36 |
try:
|
37 |
image = load_image(image_name, path_to_images)
|
38 |
-
return
|
39 |
except cv2.error:
|
40 |
return 1, 0
|
41 |
else:
|
@@ -89,6 +91,16 @@ def show_credentials():
|
|
89 |
)
|
90 |
|
91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
def show_docstring(obj_with_ds):
|
93 |
st.markdown("* * *")
|
94 |
st.subheader("Docstring for " + obj_with_ds.__class__.__name__)
|
|
|
1 |
import cv2
|
2 |
import streamlit as st
|
3 |
|
4 |
+
import albumentations as A
|
5 |
+
|
6 |
from control import param2func
|
7 |
from utils import get_images_list, load_image, upload_image
|
8 |
|
|
|
37 |
if image_name != "Upload my image":
|
38 |
try:
|
39 |
image = load_image(image_name, path_to_images)
|
40 |
+
return 0, image
|
41 |
except cv2.error:
|
42 |
return 1, 0
|
43 |
else:
|
|
|
91 |
)
|
92 |
|
93 |
|
94 |
+
def get_transormations_params(transform_names: list, augmentations: dict) -> list:
|
95 |
+
transforms = []
|
96 |
+
for i, transform_name in enumerate(transform_names):
|
97 |
+
# select the params values
|
98 |
+
st.sidebar.subheader("Params of the " + transform_name)
|
99 |
+
param_values = show_transform_control(augmentations[transform_name], i)
|
100 |
+
transforms.append(getattr(A, transform_name)(**param_values))
|
101 |
+
return transforms
|
102 |
+
|
103 |
+
|
104 |
def show_docstring(obj_with_ds):
|
105 |
st.markdown("* * *")
|
106 |
st.subheader("Docstring for " + obj_with_ds.__class__.__name__)
|