def show_resolution(seed): rng = np.random.RandomState(seed) kwargs = dict(alphabet=LANGUAGE_MAP['english'].get_alphabet(), is_bold=False, is_slant=False, inverse_color=False, pixel_noise_scale=0) attr_list = [ basic_attribute_sampler(resolution=(8, 8), char='b', font='arial', scale=0.9, rotation=0, background=SolidColor((0, 0, 0)), foreground=SolidColor((0.5, 0.5, 0)), **kwargs), basic_attribute_sampler(resolution=(16, 16), char='x', font='time', scale=0.7, **kwargs), basic_attribute_sampler(resolution=(32, 32), char='g', font='flavors', scale=0.6, rotation=1, **kwargs), basic_attribute_sampler(resolution=(64, 64), scale=0.3, n_symbols=5, **kwargs), basic_attribute_sampler(resolution=(128, 128), scale=0.1, n_symbols=30, **kwargs), ] def attr_sampler(): for attr in attr_list: yield attr(seed=rand_seed(rng)) x, y = pack_dataset_resample(dataset_generator(attr_sampler(), 1000)) plot_dataset(x, y, h_axis='rotation', v_axis=None, n_col=5, n_row=1, hide_axis=True) ax = plt.gca() ax.set_xticks((np.arange(len(attr_list)) + 0.5) * x.shape[1]) ax.set_xticklabels(['8 x 8', '16 x 16', '32 x 32', '64 x 64', '128 x 128'], rotation=0) ax.get_xaxis().set_visible(True) plt.xlabel('')
def show_background(seed): rng = np.random.RandomState(seed) kwargs = dict(resolution=(128, 128), alphabet=LANGUAGE_MAP['english'].get_alphabet(), char='a', inverse_color=False, pixel_noise_scale=0) attr_list = [ basic_attribute_sampler(background=SolidColor((0.2, 0.2, 0)), foreground=SolidColor((0.8, 0, 0.8)), **kwargs), basic_attribute_sampler(background=lambda _rng: Gradient( types=('radial', ), seed=rand_seed(_rng)), foreground=lambda _rng: Gradient( types=('radial', ), seed=rand_seed(_rng)), **kwargs), basic_attribute_sampler( background=lambda _rng: Camouflage(stroke_angle=np.pi / 4, seed=rand_seed(_rng)), foreground=lambda _rng: Camouflage(stroke_angle=np.pi * 3 / 4, seed=rand_seed(_rng)), **kwargs), basic_attribute_sampler( background=lambda _rng: ImagePattern(seed=rand_seed(_rng)), foreground=lambda _rng: ImagePattern(seed=rand_seed(_rng)), **kwargs), add_occlusion(basic_attribute_sampler(**kwargs), n_occlusion=3, scale=lambda _rng: 0.3 * np.exp(_rng.randn() * 0.1), translation=lambda _rng: tuple(_rng.rand(2) * 2 - 1)) ] def attr_sampler(): for attr in attr_list: yield attr(seed=rand_seed(rng)) x, _, y = pack_dataset( dataset_generator(attr_sampler(), 1000, flatten_mask_except_first)) plot_dataset(x, y, h_axis='scale', v_axis=None, n_col=5, n_row=1, hide_axis=True) ax = plt.gca() ax.set_xticks((np.arange(5) + 0.5) * x.shape[1]) ax.set_xticklabels( ['Solid', 'Gradient', 'Camouflage', 'Natural', 'Occlusions'], rotation=0) ax.get_xaxis().set_visible(True) plt.xlabel('')
def show_fonts(seed): rng = np.random.RandomState(seed) def attr_sampler(): for char in 'abCD': for font in font_list: yield basic_attribute_sampler( alphabet=LANGUAGE_MAP['english'], char=char, font=font, is_bold=False, is_slant=False, resolution=(128, 128), pixel_noise_scale=0)(seed=rand_seed(rng)) x, _, y = pack_dataset(dataset_generator(attr_sampler(), 1000)) plot_dataset(x, y, h_axis='font', v_axis='char', hide_axis=True)
def main(): # XXX: Imports are here so that they are done # inside the docker image (synbols [...]) from synbols.data_io import load_h5 from synbols.utils import flatten_attr from synbols.visualization import plot_dataset args = parse_args() if args.data is None: raise Exception(" path to the data is not defined." "Please use `--data` and indicate the path.") print("load dataset in h5 format ...") x, mask, attr_list, splits = load_h5(args.data) print("x.shape:", x.shape) attr_list = [flatten_attr(attr) for attr in attr_list] all_attr_keys = [] for attr in attr_list[0].keys(): all_attr_keys.append(attr) check = all(key in all_attr_keys for key in args.attr_keys) if not check: raise Exception("One or more of the provided attribute keys are" + "not valid." + f"The complete list of keys is {all_attr_keys}") split_masks = splits[args.split_name] print("making statistics for %s." % args.split_name) view_split(split_masks, attr_list, args.attr_keys, args.split_name) plot_dataset(x, attr_list, v_axis=None, h_axis="font") if args.save: plt.savefig(args.save) plt.show()
def show_languages(seed): language_list = [ 'korean', 'chinese', 'telugu', 'thai', 'gujarati', 'arabic', 'tamil', 'russian' ] rng = np.random.RandomState(seed) def attr_sampler(): for lang in language_list: alphabet = LANGUAGE_MAP[lang].get_alphabet() for i in range(4): yield basic_attribute_sampler( alphabet=alphabet, char=lambda rng: rng.choice(alphabet.symbols), font=lambda rng: rng.choice(alphabet.fonts), is_bold=False, is_slant=False, resolution=(128, 128), pixel_noise_scale=0)(seed=rand_seed(rng)) x, _, y = pack_dataset(dataset_generator(attr_sampler(), 1000)) h_values, v_values = plot_dataset(x, y, h_axis='alphabet', v_axis=None, n_col=len(language_list), n_row=4, hide_axis=True) # map = {'chinese-simplified': 'chinese'} # h_values = [map.get(val, val) for val in h_values] ax = plt.gca() ax.set_xticks((np.arange(len(h_values)) + 0.5) * x.shape[1]) ax.set_xticklabels(h_values, rotation=0) ax.get_xaxis().set_visible(True) plt.xlabel('')
def make_image(attr_sampler, file_name): x, _, y = pack_dataset(dataset_generator(attr_sampler, 1000)) plot_dataset(x, y, h_axis='font', v_axis='char') plt.savefig(file_name)
from synbols import generate from synbols import drawing from synbols.visualization import plot_dataset import matplotlib.pyplot as plt # bg = drawing.Camouflage(stroke_angle=1.) # bg = drawing.NoPattern() bg = drawing.MultiGradient(alpha=0.5, n_gradients=2, types=('linear', 'radial')) # bg = drawing.Gradient(types=('linear',), random_color=drawing.color_sampler(brightness_range=(0.1, 0.9))) # fg = drawing.Camouflage(stroke_angle=0.5) # fg = drawing.SolidColor((1, 1, 1)) fg = drawing.Gradient( types=('radial', ), random_color=drawing.color_sampler(brightness_range=(0.1, 0.9))) attr_sampler = generate.basic_attribute_sampler(resolution=(64, 64), foreground=fg, background=bg) # attr_sampler = generate.add_occlusion(attr_sampler) x, mask, y = pack_dataset( generate.dataset_generator(attr_sampler, 500, generate.flatten_mask)) plt.figure('dataset') plot_dataset(x, y, h_axis='char', v_axis='font', n_row=10, n_col=20) plt.savefig('view_generator.png')