IliaLarchenko commited on
Commit
6684d9c
1 Parent(s): dac9a79

added comments

Browse files
Files changed (2) hide show
  1. src/control.py +2 -2
  2. src/utils.py +25 -1
src/control.py CHANGED
@@ -1,9 +1,9 @@
1
  import streamlit as st
2
 
3
- # TODO: rename everything
4
 
5
 
6
- def select_int_interval(param_name, limits_list, defaults, **kwargs):
7
  st.sidebar.subheader(param_name)
8
  min_max_interval = st.sidebar.slider(
9
  "", limits_list[0], limits_list[1], defaults, key=hash(param_name)
 
1
  import streamlit as st
2
 
3
+ # TODO: rename and refactor everything
4
 
5
 
6
+ def select_int_interval(param_name: str, limits_list: list, defaults, **kwargs):
7
  st.sidebar.subheader(param_name)
8
  min_max_interval = st.sidebar.slider(
9
  "", limits_list[0], limits_list[1], defaults, key=hash(param_name)
src/utils.py CHANGED
@@ -7,6 +7,10 @@ import streamlit as st
7
 
8
  @st.cache
9
  def get_images_list(path_to_folder: str) -> list:
 
 
 
 
10
  image_names_list = [
11
  x for x in os.listdir(path_to_folder) if x[-3:] in ["jpg", "peg", "png"]
12
  ]
@@ -17,6 +21,12 @@ def get_images_list(path_to_folder: str) -> list:
17
  def load_image(
18
  image_name: str, path_to_folder: str = "../images", bgr2rgb: bool = True
19
  ):
 
 
 
 
 
 
20
  path_to_image = os.path.join(path_to_folder, image_name)
21
  image = cv2.imread(path_to_image)
22
  if bgr2rgb:
@@ -28,6 +38,11 @@ def load_image(
28
  def load_augmentations_config(
29
  placeholder_params: dict, path_to_config: str = "configs/augmentations.json"
30
  ) -> dict:
 
 
 
 
 
31
  with open(path_to_config, "r") as config_file:
32
  augmentations = json.load(config_file)
33
  for name, params in augmentations.items():
@@ -35,7 +50,12 @@ def load_augmentations_config(
35
  return augmentations
36
 
37
 
38
- def fill_placeholders(params, placeholder_params):
 
 
 
 
 
39
  # TODO: refactor
40
  if "placeholder" in params:
41
  placeholder_dict = params["placeholder"]
@@ -57,6 +77,10 @@ def fill_placeholders(params, placeholder_params):
57
 
58
 
59
  def get_params_string(param_values: dict) -> str:
 
 
 
 
60
  params_string = ", ".join(
61
  [k + "=" + str(param_values[k]) for k in param_values.keys()]
62
  )
 
7
 
8
  @st.cache
9
  def get_images_list(path_to_folder: str) -> list:
10
+ """Return the list of images from folder
11
+ Args:
12
+ path_to_folder (str): absolute or relative path to the folder with images
13
+ """
14
  image_names_list = [
15
  x for x in os.listdir(path_to_folder) if x[-3:] in ["jpg", "peg", "png"]
16
  ]
 
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
27
+ path_to_folder (str): path to the folder with image
28
+ bgr2rgb (bool): converts BGR image to RGB if True
29
+ """
30
  path_to_image = os.path.join(path_to_folder, image_name)
31
  image = cv2.imread(path_to_image)
32
  if bgr2rgb:
 
38
  def load_augmentations_config(
39
  placeholder_params: dict, path_to_config: str = "configs/augmentations.json"
40
  ) -> dict:
41
+ """Load the json config with params of all transforms
42
+ Args:
43
+ placeholder_params (dict): dict with values of placeholders
44
+ path_to_config (str): path to the json config file
45
+ """
46
  with open(path_to_config, "r") as config_file:
47
  augmentations = json.load(config_file)
48
  for name, params in augmentations.items():
 
50
  return augmentations
51
 
52
 
53
+ def fill_placeholders(params: dict, placeholder_params: dict) -> dict:
54
+ """Fill the placeholder values in the config file
55
+ Args:
56
+ params (dict): original params dict with placeholders
57
+ placeholder_params (dict): dict with values of placeholders
58
+ """
59
  # TODO: refactor
60
  if "placeholder" in params:
61
  placeholder_dict = params["placeholder"]
 
77
 
78
 
79
  def get_params_string(param_values: dict) -> str:
80
+ """Generate the string from the dict with parameters
81
+ Args:
82
+ param_values (dict): dict of "param_name" -> "param_value"
83
+ """
84
  params_string = ", ".join(
85
  [k + "=" + str(param_values[k]) for k in param_values.keys()]
86
  )