File size: 1,854 Bytes
d5465e6 b30ce1c d5465e6 b30ce1c d5465e6 b30ce1c d5465e6 52a0611 d5465e6 b30ce1c 52a0611 b30ce1c d5465e6 52a0611 d5465e6 b30ce1c d5465e6 cc797bf d5465e6 b30ce1c |
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 |
import cv2
import os
import json
import streamlit as st
@st.cache
def load_image(
image_name: str, path_to_folder: str = "../images", bgr2rgb: bool = True
):
path_to_image = os.path.join(path_to_folder, image_name)
image = cv2.imread(path_to_image,)
if bgr2rgb:
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
return image
@st.cache
def get_images_list(path_to_folder: str) -> list:
image_names_list = [
x for x in os.listdir(path_to_folder) if x[-3:] in ["jpg", "peg", "png"]
]
return image_names_list
def fill_placeholders(params, placeholder_params):
# TODO: refactor
if "placeholder" in params:
placeholder_dict = params["placeholder"]
for k, v in placeholder_dict.items():
if isinstance(v, list):
params[k] = []
for element in v:
if element in placeholder_params:
params[k].append(placeholder_params[element])
else:
params[k].append(element)
else:
if v in placeholder_params:
params[k] = placeholder_params[v]
else:
params[k] = v
params.pop("placeholder")
return params
@st.cache
def load_augmentations_config(
placeholder_params: dict, path_to_config: str = "configs/augmentations.json"
) -> dict:
with open(path_to_config, "r") as config_file:
augmentations = json.load(config_file)
for name, params in augmentations.items():
params = [fill_placeholders(param, placeholder_params) for param in params]
return augmentations
def get_params_string(param_values: dict) -> str:
params_string = ", ".join(
[k + "=" + str(param_values[k]) for k in param_values.keys()]
)
return params_string
|