IliaLarchenko commited on
Commit
6e61d26
1 Parent(s): 4fe3025

formatting

Browse files
Files changed (3) hide show
  1. configs/augmentations.json +424 -168
  2. src/control.py +27 -18
  3. src/main.py +36 -27
configs/augmentations.json CHANGED
@@ -1,170 +1,426 @@
1
  {
2
- "ToGray": [],
3
- "ToSepia": [],
4
- "ChannelShuffle": [],
5
- "InvertImg": [],
6
- "VerticalFlip": [],
7
- "HorizontalFlip": [],
8
- "Flip": [],
9
- "RandomGridShuffle": [
10
- {"param_name" : "grid",
11
- "type" : "several_ints",
12
- "subparam_names": ["y", "x"],
13
- "limits_list" : [[1, 10],[1, 10]],
14
- "defaults_list" : [3, 3]}
15
- ],
16
- "Blur": [{"param_name" : "blur_limit",
17
- "type" : "int_interval",
18
- "limits_list" : [3, 100],
19
- "defaults" : [3, 7]}
20
- ],
21
- "MotionBlur": [{"param_name" : "blur_limit",
22
- "type" : "int_interval",
23
- "limits_list" : [3, 100],
24
- "defaults" : [3, 7]}
25
- ],
26
- "MedianBlur": [{"param_name" : "blur_limit",
27
- "type" : "int_interval",
28
- "limits_list" : [3, 100],
29
- "defaults" : [3, 7]}
30
- ],
31
- "GaussNoise": [{"param_name" : "var_limit",
32
- "type" : "int_interval",
33
- "limits_list" : [0.0, 500.0],
34
- "defaults" : [10.0, 50.0]},
35
- {"param_name" : "mean",
36
- "type" : "int_interval",
37
- "limits_list" : [-100.0, 100.0],
38
- "defaults" : 0.0}
39
- ],
40
- "RandomBrightness": [{"param_name" : "limit",
41
- "type" : "int_interval",
42
- "limits_list" : [-1.0, 1.0],
43
- "defaults" : [-0.2, 0.2]}
44
- ],
45
- "RandomContrast": [{"param_name" : "limit",
46
- "type" : "int_interval",
47
- "limits_list" : [-1.0, 1.0],
48
- "defaults" : [-0.2, 0.2]}
49
- ],
50
- "HueSaturationValue": [{ "param_name" : "hue_shift_limit",
51
- "type" : "int_interval",
52
- "limits_list" : [-100, 100],
53
- "defaults" : [-20, 20]},
54
- { "param_name" : "sat_shift_limit",
55
- "type" : "int_interval",
56
- "limits_list" : [-100, 100],
57
- "defaults" : [-30, 30]},
58
- { "param_name" : "val_shift_limit",
59
- "type" : "int_interval",
60
- "limits_list" : [-100, 100],
61
- "defaults" : [-20, 20]}
62
- ],
63
- "RGBShift": [{ "param_name" : "r_shift_limit",
64
- "type" : "int_interval",
65
- "limits_list" : [-255, 255],
66
- "defaults" : [-20, 20]},
67
- { "param_name" : "g_shift_limit",
68
- "type" : "int_interval",
69
- "limits_list" : [-255, 255],
70
- "defaults" : [-20, 20]},
71
- { "param_name" : "b_shift_limit",
72
- "type" : "int_interval",
73
- "limits_list" : [-255, 255],
74
- "defaults" : [-20, 20]}
75
- ],
76
- "JpegCompression": [{"param_name" : "quality_lower",
77
- "type" : "int_interval",
78
- "limits_list" : [0, 100],
79
- "defaults" : 99},
80
- {"param_name" : "quality_upper",
81
- "type" : "int_interval",
82
- "limits_list" : [0, 100],
83
- "defaults" : 100}
84
- ],
85
- "ImageCompression": [{"param_name" : "quality_lower",
86
- "type" : "int_interval",
87
- "limits_list" : [0, 100],
88
- "defaults" : 99},
89
- {"param_name" : "quality_upper",
90
- "type" : "int_interval",
91
- "limits_list" : [0, 100],
92
- "defaults" : 100},
93
- {"param_name" : "compression_type",
94
- "type" : "radio",
95
- "options_list" : [0, 1]}
96
- ],
97
- "CLAHE": [{"param_name" : "clip_limit",
98
- "type" : "int_interval",
99
- "limits_list" : [1, 100],
100
- "defaults" : [1, 4]},
101
- {"param_name" : "tile_grid_size",
102
- "type" : "several_ints",
103
- "subparam_names": ["y", "x"],
104
- "limits_list" : [[1, 100],[1, 100]],
105
- "defaults_list" : [8, 8]}
106
- ],
107
- "Cutout": [{"param_name" : "num_holes",
108
- "type" : "int_interval",
109
- "limits_list" : [1, 100],
110
- "defaults" : 8},
111
- {"param_name" : "max_h_size",
112
- "type" : "int_interval",
113
- "limits_list" : [1, 100],
114
- "defaults" : 8},
115
- {"param_name" : "max_w_size",
116
- "type" : "int_interval",
117
- "limits_list" : [1, 100],
118
- "defaults" : 8},
119
- {"param_name" : "fill_value",
120
- "type" : "rgb"}
121
- ],
122
- "RandomSnow": [{"param_name" : "snow_point_lower",
123
- "type" : "int_interval",
124
- "limits_list" : [0.0, 1.0],
125
- "defaults" : 0.1},
126
- {"param_name" : "snow_point_upper",
127
- "type" : "int_interval",
128
- "limits_list" : [0.0, 1.0],
129
- "defaults" : 0.1},
130
- {"param_name" : "brightness_coeff",
131
- "type" : "int_interval",
132
- "limits_list" : [0.0, 20.0],
133
- "defaults" : 2.5}
134
- ],
135
- "RandomFog": [{"param_name" : "fog_coef_lower",
136
- "type" : "int_interval",
137
- "limits_list" : [0.0, 1.0],
138
- "defaults" : 0.1},
139
- {"param_name" : "fog_coef_upper",
140
- "type" : "int_interval",
141
- "limits_list" : [0.0, 1.0],
142
- "defaults" : 0.1},
143
- {"param_name" : "alpha_coef",
144
- "type" : "int_interval",
145
- "limits_list" : [0.0, 1.0],
146
- "defaults" : 0.08}
147
- ],
148
- "ChannelDropout": [{"param_name" : "channel_drop_range",
149
- "type" : "int_interval",
150
- "limits_list" : [1, 3],
151
- "defaults" : [1, 1]},
152
- {"param_name" : "fill_value",
153
- "type" : "int_interval",
154
- "limits_list" : [0, 255],
155
- "defaults" : 0}
156
- ],
157
- "Solarize": [{"param_name" : "threshold",
158
- "type" : "int_interval",
159
- "limits_list" : [0, 255],
160
- "defaults" : 128}
161
- ],
162
- "Equalize": [
163
- {"param_name" : "mode",
164
- "type" : "radio",
165
- "options_list" : ["cv", "pil"]},
166
- {"param_name" : "by_channels",
167
- "type" : "checkbox",
168
- "defaults": 1}
169
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  }
 
1
  {
2
+ "ToGray": [],
3
+ "ToSepia": [],
4
+ "ChannelShuffle": [],
5
+ "InvertImg": [],
6
+ "VerticalFlip": [],
7
+ "HorizontalFlip": [],
8
+ "Flip": [],
9
+ "RandomGridShuffle": [
10
+ {
11
+ "param_name": "grid",
12
+ "type": "several_ints",
13
+ "subparam_names": [
14
+ "y",
15
+ "x"
16
+ ],
17
+ "limits_list": [
18
+ [
19
+ 1,
20
+ 10
21
+ ],
22
+ [
23
+ 1,
24
+ 10
25
+ ]
26
+ ],
27
+ "defaults_list": [
28
+ 3,
29
+ 3
30
+ ]
31
+ }
32
+ ],
33
+ "Blur": [
34
+ {
35
+ "param_name": "blur_limit",
36
+ "type": "int_interval",
37
+ "limits_list": [
38
+ 3,
39
+ 100
40
+ ],
41
+ "defaults": [
42
+ 3,
43
+ 7
44
+ ]
45
+ }
46
+ ],
47
+ "MotionBlur": [
48
+ {
49
+ "param_name": "blur_limit",
50
+ "type": "int_interval",
51
+ "limits_list": [
52
+ 3,
53
+ 100
54
+ ],
55
+ "defaults": [
56
+ 3,
57
+ 7
58
+ ]
59
+ }
60
+ ],
61
+ "MedianBlur": [
62
+ {
63
+ "param_name": "blur_limit",
64
+ "type": "int_interval",
65
+ "limits_list": [
66
+ 3,
67
+ 100
68
+ ],
69
+ "defaults": [
70
+ 3,
71
+ 7
72
+ ]
73
+ }
74
+ ],
75
+ "GaussNoise": [
76
+ {
77
+ "param_name": "var_limit",
78
+ "type": "int_interval",
79
+ "limits_list": [
80
+ 0.0,
81
+ 500.0
82
+ ],
83
+ "defaults": [
84
+ 10.0,
85
+ 50.0
86
+ ]
87
+ },
88
+ {
89
+ "param_name": "mean",
90
+ "type": "int_interval",
91
+ "limits_list": [
92
+ -100.0,
93
+ 100.0
94
+ ],
95
+ "defaults": 0.0
96
+ }
97
+ ],
98
+ "RandomBrightness": [
99
+ {
100
+ "param_name": "limit",
101
+ "type": "int_interval",
102
+ "limits_list": [
103
+ -1.0,
104
+ 1.0
105
+ ],
106
+ "defaults": [
107
+ -0.2,
108
+ 0.2
109
+ ]
110
+ }
111
+ ],
112
+ "RandomContrast": [
113
+ {
114
+ "param_name": "limit",
115
+ "type": "int_interval",
116
+ "limits_list": [
117
+ -1.0,
118
+ 1.0
119
+ ],
120
+ "defaults": [
121
+ -0.2,
122
+ 0.2
123
+ ]
124
+ }
125
+ ],
126
+ "HueSaturationValue": [
127
+ {
128
+ "param_name": "hue_shift_limit",
129
+ "type": "int_interval",
130
+ "limits_list": [
131
+ -100,
132
+ 100
133
+ ],
134
+ "defaults": [
135
+ -20,
136
+ 20
137
+ ]
138
+ },
139
+ {
140
+ "param_name": "sat_shift_limit",
141
+ "type": "int_interval",
142
+ "limits_list": [
143
+ -100,
144
+ 100
145
+ ],
146
+ "defaults": [
147
+ -30,
148
+ 30
149
+ ]
150
+ },
151
+ {
152
+ "param_name": "val_shift_limit",
153
+ "type": "int_interval",
154
+ "limits_list": [
155
+ -100,
156
+ 100
157
+ ],
158
+ "defaults": [
159
+ -20,
160
+ 20
161
+ ]
162
+ }
163
+ ],
164
+ "RGBShift": [
165
+ {
166
+ "param_name": "r_shift_limit",
167
+ "type": "int_interval",
168
+ "limits_list": [
169
+ -255,
170
+ 255
171
+ ],
172
+ "defaults": [
173
+ -20,
174
+ 20
175
+ ]
176
+ },
177
+ {
178
+ "param_name": "g_shift_limit",
179
+ "type": "int_interval",
180
+ "limits_list": [
181
+ -255,
182
+ 255
183
+ ],
184
+ "defaults": [
185
+ -20,
186
+ 20
187
+ ]
188
+ },
189
+ {
190
+ "param_name": "b_shift_limit",
191
+ "type": "int_interval",
192
+ "limits_list": [
193
+ -255,
194
+ 255
195
+ ],
196
+ "defaults": [
197
+ -20,
198
+ 20
199
+ ]
200
+ }
201
+ ],
202
+ "JpegCompression": [
203
+ {
204
+ "param_name": "quality_lower",
205
+ "type": "int_interval",
206
+ "limits_list": [
207
+ 0,
208
+ 100
209
+ ],
210
+ "defaults": 99
211
+ },
212
+ {
213
+ "param_name": "quality_upper",
214
+ "type": "int_interval",
215
+ "limits_list": [
216
+ 0,
217
+ 100
218
+ ],
219
+ "defaults": 100
220
+ }
221
+ ],
222
+ "ImageCompression": [
223
+ {
224
+ "param_name": "quality_lower",
225
+ "type": "int_interval",
226
+ "limits_list": [
227
+ 0,
228
+ 100
229
+ ],
230
+ "defaults": 99
231
+ },
232
+ {
233
+ "param_name": "quality_upper",
234
+ "type": "int_interval",
235
+ "limits_list": [
236
+ 0,
237
+ 100
238
+ ],
239
+ "defaults": 100
240
+ },
241
+ {
242
+ "param_name": "compression_type",
243
+ "type": "radio",
244
+ "options_list": [
245
+ 0,
246
+ 1
247
+ ]
248
+ }
249
+ ],
250
+ "CLAHE": [
251
+ {
252
+ "param_name": "clip_limit",
253
+ "type": "int_interval",
254
+ "limits_list": [
255
+ 1,
256
+ 100
257
+ ],
258
+ "defaults": [
259
+ 1,
260
+ 4
261
+ ]
262
+ },
263
+ {
264
+ "param_name": "tile_grid_size",
265
+ "type": "several_ints",
266
+ "subparam_names": [
267
+ "y",
268
+ "x"
269
+ ],
270
+ "limits_list": [
271
+ [
272
+ 1,
273
+ 100
274
+ ],
275
+ [
276
+ 1,
277
+ 100
278
+ ]
279
+ ],
280
+ "defaults_list": [
281
+ 8,
282
+ 8
283
+ ]
284
+ }
285
+ ],
286
+ "Cutout": [
287
+ {
288
+ "param_name": "num_holes",
289
+ "type": "int_interval",
290
+ "limits_list": [
291
+ 1,
292
+ 100
293
+ ],
294
+ "defaults": 8
295
+ },
296
+ {
297
+ "param_name": "max_h_size",
298
+ "type": "int_interval",
299
+ "limits_list": [
300
+ 1,
301
+ 100
302
+ ],
303
+ "defaults": 8
304
+ },
305
+ {
306
+ "param_name": "max_w_size",
307
+ "type": "int_interval",
308
+ "limits_list": [
309
+ 1,
310
+ 100
311
+ ],
312
+ "defaults": 8
313
+ },
314
+ {
315
+ "param_name": "fill_value",
316
+ "type": "rgb"
317
+ }
318
+ ],
319
+ "RandomSnow": [
320
+ {
321
+ "param_name": "snow_point_lower",
322
+ "type": "int_interval",
323
+ "limits_list": [
324
+ 0.0,
325
+ 1.0
326
+ ],
327
+ "defaults": 0.1
328
+ },
329
+ {
330
+ "param_name": "snow_point_upper",
331
+ "type": "int_interval",
332
+ "limits_list": [
333
+ 0.0,
334
+ 1.0
335
+ ],
336
+ "defaults": 0.1
337
+ },
338
+ {
339
+ "param_name": "brightness_coeff",
340
+ "type": "int_interval",
341
+ "limits_list": [
342
+ 0.0,
343
+ 20.0
344
+ ],
345
+ "defaults": 2.5
346
+ }
347
+ ],
348
+ "RandomFog": [
349
+ {
350
+ "param_name": "fog_coef_lower",
351
+ "type": "int_interval",
352
+ "limits_list": [
353
+ 0.0,
354
+ 1.0
355
+ ],
356
+ "defaults": 0.1
357
+ },
358
+ {
359
+ "param_name": "fog_coef_upper",
360
+ "type": "int_interval",
361
+ "limits_list": [
362
+ 0.0,
363
+ 1.0
364
+ ],
365
+ "defaults": 0.1
366
+ },
367
+ {
368
+ "param_name": "alpha_coef",
369
+ "type": "int_interval",
370
+ "limits_list": [
371
+ 0.0,
372
+ 1.0
373
+ ],
374
+ "defaults": 0.08
375
+ }
376
+ ],
377
+ "ChannelDropout": [
378
+ {
379
+ "param_name": "channel_drop_range",
380
+ "type": "int_interval",
381
+ "limits_list": [
382
+ 1,
383
+ 3
384
+ ],
385
+ "defaults": [
386
+ 1,
387
+ 1
388
+ ]
389
+ },
390
+ {
391
+ "param_name": "fill_value",
392
+ "type": "int_interval",
393
+ "limits_list": [
394
+ 0,
395
+ 255
396
+ ],
397
+ "defaults": 0
398
+ }
399
+ ],
400
+ "Solarize": [
401
+ {
402
+ "param_name": "threshold",
403
+ "type": "int_interval",
404
+ "limits_list": [
405
+ 0,
406
+ 255
407
+ ],
408
+ "defaults": 128
409
+ }
410
+ ],
411
+ "Equalize": [
412
+ {
413
+ "param_name": "mode",
414
+ "type": "radio",
415
+ "options_list": [
416
+ "cv",
417
+ "pil"
418
+ ]
419
+ },
420
+ {
421
+ "param_name": "by_channels",
422
+ "type": "checkbox",
423
+ "defaults": 1
424
+ }
425
+ ]
426
  }
src/control.py CHANGED
@@ -3,32 +3,43 @@ import streamlit as st
3
 
4
  def select_int_interval(param_name, limits_list, defaults, **kwargs):
5
  st.sidebar.subheader(param_name)
6
- min_max_interval = st.sidebar.slider('', limits_list[0], limits_list[1], defaults, key = hash(param_name))
 
 
7
  return min_max_interval
8
 
9
 
10
- def select_several_ints(param_name, subparam_names, limits_list, defaults_list, **kwargs):
 
 
11
  st.sidebar.subheader(param_name)
12
  result = []
13
  assert len(limits_list) == len(defaults_list)
14
  assert len(subparam_names) == len(defaults_list)
15
-
16
  for name, limits, defaults in zip(subparam_names, limits_list, defaults_list):
17
- result.append(st.sidebar.slider(name, limits[0], limits[1], defaults, key = hash(param_name + name)))
 
 
 
 
18
  return tuple(result)
19
 
 
20
  def select_several_RGB(param_name, **kwargs):
21
- result = select_several_ints(param_name,
22
- subparam_names = ["Red", "Green", "Blue"],
23
- limits_list = [[0, 255],[0, 255],[0, 255]],
24
- defaults_list = [0, 0, 0])
 
 
25
  return tuple(result)
26
 
27
 
28
  def select_radio(param_name, options_list, **kwargs):
29
  st.sidebar.subheader(param_name)
30
- result = st.sidebar.radio('', options_list)
31
- if isinstance(options_list[0],str):
32
  result = '"' + result + '"'
33
  return result
34
 
@@ -39,13 +50,11 @@ def select_checkbox(param_name, defaults, **kwargs):
39
  return result
40
 
41
 
42
-
43
  # dict from param name to function showing this param
44
  param2func = {
45
- 'int_interval': select_int_interval,
46
- 'several_ints': select_several_ints,
47
- 'radio': select_radio,
48
- 'rgb': select_several_RGB,
49
- 'checkbox': select_checkbox
50
-
51
- }
 
3
 
4
  def select_int_interval(param_name, limits_list, defaults, **kwargs):
5
  st.sidebar.subheader(param_name)
6
+ min_max_interval = st.sidebar.slider(
7
+ "", limits_list[0], limits_list[1], defaults, key=hash(param_name)
8
+ )
9
  return min_max_interval
10
 
11
 
12
+ def select_several_ints(
13
+ param_name, subparam_names, limits_list, defaults_list, **kwargs
14
+ ):
15
  st.sidebar.subheader(param_name)
16
  result = []
17
  assert len(limits_list) == len(defaults_list)
18
  assert len(subparam_names) == len(defaults_list)
19
+
20
  for name, limits, defaults in zip(subparam_names, limits_list, defaults_list):
21
+ result.append(
22
+ st.sidebar.slider(
23
+ name, limits[0], limits[1], defaults, key=hash(param_name + name)
24
+ )
25
+ )
26
  return tuple(result)
27
 
28
+
29
  def select_several_RGB(param_name, **kwargs):
30
+ result = select_several_ints(
31
+ param_name,
32
+ subparam_names=["Red", "Green", "Blue"],
33
+ limits_list=[[0, 255], [0, 255], [0, 255]],
34
+ defaults_list=[0, 0, 0],
35
+ )
36
  return tuple(result)
37
 
38
 
39
  def select_radio(param_name, options_list, **kwargs):
40
  st.sidebar.subheader(param_name)
41
+ result = st.sidebar.radio("", options_list)
42
+ if isinstance(options_list[0], str):
43
  result = '"' + result + '"'
44
  return result
45
 
 
50
  return result
51
 
52
 
 
53
  # dict from param name to function showing this param
54
  param2func = {
55
+ "int_interval": select_int_interval,
56
+ "several_ints": select_several_ints,
57
+ "radio": select_radio,
58
+ "rgb": select_several_RGB,
59
+ "checkbox": select_checkbox,
60
+ }
 
src/main.py CHANGED
@@ -9,56 +9,65 @@ import streamlit as st
9
  from control import *
10
 
11
 
12
- def load_image(image_name, path_to_folder = '../images'):
13
  path_to_image = os.path.join(path_to_folder, image_name)
14
  image = cv2.imread(path_to_image)
15
  image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
16
  return image
17
 
18
 
19
- st.title('Demo of Albumentations transforms')
20
 
21
 
22
  # selecting the image
23
- path_to_images = 'images'
24
- image_names_list = [x for x in os.listdir(path_to_images) if x[-3:] in ['jpg', 'peg', 'png']]
25
- image_name = st.sidebar.selectbox('Select an image:', image_names_list)
 
 
26
  image = load_image(image_name, path_to_images)
27
 
28
 
29
  # selecting the transformation
30
- path_to_config = 'configs/augmentations.json'
31
- with open(path_to_config, 'r') as config_file:
32
  augmentations = json.load(config_file)
33
- transform_name = st.sidebar.selectbox('Select a transformation:', sorted(list(augmentations.keys())))
 
 
34
  transform_params = augmentations[transform_name]
35
 
36
 
37
  # show the transform options
38
  if len(transform_params) == 0:
39
- st.sidebar.text(transform_name + ' transform has no parameters')
40
  else:
41
  for param in transform_params:
42
- param['value'] = param2func[param['type']](**param)
43
-
44
-
45
- params_string = ", ".join([param['param_name'] + '=' + str(param['value']) for param in transform_params] + ['p=1.0'])
46
- params_string = '(' + params_string + ')'
47
 
48
- st.text(transform_name + params_string)
49
- st.text('Press R to update')
50
- exec('transform = A.' + transform_name + params_string)
51
- st.image([image, transform(image = image)['image']],
52
- caption = ['Original image', 'Transformed image'],
53
- width = 320)
54
 
55
- st.subheader('Docstring:')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  st.text(str(transform.__doc__))
57
 
58
 
59
- st.text('')
60
- st.text('')
61
- st.subheader('Credentials:')
62
- st.text('Source: https://github.com/IliaLarchenko/albumentations-demo')
63
- st.text('Albumentations library: https://github.com/albumentations-team/albumentations')
64
- st.text('Image Source: https://www.pexels.com/royalty-free-images/')
 
9
  from control import *
10
 
11
 
12
+ def load_image(image_name, path_to_folder="../images"):
13
  path_to_image = os.path.join(path_to_folder, image_name)
14
  image = cv2.imread(path_to_image)
15
  image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
16
  return image
17
 
18
 
19
+ st.title("Demo of Albumentations transforms")
20
 
21
 
22
  # selecting the image
23
+ path_to_images = "images"
24
+ image_names_list = [
25
+ x for x in os.listdir(path_to_images) if x[-3:] in ["jpg", "peg", "png"]
26
+ ]
27
+ image_name = st.sidebar.selectbox("Select an image:", image_names_list)
28
  image = load_image(image_name, path_to_images)
29
 
30
 
31
  # selecting the transformation
32
+ path_to_config = "configs/augmentations.json"
33
+ with open(path_to_config, "r") as config_file:
34
  augmentations = json.load(config_file)
35
+ transform_name = st.sidebar.selectbox(
36
+ "Select a transformation:", sorted(list(augmentations.keys()))
37
+ )
38
  transform_params = augmentations[transform_name]
39
 
40
 
41
  # show the transform options
42
  if len(transform_params) == 0:
43
+ st.sidebar.text(transform_name + " transform has no parameters")
44
  else:
45
  for param in transform_params:
46
+ param["value"] = param2func[param["type"]](**param)
 
 
 
 
47
 
 
 
 
 
 
 
48
 
49
+ params_string = ", ".join(
50
+ [param["param_name"] + "=" + str(param["value"]) for param in transform_params]
51
+ + ["p=1.0"]
52
+ )
53
+ params_string = "(" + params_string + ")"
54
+
55
+ st.text(transform_name + params_string)
56
+ st.text("Press R to update")
57
+ exec("transform = A." + transform_name + params_string)
58
+ st.image(
59
+ [image, transform(image=image)["image"]],
60
+ caption=["Original image", "Transformed image"],
61
+ width=320,
62
+ )
63
+
64
+ st.subheader("Docstring:")
65
  st.text(str(transform.__doc__))
66
 
67
 
68
+ st.text("")
69
+ st.text("")
70
+ st.subheader("Credentials:")
71
+ st.text("Source: https://github.com/IliaLarchenko/albumentations-demo")
72
+ st.text("Albumentations library: https://github.com/albumentations-team/albumentations")
73
+ st.text("Image Source: https://www.pexels.com/royalty-free-images/")