@@ -32,6 +32,7 @@ def __init__(
32
32
self ,
33
33
font_root_path ,
34
34
font_variation_degrees ,
35
+ text_variation_degrees ,
35
36
font_size_variation_degrees ,
36
37
rotation_degree_variation_degrees ,
37
38
stroke_width_variation_degrees ,
@@ -52,6 +53,10 @@ def __init__(
52
53
is provided, the same variation degree will be used for all iterations. The value means the probability of
53
54
changing the font to a random font.
54
55
:type font_variation_degrees: float or list[float]
56
+ :param text_variation_degrees: The variation degrees for text utilized at each PE iteration. If a single value
57
+ is provided, the same variation degree will be used for all iterations. The value means the probability of
58
+ changing the text to a random text.
59
+ :type text_variation_degrees: float or list[float]
55
60
:param font_size_variation_degrees: The variation degrees for font size utilized at each PE iteration. If a
56
61
single value is provided, the same variation degree will be used for all iterations. The value means
57
62
the maximum possible variation in font size.
@@ -89,6 +94,7 @@ def __init__(
89
94
super ().__init__ ()
90
95
self ._font_root_path = font_root_path
91
96
self ._font_variation_degrees = _to_constant_list_if_needed (font_variation_degrees )
97
+ self ._text_variation_degrees = _to_constant_list_if_needed (text_variation_degrees )
92
98
self ._font_size_variation_degrees = _to_constant_list_if_needed (font_size_variation_degrees )
93
99
self ._rotation_degree_variation_degrees = _to_constant_list_if_needed (rotation_degree_variation_degrees )
94
100
self ._stroke_width_variation_degrees = _to_constant_list_if_needed (stroke_width_variation_degrees )
@@ -223,8 +229,10 @@ def _get_variation_image(
223
229
rotation_degree ,
224
230
font_size_variation_degree ,
225
231
font_variation_degree ,
232
+ text_variation_degree ,
226
233
stroke_width_variation_degree ,
227
234
rotation_degree_variation_degree ,
235
+ label_name ,
228
236
):
229
237
"""Get a variation image and its parameters.
230
238
@@ -242,16 +250,23 @@ def _get_variation_image(
242
250
:type font_size_variation_degree: int
243
251
:param font_variation_degree: The degree of variation in font
244
252
:type font_variation_degree: float
253
+ :param text_variation_degree: The degree of variation in text
254
+ :type text_variation_degree: float
245
255
:param stroke_width_variation_degree: The degree of variation in stroke width
246
256
:type stroke_width_variation_degree: int
247
257
:param rotation_degree_variation_degree: The degree of variation in rotation degree
248
258
:type rotation_degree_variation_degree: int
259
+ :param label_name: The label name
260
+ :type label_name: str
249
261
:return: The image of the avatar and its parameters
250
262
:rtype: tuple[np.ndarray, dict]
251
263
"""
252
264
do_font_variation = random .random () < font_variation_degree
253
265
if do_font_variation :
254
266
font_file = random .choice (self ._font_files )
267
+ do_text_variation = random .random () < text_variation_degree
268
+ if do_text_variation :
269
+ text = random .choice (self ._text_list [label_name ])
255
270
256
271
font_size += random .randint (- font_size_variation_degree , font_size_variation_degree )
257
272
font_size = max (min (font_size , max (self ._font_size_list )), min (self ._font_size_list ))
@@ -289,9 +304,11 @@ def variation_api(self, syn_data):
289
304
execution_logger .info (f"VARIATION API: creating variations for { len (syn_data .data_frame )} samples" )
290
305
original_params = list (syn_data .data_frame [TEXT_PARAMS_COLUMN_NAME ].values )
291
306
original_images = np .stack (syn_data .data_frame [IMAGE_DATA_COLUMN_NAME ].values )
307
+ original_label_ids = syn_data .data_frame [LABEL_ID_COLUMN_NAME ].values
292
308
iteration = getattr (syn_data .metadata , "iteration" , - 1 )
293
309
font_variation_degree = self ._font_variation_degrees [iteration + 1 ]
294
310
font_size_variation_degree = self ._font_size_variation_degrees [iteration + 1 ]
311
+ text_variation_degree = self ._text_variation_degrees [iteration + 1 ]
295
312
rotation_variation_degree = self ._rotation_degree_variation_degrees [iteration + 1 ]
296
313
stroke_width_variation_degree = self ._stroke_width_variation_degrees [iteration + 1 ]
297
314
@@ -307,9 +324,11 @@ def variation_api(self, syn_data):
307
324
original_param = original_params [i ]
308
325
image , param = self ._get_variation_image (
309
326
font_size_variation_degree = font_size_variation_degree ,
327
+ text_variation_degree = text_variation_degree ,
310
328
font_variation_degree = font_variation_degree ,
311
329
rotation_degree_variation_degree = rotation_variation_degree ,
312
330
stroke_width_variation_degree = stroke_width_variation_degree ,
331
+ label_name = syn_data .metadata .label_info [int (original_label_ids [i ])].name ,
313
332
** original_param ,
314
333
)
315
334
if image is not None :
0 commit comments