Commit
·
96a96d9
1
Parent(s):
2403575
added the optional path to the images folder
Browse files- README.md +6 -1
- configs/augmentations.json +53 -50
- src/app.py +52 -41
- src/utils.py +10 -3
- src/visuals.py +11 -4
README.md
CHANGED
|
@@ -16,6 +16,11 @@ pip install -r requirements.txt
|
|
| 16 |
streamlit run src/app.py
|
| 17 |
```
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
In your terminal you will see the link to the running local service similar to :
|
| 20 |
```console
|
| 21 |
You can now view your Streamlit app in your browser.
|
|
@@ -39,4 +44,4 @@ The interface is very simple and intuitive:
|
|
| 39 |
## Links
|
| 40 |
* Albumentations library: [github.com/albumentations-team/albumentations](https://github.com/albumentations-team/albumentations)
|
| 41 |
* Image Source: [pexels.com/royalty-free-images](https://pexels.com/royalty-free-images/)
|
| 42 |
-
* Streamlit - framework powering this app [github.com/streamlit/streamlit](https://github.com/streamlit/streamlit)
|
|
|
|
| 16 |
streamlit run src/app.py
|
| 17 |
```
|
| 18 |
|
| 19 |
+
If you want to work with you own images just replace the last line with:
|
| 20 |
+
```
|
| 21 |
+
streamlit run src/app.py -- --images_folder PATH_TO_YOUR_IMAGE_FOLDER
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
In your terminal you will see the link to the running local service similar to :
|
| 25 |
```console
|
| 26 |
You can now view your Streamlit app in your browser.
|
|
|
|
| 44 |
## Links
|
| 45 |
* Albumentations library: [github.com/albumentations-team/albumentations](https://github.com/albumentations-team/albumentations)
|
| 46 |
* Image Source: [pexels.com/royalty-free-images](https://pexels.com/royalty-free-images/)
|
| 47 |
+
* Streamlit - framework powering this app [github.com/streamlit/streamlit](https://github.com/streamlit/streamlit)
|
configs/augmentations.json
CHANGED
|
@@ -507,6 +507,58 @@
|
|
| 507 |
"type": "checkbox"
|
| 508 |
}
|
| 509 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 510 |
"Posterize": [
|
| 511 |
{
|
| 512 |
"defaults_list": [
|
|
@@ -1109,54 +1161,5 @@
|
|
| 1109 |
"ToGray": [],
|
| 1110 |
"ToSepia": [],
|
| 1111 |
"Transpose": [],
|
| 1112 |
-
"VerticalFlip": []
|
| 1113 |
-
|
| 1114 |
-
|
| 1115 |
-
"OpticalDistortion": [
|
| 1116 |
-
{
|
| 1117 |
-
"defaults": [
|
| 1118 |
-
-0.3,
|
| 1119 |
-
0.3
|
| 1120 |
-
],
|
| 1121 |
-
"limits_list": [
|
| 1122 |
-
-2.0,
|
| 1123 |
-
2.0
|
| 1124 |
-
],
|
| 1125 |
-
"param_name": "distort_limit",
|
| 1126 |
-
"type": "num_interval"
|
| 1127 |
-
}, {
|
| 1128 |
-
"defaults": [-0.05, 0.05],
|
| 1129 |
-
"limits_list": [
|
| 1130 |
-
-1.0,
|
| 1131 |
-
1.0
|
| 1132 |
-
],
|
| 1133 |
-
"param_name": "shift_limit",
|
| 1134 |
-
"type": "num_interval"
|
| 1135 |
-
},
|
| 1136 |
-
{
|
| 1137 |
-
"options_list": [
|
| 1138 |
-
0,
|
| 1139 |
-
1,
|
| 1140 |
-
2,
|
| 1141 |
-
3,
|
| 1142 |
-
4
|
| 1143 |
-
],
|
| 1144 |
-
"param_name": "interpolation",
|
| 1145 |
-
"type": "radio"
|
| 1146 |
-
},
|
| 1147 |
-
{
|
| 1148 |
-
"options_list": [
|
| 1149 |
-
0,
|
| 1150 |
-
1,
|
| 1151 |
-
2,
|
| 1152 |
-
3,
|
| 1153 |
-
4
|
| 1154 |
-
],
|
| 1155 |
-
"param_name": "border_mode",
|
| 1156 |
-
"type": "radio"
|
| 1157 |
-
},
|
| 1158 |
-
{
|
| 1159 |
-
"param_name": "value",
|
| 1160 |
-
"type": "rgb"
|
| 1161 |
-
}]
|
| 1162 |
}
|
|
|
|
| 507 |
"type": "checkbox"
|
| 508 |
}
|
| 509 |
],
|
| 510 |
+
"OpticalDistortion": [
|
| 511 |
+
{
|
| 512 |
+
"defaults": [
|
| 513 |
+
-0.3,
|
| 514 |
+
0.3
|
| 515 |
+
],
|
| 516 |
+
"limits_list": [
|
| 517 |
+
-2.0,
|
| 518 |
+
2.0
|
| 519 |
+
],
|
| 520 |
+
"param_name": "distort_limit",
|
| 521 |
+
"type": "num_interval"
|
| 522 |
+
},
|
| 523 |
+
{
|
| 524 |
+
"defaults": [
|
| 525 |
+
-0.05,
|
| 526 |
+
0.05
|
| 527 |
+
],
|
| 528 |
+
"limits_list": [
|
| 529 |
+
-1.0,
|
| 530 |
+
1.0
|
| 531 |
+
],
|
| 532 |
+
"param_name": "shift_limit",
|
| 533 |
+
"type": "num_interval"
|
| 534 |
+
},
|
| 535 |
+
{
|
| 536 |
+
"options_list": [
|
| 537 |
+
0,
|
| 538 |
+
1,
|
| 539 |
+
2,
|
| 540 |
+
3,
|
| 541 |
+
4
|
| 542 |
+
],
|
| 543 |
+
"param_name": "interpolation",
|
| 544 |
+
"type": "radio"
|
| 545 |
+
},
|
| 546 |
+
{
|
| 547 |
+
"options_list": [
|
| 548 |
+
0,
|
| 549 |
+
1,
|
| 550 |
+
2,
|
| 551 |
+
3,
|
| 552 |
+
4
|
| 553 |
+
],
|
| 554 |
+
"param_name": "border_mode",
|
| 555 |
+
"type": "radio"
|
| 556 |
+
},
|
| 557 |
+
{
|
| 558 |
+
"param_name": "value",
|
| 559 |
+
"type": "rgb"
|
| 560 |
+
}
|
| 561 |
+
],
|
| 562 |
"Posterize": [
|
| 563 |
{
|
| 564 |
"defaults_list": [
|
|
|
|
| 1161 |
"ToGray": [],
|
| 1162 |
"ToSepia": [],
|
| 1163 |
"Transpose": [],
|
| 1164 |
+
"VerticalFlip": []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1165 |
}
|
src/app.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import albumentations as A
|
| 3 |
|
| 4 |
-
|
|
|
|
| 5 |
from visuals import (
|
| 6 |
show_transform_control,
|
| 7 |
select_image,
|
|
@@ -9,53 +11,62 @@ from visuals import (
|
|
| 9 |
show_docstring,
|
| 10 |
)
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
st.title("Demo of Albumentations")
|
| 15 |
-
|
| 16 |
-
# select image
|
| 17 |
-
image = select_image(path_to_images="images")
|
| 18 |
-
placeholder_params = {
|
| 19 |
-
"image_width": image.shape[1],
|
| 20 |
-
"image_height": image.shape[0],
|
| 21 |
-
"image_half_width": int(image.shape[1] / 2),
|
| 22 |
-
"image_half_height": int(image.shape[0] / 2),
|
| 23 |
-
}
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
)
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
)
|
| 34 |
|
| 35 |
-
# select
|
| 36 |
-
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
#
|
| 39 |
-
|
| 40 |
-
data = A.ReplayCompose([transform])(image=image)
|
| 41 |
-
augmented_image = data["image"]
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
# st.write(applied_params)
|
| 48 |
-
# st.write(data["replay"])
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
# show the images
|
| 52 |
-
width_original = 400
|
| 53 |
-
width_transformed = int(
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
st.image(image, caption="Original image", width=width_original)
|
| 56 |
-
st.image(augmented_image, caption="Transformed image", width=width_transformed)
|
| 57 |
|
| 58 |
-
# print additional info
|
| 59 |
-
st.code(str(transform))
|
| 60 |
-
show_docstring(transform)
|
| 61 |
-
show_credentials()
|
|
|
|
| 1 |
+
import os
|
| 2 |
import streamlit as st
|
| 3 |
import albumentations as A
|
| 4 |
|
| 5 |
+
|
| 6 |
+
from utils import load_augmentations_config, get_path_to_the_image
|
| 7 |
from visuals import (
|
| 8 |
show_transform_control,
|
| 9 |
select_image,
|
|
|
|
| 11 |
show_docstring,
|
| 12 |
)
|
| 13 |
|
| 14 |
+
# get the path to images
|
| 15 |
+
path_to_images = get_path_to_the_image()
|
| 16 |
+
if not os.path.isdir(path_to_images):
|
| 17 |
+
st.title("There is no directory: " + path_to_images)
|
| 18 |
+
else:
|
| 19 |
+
status, image = select_image(path_to_images)
|
| 20 |
+
if status == 0:
|
| 21 |
+
st.title("Can't load image from: " + path_to_images)
|
| 22 |
+
else:
|
| 23 |
+
# show title
|
| 24 |
+
st.title("Demo of Albumentations")
|
| 25 |
|
| 26 |
+
# select image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
placeholder_params = {
|
| 29 |
+
"image_width": image.shape[1],
|
| 30 |
+
"image_height": image.shape[0],
|
| 31 |
+
"image_half_width": int(image.shape[1] / 2),
|
| 32 |
+
"image_half_height": int(image.shape[0] / 2),
|
| 33 |
+
}
|
| 34 |
|
| 35 |
+
# load the config
|
| 36 |
+
augmentations = load_augmentations_config(
|
| 37 |
+
placeholder_params, "configs/augmentations.json"
|
| 38 |
+
)
|
| 39 |
|
| 40 |
+
# select a transformation
|
| 41 |
+
transform_name = st.sidebar.selectbox(
|
| 42 |
+
"Select a transformation:", sorted(list(augmentations.keys()))
|
| 43 |
+
)
|
| 44 |
|
| 45 |
+
# select the params values
|
| 46 |
+
param_values = show_transform_control(augmentations[transform_name])
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
# apply the transformation to the image
|
| 49 |
+
transform = getattr(A, transform_name)(**param_values)
|
| 50 |
+
data = A.ReplayCompose([transform])(image=image)
|
| 51 |
+
augmented_image = data["image"]
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
# TODO add convinient replay compose
|
| 54 |
+
# applied_params = data["replay"]["transforms"][0]['params']
|
| 55 |
+
# for k,v in applied_params.items():
|
| 56 |
+
# applied_params[k] = str(v)
|
| 57 |
+
# st.write(applied_params)
|
| 58 |
+
# st.write(data["replay"])
|
| 59 |
|
| 60 |
+
# show the images
|
| 61 |
+
width_original = 400
|
| 62 |
+
width_transformed = int(
|
| 63 |
+
width_original / image.shape[1] * augmented_image.shape[1]
|
| 64 |
+
)
|
| 65 |
|
| 66 |
+
st.image(image, caption="Original image", width=width_original)
|
| 67 |
+
st.image(augmented_image, caption="Transformed image", width=width_transformed)
|
| 68 |
|
| 69 |
+
# print additional info
|
| 70 |
+
st.code(str(transform))
|
| 71 |
+
show_docstring(transform)
|
| 72 |
+
show_credentials()
|
src/utils.py
CHANGED
|
@@ -1,10 +1,19 @@
|
|
| 1 |
import cv2
|
| 2 |
import os
|
| 3 |
import json
|
|
|
|
| 4 |
|
| 5 |
import streamlit as st
|
| 6 |
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
@st.cache
|
| 9 |
def get_images_list(path_to_folder: str) -> list:
|
| 10 |
"""Return the list of images from folder
|
|
@@ -18,9 +27,7 @@ def get_images_list(path_to_folder: str) -> list:
|
|
| 18 |
|
| 19 |
|
| 20 |
@st.cache
|
| 21 |
-
def load_image(
|
| 22 |
-
image_name: str, path_to_folder: str = "../images", bgr2rgb: bool = True
|
| 23 |
-
):
|
| 24 |
"""Load the image
|
| 25 |
Args:
|
| 26 |
image_name (str): name of the image
|
|
|
|
| 1 |
import cv2
|
| 2 |
import os
|
| 3 |
import json
|
| 4 |
+
import argparse
|
| 5 |
|
| 6 |
import streamlit as st
|
| 7 |
|
| 8 |
|
| 9 |
+
@st.cache
|
| 10 |
+
def get_path_to_the_image():
|
| 11 |
+
parser = argparse.ArgumentParser()
|
| 12 |
+
parser.add_argument("--images_folder", default="images")
|
| 13 |
+
args = parser.parse_args()
|
| 14 |
+
return getattr(args, "images_folder")
|
| 15 |
+
|
| 16 |
+
|
| 17 |
@st.cache
|
| 18 |
def get_images_list(path_to_folder: str) -> list:
|
| 19 |
"""Return the list of images from folder
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
@st.cache
|
| 30 |
+
def load_image(image_name: str, path_to_folder: str, bgr2rgb: bool = True):
|
|
|
|
|
|
|
| 31 |
"""Load the image
|
| 32 |
Args:
|
| 33 |
image_name (str): name of the image
|
src/visuals.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
from control import param2func
|
|
@@ -8,11 +9,17 @@ def show_logo():
|
|
| 8 |
st.image(load_image("logo.png", "../images"), format="PNG")
|
| 9 |
|
| 10 |
|
| 11 |
-
def select_image(path_to_images: str
|
| 12 |
image_names_list = get_images_list(path_to_images)
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
def show_transform_control(transform_params: dict) -> dict:
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
import streamlit as st
|
| 3 |
|
| 4 |
from control import param2func
|
|
|
|
| 9 |
st.image(load_image("logo.png", "../images"), format="PNG")
|
| 10 |
|
| 11 |
|
| 12 |
+
def select_image(path_to_images: str):
|
| 13 |
image_names_list = get_images_list(path_to_images)
|
| 14 |
+
if len(image_names_list) < 1:
|
| 15 |
+
return 0, 0
|
| 16 |
+
else:
|
| 17 |
+
try:
|
| 18 |
+
image_name = st.sidebar.selectbox("Select an image:", image_names_list)
|
| 19 |
+
image = load_image(image_name, path_to_images)
|
| 20 |
+
return 1, image
|
| 21 |
+
except cv2.error:
|
| 22 |
+
return 0, 0
|
| 23 |
|
| 24 |
|
| 25 |
def show_transform_control(transform_params: dict) -> dict:
|