IliaLarchenko commited on
Commit
dac9a79
1 Parent(s): ff50e43

added pytest

Browse files
Files changed (7) hide show
  1. run.sh +1 -1
  2. setup.py +5 -5
  3. src/app.py +0 -4
  4. src/utils.py +16 -16
  5. src/visuals.py +1 -1
  6. tests/test_app.py +0 -9
  7. tests/test_utils.py +41 -1
run.sh CHANGED
@@ -1 +1 @@
1
- streamlit run src/app.py
 
1
+ streamlit run src/app.py
setup.py CHANGED
@@ -4,19 +4,19 @@ with open("README.md", "r") as fh:
4
  long_description = fh.read()
5
 
6
  setuptools.setup(
7
- name="albumentations-demo", # Replace with your own username
8
  version="0.0.1",
9
  author="Ilya Larchenko",
10
  author_email="[email protected]",
11
- description="Service for demonstration of ",
12
  long_description=long_description,
13
  long_description_content_type="text/markdown",
14
- url="https://github.com/pypa/sampleproject",
15
  packages=setuptools.find_packages(),
16
  classifiers=[
17
  "Programming Language :: Python :: 3",
18
  "License :: OSI Approved :: MIT License",
19
  "Operating System :: OS Independent",
20
  ],
21
- python_requires='>=3.6',
22
- )
 
4
  long_description = fh.read()
5
 
6
  setuptools.setup(
7
+ name="albumentations-demo", # Replace with your own username
8
  version="0.0.1",
9
  author="Ilya Larchenko",
10
  author_email="[email protected]",
11
+ description="Service for demonstration of Albumentations",
12
  long_description=long_description,
13
  long_description_content_type="text/markdown",
14
+ url="https://github.com/IliaLarchenko/albumentations-demo",
15
  packages=setuptools.find_packages(),
16
  classifiers=[
17
  "Programming Language :: Python :: 3",
18
  "License :: OSI Approved :: MIT License",
19
  "Operating System :: OS Independent",
20
  ],
21
+ python_requires=">=3.6",
22
+ )
src/app.py CHANGED
@@ -39,10 +39,6 @@ param_values = show_transform_control(augmentations[transform_name])
39
  transform = getattr(A, transform_name)(**param_values)
40
  augmented_image = transform(image=image)["image"]
41
 
42
- # show the params passed
43
- # st.text("Params passed: ")
44
- # st.code(get_params_string(param_values))
45
- # st.text("Press R to update")
46
 
47
  # show the images
48
  width_original = 400
 
39
  transform = getattr(A, transform_name)(**param_values)
40
  augmented_image = transform(image=image)["image"]
41
 
 
 
 
 
42
 
43
  # show the images
44
  width_original = 400
src/utils.py CHANGED
@@ -5,6 +5,14 @@ import json
5
  import streamlit as st
6
 
7
 
 
 
 
 
 
 
 
 
8
  @st.cache
9
  def load_image(
10
  image_name: str, path_to_folder: str = "../images", bgr2rgb: bool = True
@@ -17,11 +25,14 @@ def load_image(
17
 
18
 
19
  @st.cache
20
- def get_images_list(path_to_folder: str) -> list:
21
- image_names_list = [
22
- x for x in os.listdir(path_to_folder) if x[-3:] in ["jpg", "peg", "png"]
23
- ]
24
- return image_names_list
 
 
 
25
 
26
 
27
  def fill_placeholders(params, placeholder_params):
@@ -45,17 +56,6 @@ def fill_placeholders(params, placeholder_params):
45
  return params
46
 
47
 
48
- @st.cache
49
- def load_augmentations_config(
50
- placeholder_params: dict, path_to_config: str = "configs/augmentations.json"
51
- ) -> dict:
52
- with open(path_to_config, "r") as config_file:
53
- augmentations = json.load(config_file)
54
- for name, params in augmentations.items():
55
- params = [fill_placeholders(param, placeholder_params) for param in params]
56
- return augmentations
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()]
 
5
  import streamlit as st
6
 
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
+ ]
13
+ return image_names_list
14
+
15
+
16
  @st.cache
17
  def load_image(
18
  image_name: str, path_to_folder: str = "../images", bgr2rgb: bool = True
 
25
 
26
 
27
  @st.cache
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():
34
+ params = [fill_placeholders(param, placeholder_params) for param in params]
35
+ return augmentations
36
 
37
 
38
  def fill_placeholders(params, placeholder_params):
 
56
  return 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()]
src/visuals.py CHANGED
@@ -15,7 +15,7 @@ def select_image(path_to_images: str = "images"):
15
  return image
16
 
17
 
18
- def show_transform_control(transform_params: dict):
19
  param_values = {"p": 1.0}
20
  if len(transform_params) == 0:
21
  st.sidebar.text("Transform has no parameters")
 
15
  return image
16
 
17
 
18
+ def show_transform_control(transform_params: dict) -> dict:
19
  param_values = {"p": 1.0}
20
  if len(transform_params) == 0:
21
  st.sidebar.text("Transform has no parameters")
tests/test_app.py DELETED
@@ -1,9 +0,0 @@
1
- # test
2
-
3
-
4
- def func(x):
5
- return x + 1
6
-
7
-
8
- def test_answer():
9
- assert func(3) == 4
 
 
 
 
 
 
 
 
 
 
tests/test_utils.py CHANGED
@@ -1,6 +1,9 @@
1
  # test
2
 
3
- from src.utils import get_images_list
 
 
 
4
 
5
 
6
  def test_get_images_list():
@@ -8,3 +11,40 @@ def test_get_images_list():
8
  assert isinstance(images_list, list)
9
  assert len(images_list) > 0
10
  assert isinstance(images_list[0], str)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # test
2
 
3
+ import numpy as np
4
+ import albumentations as A
5
+
6
+ from src.utils import get_images_list, load_image, load_augmentations_config
7
 
8
 
9
  def test_get_images_list():
 
11
  assert isinstance(images_list, list)
12
  assert len(images_list) > 0
13
  assert isinstance(images_list[0], str)
14
+
15
+
16
+ def test_load_image():
17
+ images_list = get_images_list("images")
18
+ for image_name in images_list:
19
+ image = load_image(image_name, path_to_folder="images", bgr2rgb=True)
20
+ assert len(image.shape) == 3, f"error in {image_name}"
21
+ assert image.shape[2] == 3, f"error in {image_name}"
22
+ assert image.max() <= 255, f"error in {image_name}"
23
+ assert image.min() >= 0, f"error in {image_name}"
24
+
25
+
26
+ def test_load_augmentations_config():
27
+ image = np.random.randint(0, 255, (100, 100, 3)).astype(np.uint8)
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
+ augmentations = load_augmentations_config(
35
+ placeholder_params, path_to_config="configs/augmentations.json"
36
+ )
37
+
38
+ for transform_name in augmentations.keys():
39
+ if transform_name in ["CenterCrop", "RandomCrop"]:
40
+ param_values = {"p": 1.0, "height": 10, "width": 10}
41
+ elif transform_name in ["Crop"]:
42
+ param_values = {"p": 1.0, "x_max": 10, "y_max": 10}
43
+ else:
44
+ param_values = {"p": 1.0}
45
+ transform = getattr(A, transform_name)(**param_values)
46
+ transformed_image = transform(image=image)["image"]
47
+ assert len(transformed_image.shape) == 3, f"error in {str(transform)}"
48
+ assert transformed_image.shape[2] == 3, f"error in {str(transform)}"
49
+ assert transformed_image.max() <= 255, f"error in {str(transform)}"
50
+ assert transformed_image.min() >= 0, f"error in {str(transform)}"