Commit
•
6e7a74d
1
Parent(s):
d5465e6
refactoring
Browse files- src/main.py +13 -39
- src/visuals.py +37 -0
src/main.py
CHANGED
@@ -3,72 +3,46 @@ import albumentations as A
|
|
3 |
|
4 |
from control import *
|
5 |
from utils import (
|
6 |
-
load_image,
|
7 |
-
get_images_list,
|
8 |
load_augmentations_config,
|
9 |
generate_executable_string,
|
10 |
)
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
return image
|
18 |
-
|
19 |
-
|
20 |
-
def show_transform_control(transform_params: dict):
|
21 |
-
param_values = {}
|
22 |
-
if len(transform_params) == 0:
|
23 |
-
st.sidebar.text(transform_name + " transform has no parameters")
|
24 |
-
else:
|
25 |
-
for param in transform_params:
|
26 |
-
param_values[param["param_name"]] = param2func[param["type"]](**param)
|
27 |
-
return param_values
|
28 |
-
|
29 |
-
|
30 |
-
def show_credentials():
|
31 |
-
st.text("")
|
32 |
-
st.text("")
|
33 |
-
st.subheader("Credentials:")
|
34 |
-
st.text("Source: https://github.com/IliaLarchenko/albumentations-demo")
|
35 |
-
st.text(
|
36 |
-
"Albumentations library: https://github.com/albumentations-team/albumentations"
|
37 |
-
)
|
38 |
-
st.text("Image Source: https://www.pexels.com/royalty-free-images/")
|
39 |
-
|
40 |
-
|
41 |
-
def show_docstring(object):
|
42 |
-
st.subheader("Docstring:")
|
43 |
-
st.text(str(object.__doc__))
|
44 |
|
45 |
|
46 |
# main
|
47 |
st.title("Demo of Albumentations transforms")
|
48 |
-
|
49 |
-
# selecting an image
|
50 |
image = select_image(path_to_images="images")
|
51 |
|
52 |
# load the config
|
53 |
augmentations = load_augmentations_config("configs/augmentations.json")
|
|
|
|
|
54 |
transform_name = st.sidebar.selectbox(
|
55 |
"Select a transformation:", sorted(list(augmentations.keys()))
|
56 |
)
|
57 |
|
58 |
# select the params values
|
59 |
param_values = show_transform_control(augmentations[transform_name])
|
60 |
-
executable_string = generate_executable_string(transform_name, param_values)
|
61 |
|
|
|
|
|
62 |
st.text(executable_string)
|
63 |
-
st.text("Press R to update")
|
64 |
exec("transform = A." + executable_string)
|
65 |
augmented_image = transform(image=image)["image"]
|
66 |
|
|
|
|
|
67 |
st.image(
|
68 |
[image, augmented_image],
|
69 |
caption=["Original image", "Transformed image"],
|
70 |
width=320,
|
71 |
)
|
72 |
|
|
|
73 |
show_docstring(transform)
|
74 |
show_credentials()
|
|
|
3 |
|
4 |
from control import *
|
5 |
from utils import (
|
|
|
|
|
6 |
load_augmentations_config,
|
7 |
generate_executable_string,
|
8 |
)
|
9 |
+
from visuals import (
|
10 |
+
show_transform_control,
|
11 |
+
select_image,
|
12 |
+
show_credentials,
|
13 |
+
show_docstring,
|
14 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
|
17 |
# main
|
18 |
st.title("Demo of Albumentations transforms")
|
|
|
|
|
19 |
image = select_image(path_to_images="images")
|
20 |
|
21 |
# load the config
|
22 |
augmentations = load_augmentations_config("configs/augmentations.json")
|
23 |
+
|
24 |
+
# select a transformation
|
25 |
transform_name = st.sidebar.selectbox(
|
26 |
"Select a transformation:", sorted(list(augmentations.keys()))
|
27 |
)
|
28 |
|
29 |
# select the params values
|
30 |
param_values = show_transform_control(augmentations[transform_name])
|
|
|
31 |
|
32 |
+
# apply the transformation to the image
|
33 |
+
executable_string = generate_executable_string(transform_name, param_values)
|
34 |
st.text(executable_string)
|
|
|
35 |
exec("transform = A." + executable_string)
|
36 |
augmented_image = transform(image=image)["image"]
|
37 |
|
38 |
+
# show the images
|
39 |
+
st.text("Press R to update")
|
40 |
st.image(
|
41 |
[image, augmented_image],
|
42 |
caption=["Original image", "Transformed image"],
|
43 |
width=320,
|
44 |
)
|
45 |
|
46 |
+
# print additional info
|
47 |
show_docstring(transform)
|
48 |
show_credentials()
|
src/visuals.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
from control import param2func
|
4 |
+
from utils import get_images_list, load_image
|
5 |
+
|
6 |
+
|
7 |
+
def select_image(path_to_images: str = "images"):
|
8 |
+
image_names_list = get_images_list(path_to_images)
|
9 |
+
image_name = st.sidebar.selectbox("Select an image:", image_names_list)
|
10 |
+
image = load_image(image_name, path_to_images)
|
11 |
+
return image
|
12 |
+
|
13 |
+
|
14 |
+
def show_transform_control(transform_params: dict):
|
15 |
+
param_values = {}
|
16 |
+
if len(transform_params) == 0:
|
17 |
+
st.sidebar.text(transform_name + " transform has no parameters")
|
18 |
+
else:
|
19 |
+
for param in transform_params:
|
20 |
+
param_values[param["param_name"]] = param2func[param["type"]](**param)
|
21 |
+
return param_values
|
22 |
+
|
23 |
+
|
24 |
+
def show_credentials():
|
25 |
+
st.text("")
|
26 |
+
st.text("")
|
27 |
+
st.subheader("Credentials:")
|
28 |
+
st.text("Source: https://github.com/IliaLarchenko/albumentations-demo")
|
29 |
+
st.text(
|
30 |
+
"Albumentations library: https://github.com/albumentations-team/albumentations"
|
31 |
+
)
|
32 |
+
st.text("Image Source: https://www.pexels.com/royalty-free-images/")
|
33 |
+
|
34 |
+
|
35 |
+
def show_docstring(object):
|
36 |
+
st.subheader("Docstring:")
|
37 |
+
st.text(str(object.__doc__))
|