run_experiment_apd_apdl.py 13.1 KB
Newer Older
Jiri Borovec's avatar
Jiri Borovec committed
1 2 3 4
"""
run experiments with Atomic Learning Pattern Encoding

Example run:
Jiri Borovec's avatar
Jiri Borovec committed
5
>> python run_experiment_apd_apdl.py \
Jiri Borovec's avatar
Jiri Borovec committed
6 7 8 9 10 11 12
    -in /datagrid/Medical/microscopy/drosophila/synthetic_data/atomicPatternDictionary_v1 \
    -out /datagrid/Medical/microscopy/drosophila/TEMPORARY/experiments_APDL_synth

>> python run_experiment_apd_apdl.py --type real \
    -in /datagrid/Medical/microscopy/drosophila/TEMPORARY/type_1_segm_reg_binary \
    -out /datagrid/Medical/microscopy/drosophila/TEMPORARY/experiments_APDL_real \
    --dataset gene_ssmall
Jiri Borovec's avatar
Jiri Borovec committed
13

Jiri Borovec's avatar
Jiri Borovec committed
14
Copyright (C) 2015-2016 Jiri Borovec <jiri.borovec@fel.cvut.cz>
Jiri Borovec's avatar
Jiri Borovec committed
15 16
"""

17
# to suppress all visu, has to be on the beginning
Jiri Borovec's avatar
Jiri Borovec committed
18

Jiri Borovec's avatar
Jiri Borovec committed
19
import os
Jiri Borovec's avatar
Jiri Borovec committed
20
import sys
Jiri Borovec's avatar
Jiri Borovec committed
21
import time
Jiri Borovec's avatar
Jiri Borovec committed
22
import traceback
Jiri Borovec's avatar
Jiri Borovec committed
23
import logging
Jiri Borovec's avatar
Jiri Borovec committed
24
import copy
Jiri Borovec's avatar
Jiri Borovec committed
25
import gc
Jiri Borovec's avatar
Jiri Borovec committed
26
from functools import partial
Jiri Borovec's avatar
Jiri Borovec committed
27

Jiri Borovec's avatar
Jiri Borovec committed
28
import matplotlib
29
# matplotlib.use('Agg')
Jiri Borovec's avatar
Jiri Borovec committed
30 31 32
import numpy as np
import matplotlib.pylab as plt
import matplotlib.gridspec as gridspec
Jiri Borovec's avatar
Jiri Borovec committed
33
import tqdm
Jiri Borovec's avatar
Jiri Borovec committed
34

Jiri Borovec's avatar
Jiri Borovec committed
35
sys.path.append(os.path.abspath(os.path.join('..','..')))  # Add path to root
Jiri Borovec's avatar
Jiri Borovec committed
36
import dataset_utils as gen_data
Jiri Borovec's avatar
Jiri Borovec committed
37
import dictionary_learning as dl
Jiri Borovec's avatar
Jiri Borovec committed
38 39
import pattern_disctionary as ptn_dict
import pattern_weights as ptn_weigth
Jiri Borovec's avatar
Jiri Borovec committed
40
import experiment_apd as expt_apd
Jiri Borovec's avatar
Jiri Borovec committed
41

Jiri Borovec's avatar
Jiri Borovec committed
42

Jiri Borovec's avatar
Jiri Borovec committed
43 44 45 46 47
NB_THREADS = expt_apd.NB_THREADS
SYNTH_PARAMS = expt_apd.SYNTH_PARAMS
SYNTH_SUB_DATASETS = expt_apd.SYNTH_SUB_DATASETS
SYNTH_PTN_RANGE = expt_apd.SYNTH_PTN_RANGE
REAL_PARAMS = expt_apd.REAL_PARAMS
Jiri Borovec's avatar
Jiri Borovec committed
48 49 50 51 52 53 54
NB_PATTERNS_REAL = expt_apd.NB_PATTERNS_REAL

DICT_ATLAS_INIT = {
    'msc': ptn_dict.initialise_atlas_mosaic,
    'msc1': partial(ptn_dict.initialise_atlas_mosaic, coef=1.5),
    'msc2': partial(ptn_dict.initialise_atlas_mosaic, coef=2),
    'rnd': ptn_dict.initialise_atlas_random,
55 56 57
    'OWS': ptn_dict.initialise_atlas_otsu_watershed_2d,
    'OWSr': partial(ptn_dict.initialise_atlas_otsu_watershed_2d, bg='rand'),
    'GWS': ptn_dict.initialise_atlas_gauss_watershed_2d,
Jiri Borovec's avatar
Jiri Borovec committed
58 59 60 61 62
    'GT': None,  # init by Ground Truth, require GT atlas
    'GTd': None,  # init by deformed Ground Truth, require GT atlas
}

# SIMPLE RUN
63 64
INIT_TYPES = ['OWS', 'OWSr', 'GWS']
GRAPHCUT_REGUL = [0., 1e-9, 1e-3]
Jiri Borovec's avatar
Jiri Borovec committed
65 66
# COMPLEX RUN
# INIT_TYPES = DICT_ATLAS_INIT.keys()
67
# GRAPHCUT_REGUL = [0., 0e-12, 1e-9, 1e-6, 1e-3, 1e-1]
Jiri Borovec's avatar
Jiri Borovec committed
68

Jiri Borovec's avatar
Jiri Borovec committed
69

Jiri Borovec's avatar
Jiri Borovec committed
70
def test_simple_show_case():
Jiri Borovec's avatar
Jiri Borovec committed
71
    """   """
Jiri Borovec's avatar
Jiri Borovec committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    # implement simple case just with 2 images and 2/3 classes in atlas
    atlas = gen_data.get_simple_atlas()
    # atlas2 = atlas.copy()
    # atlas2[atlas2>2] = 0
    imgs = gen_data.get_sample_images(atlas)
    l_ws = [([1,0,0], [0,1,0], [0,0,1]),
            ([1,0,1], [0,1,1], [0,0,1])]
    for j, ws in enumerate(l_ws):
        plt.figure()
        plt.title('w: {}'.format(repr(ws)))
        gs = gridspec.GridSpec(2, len(imgs) + 2)
        plt.subplot(gs[0, 0]), plt.title('atlas')
        cm = plt.cm.get_cmap('jet', len(np.unique(atlas)))
        plt.imshow(atlas, cmap=cm, interpolation='nearest'), plt.colorbar()
        for i, (img, w) in enumerate(zip(imgs, ws)):
            plt.subplot(gs[0, i + 1]), plt.title('w:{}'.format(w))
            plt.imshow(img, cmap='gray', interpolation='nearest')
        t = time.time()
        uc = dl.compute_relative_penaly_images_weights(imgs, np.array(ws))
Jiri Borovec's avatar
Jiri Borovec committed
91
        logging.debug('elapsed TIME: %s', repr(time.time() - t))
Jiri Borovec's avatar
Jiri Borovec committed
92 93 94 95
        res = dl.estimate_atlas_graphcut_general(imgs, np.array(ws), 0.)
        plt.subplot(gs[0, -1]), plt.title('result')
        plt.imshow(res, cmap=cm, interpolation='nearest'), plt.colorbar()
        uc = uc.reshape(atlas.shape+uc.shape[2:])
Jiri Borovec's avatar
Jiri Borovec committed
96
        # logging.debug(ws)
Jiri Borovec's avatar
Jiri Borovec committed
97 98 99 100
        for i in range(uc.shape[2]):
            plt.subplot(gs[1, i])
            plt.imshow(uc[:,:,i], vmin=0, vmax=1, interpolation='nearest')
            plt.title('cost lb #{}'.format(i)), plt.colorbar()
Jiri Borovec's avatar
Jiri Borovec committed
101
        # logging.debug(uc)
Jiri Borovec's avatar
Jiri Borovec committed
102 103


Jiri Borovec's avatar
Jiri Borovec committed
104
def experiment_pipeline_alpe_showcase(path_out):
Jiri Borovec's avatar
Jiri Borovec committed
105 106
    """ an simple show case to prove that the particular steps are computed

Jiri Borovec's avatar
Jiri Borovec committed
107
    :param path_in: str
Jiri Borovec's avatar
Jiri Borovec committed
108
    :param path_out: str
Jiri Borovec's avatar
Jiri Borovec committed
109 110
    :return:
    """
Jiri Borovec's avatar
Jiri Borovec committed
111
    atlas = gen_data.dataset_compose_atlas(expt_apd.SYNTH_PATH_APD)
Jiri Borovec's avatar
Jiri Borovec committed
112 113
    # plt.imshow(atlas)

Jiri Borovec's avatar
Jiri Borovec committed
114
    path_in = os.path.join(expt_apd.SYNTH_PATH_APD, gen_data.NAME_DATASET)
Jiri Borovec's avatar
Jiri Borovec committed
115
    imgs, _ = gen_data.dataset_load_images(path_in)
Jiri Borovec's avatar
Jiri Borovec committed
116
    # imgs = gen_data.dataset_load_images('datasetBinary_defNoise',
Jiri Borovec's avatar
Jiri Borovec committed
117
    #                                     path_base=SYNTH_PATH_APD)
Jiri Borovec's avatar
Jiri Borovec committed
118 119 120 121 122 123

    init_atlas_org = ptn_dict.initialise_atlas_deform_original(atlas)
    init_atlas_rnd = ptn_dict.initialise_atlas_random(atlas.shape, np.max(atlas))
    init_atlas_msc = ptn_dict.initialise_atlas_mosaic(atlas.shape, np.max(atlas))
    init_encode_rnd = ptn_weigth.initialise_weights_random(len(imgs), np.max(atlas))

124 125 126
    atlas, w_bins = dl.apdl_pipe_atlas_learning_ptn_weights(imgs,
                                                            out_prefix='mosaic', init_atlas=init_atlas_msc,
                                                            max_iter=9, out_dir=path_out)
Jiri Borovec's avatar
Jiri Borovec committed
127
    return atlas, w_bins
Jiri Borovec's avatar
Jiri Borovec committed
128 129


130
class ExperimentAPDL_base(expt_apd.ExperimentAPD):
Jiri Borovec's avatar
Jiri Borovec committed
131
    """
Jiri Borovec's avatar
Jiri Borovec committed
132
    the main real experiment or our Atlas Learning Pattern Encoding
Jiri Borovec's avatar
Jiri Borovec committed
133
    """
134

135
    def _init_atlas(self, nb_labels, init_tp, imgs):
136 137
        """ init atlas according an param

Jiri Borovec's avatar
Jiri Borovec committed
138 139
        :param nb_lbs: int
        :param init_tp: str
140 141 142
        :return: np.array<w, h>
        """
        im_size = self.imgs[0].shape
143 144 145 146 147 148 149
        if init_tp.startswith('OWS') or init_tp == 'GWS':
            assert init_tp in DICT_ATLAS_INIT
            fn_init_atlas = DICT_ATLAS_INIT[init_tp]
            init_atlas = fn_init_atlas(imgs, nb_labels)
        elif init_tp.startswith('msc') or init_tp == 'rnd':
            assert init_tp in DICT_ATLAS_INIT
            fn_init_atlas = DICT_ATLAS_INIT[init_tp]
150
            init_atlas = fn_init_atlas(im_size, nb_labels)
Jiri Borovec's avatar
Jiri Borovec committed
151 152
        elif init_tp == 'GT':
            assert hasattr(self, 'gt_atlas')
153
            init_atlas = np.remainder(self.gt_atlas, nb_labels)
Jiri Borovec's avatar
Jiri Borovec committed
154 155
        elif init_tp == 'GTd':
            assert hasattr(self, 'gt_atlas')
156
            init_atlas = np.remainder(self.gt_atlas, nb_labels)
Jiri Borovec's avatar
Jiri Borovec committed
157
            init_atlas = ptn_dict.initialise_atlas_deform_original(init_atlas)
158 159 160
        assert init_atlas.max() < nb_labels
        assert init_atlas.shape == im_size
        assert init_atlas.dtype == np.int
161 162
        return init_atlas

Jiri Borovec's avatar
Jiri Borovec committed
163
    def _estimate_atlas(self, v):
164 165 166 167
        """ set all params and run the atlas estimation in try mode

        :param i: int, index of try
        :param init_atlas: np.array<w, h>
Jiri Borovec's avatar
Jiri Borovec committed
168
        :return: np.array, np.array
169
        """
Jiri Borovec's avatar
Jiri Borovec committed
170
        logging.debug(' -> estimate atlas...')
Jiri Borovec's avatar
Jiri Borovec committed
171 172
        self.params[self.iter_var_name] = v
        logging.debug('PARAMS: %s', repr(self.params))
173
        init_atlas = self._init_atlas(self.params['nb_labels'], self.params['init_tp'], self.imgs)
174
        # prefix = 'expt_{}'.format(p['init_tp'])
Jiri Borovec's avatar
Jiri Borovec committed
175 176
        path_out = os.path.join(self.params['path_exp'],
                                'debug_{}_{}'.format(self.iter_var_name, v))
Jiri Borovec's avatar
Jiri Borovec committed
177 178
        if isinstance(self.params['nb_samples'], float):
            self.params['nb_samples'] = int(len(self.imgs) * self.params['nb_samples'])
179
        try:
180
            atlas, w_bins = dl.apdl_pipe_atlas_learning_ptn_weights(
Jiri Borovec's avatar
Jiri Borovec committed
181 182
                                        self.imgs[:self.params['nb_samples']],
                                        init_atlas=init_atlas,
183
                                        tol=self.params['tol'],
Jiri Borovec's avatar
Jiri Borovec committed
184 185 186 187
                                        gc_reinit=self.params['gc_reinit'],
                                        gc_coef=self.params['gc_regul'],
                                        max_iter=self.params['max_iter'],
                                        ptn_split=self.params['ptn_split'],
188
                                        ptn_compact=self.params['ptn_compact'],
Jiri Borovec's avatar
Jiri Borovec committed
189 190
                                        overlap_major=self.params['overlap_mj'],
                                        out_dir=path_out)  # , out_prefix=prefix
191
        except:
Jiri Borovec's avatar
Jiri Borovec committed
192 193
            logging.error('FAILED, no atlas estimated!')
            logging.error(traceback.format_exc())
194
            atlas = np.zeros_like(self.imgs[0])
Jiri Borovec's avatar
Jiri Borovec committed
195
            w_bins = np.zeros((len(self.imgs), 0))
Jiri Borovec's avatar
Jiri Borovec committed
196
        assert atlas.max() == w_bins.shape[1]
Jiri Borovec's avatar
Jiri Borovec committed
197 198
        self.atlas = atlas
        self.w_bins = w_bins
199

Jiri Borovec's avatar
Jiri Borovec committed
200
    def _perform_once(self, v):
Jiri Borovec's avatar
Jiri Borovec committed
201 202 203
        """ perform single experiment

        :param v: value
Jiri Borovec's avatar
Jiri Borovec committed
204
        :return: {str: ...}
Jiri Borovec's avatar
Jiri Borovec committed
205
        """
Jiri Borovec's avatar
Jiri Borovec committed
206
        logging.info('perform single experiment...')
Jiri Borovec's avatar
Jiri Borovec committed
207
        self._estimate_atlas(v)
Jiri Borovec's avatar
Jiri Borovec committed
208
        logging.debug('atlas of size %s and labels %s', repr(self.atlas.shape),
Jiri Borovec's avatar
Jiri Borovec committed
209
                     repr(np.unique(self.atlas).tolist()))
Jiri Borovec's avatar
Jiri Borovec committed
210
        logging.debug('weights of size %s and summing %s', repr(self.w_bins.shape),
Jiri Borovec's avatar
Jiri Borovec committed
211
                     repr(np.sum(self.w_bins, axis=0)))
Jiri Borovec's avatar
Jiri Borovec committed
212 213 214
        name_posix = '_{}_{}'.format(self.iter_var_name, v)
        self._export_atlas(name_posix)
        self._export_coding(name_posix)
Jiri Borovec's avatar
Jiri Borovec committed
215 216
        img_rct = ptn_dict.reconstruct_samples(self.atlas, self.w_bins)
        stat = self._compute_statistic_gt(img_rct)
Jiri Borovec's avatar
Jiri Borovec committed
217
        stat[self.iter_var_name] = v
218 219
        return stat

Jiri Borovec's avatar
Jiri Borovec committed
220

Jiri Borovec's avatar
Jiri Borovec committed
221
class ExperimentAPDL(ExperimentAPDL_base, expt_apd.ExperimentAPD_parallel):
Jiri Borovec's avatar
Jiri Borovec committed
222
    """
223
    parallel version of APDL
Jiri Borovec's avatar
Jiri Borovec committed
224 225 226 227
    """
    pass


Jiri Borovec's avatar
Jiri Borovec committed
228
def experiments_test(dict_params=SYNTH_PARAMS):
Jiri Borovec's avatar
Jiri Borovec committed
229
    """ simple test of the experiments """
Jiri Borovec's avatar
Jiri Borovec committed
230
    logging.basicConfig(level=logging.DEBUG)
Jiri Borovec's avatar
Jiri Borovec committed
231
    # experiment_pipeline_alpe_showcase()
Jiri Borovec's avatar
Jiri Borovec committed
232
    params = copy.deepcopy(dict_params)
Jiri Borovec's avatar
Jiri Borovec committed
233 234
    params['nb_runs'] = 3

Jiri Borovec's avatar
Jiri Borovec committed
235
    logging.info('RUN: ExperimentALPE_raw')
236
    expt = ExperimentAPDL_base(params)
Jiri Borovec's avatar
Jiri Borovec committed
237
    expt.run(iter_var='case', iter_vals=range(params['nb_runs']))
Jiri Borovec's avatar
Jiri Borovec committed
238

Jiri Borovec's avatar
Jiri Borovec committed
239
    logging.info('RUN: ExperimentALPE_mp')
Jiri Borovec's avatar
Jiri Borovec committed
240
    expt_p = ExperimentAPDL(params)
Jiri Borovec's avatar
Jiri Borovec committed
241
    expt_p.run(iter_var='case', iter_vals=range(params['nb_runs']))
Jiri Borovec's avatar
Jiri Borovec committed
242 243


Jiri Borovec's avatar
Jiri Borovec committed
244
def experiments_synthetic(params=SYNTH_PARAMS):
Jiri Borovec's avatar
Jiri Borovec committed
245
    """ run all experiments
Jiri Borovec's avatar
Jiri Borovec committed
246

Jiri Borovec's avatar
Jiri Borovec committed
247
    :param dataset: str, name of dataset
Jiri Borovec's avatar
Jiri Borovec committed
248
    :param nb_jobs: int
Jiri Borovec's avatar
Jiri Borovec committed
249 250
    :param dict_params: {str: value}
    :param sub_datasets: [str]
Jiri Borovec's avatar
Jiri Borovec committed
251
    :param ptn_range: [int]
Jiri Borovec's avatar
Jiri Borovec committed
252
    :param ds_version: str, version of dataset
Jiri Borovec's avatar
Jiri Borovec committed
253
    """
Jiri Borovec's avatar
Jiri Borovec committed
254
    arg_params = expt_apd.parse_params(params)
Jiri Borovec's avatar
Jiri Borovec committed
255 256
    logging.info('PARAMS: \n%s', '\n'.join(['"{}": \n\t {}'.format(k, v)
                                            for k, v in arg_params.iteritems()]))
Jiri Borovec's avatar
Jiri Borovec committed
257
    params.update(arg_params)
258
    params.update({'max_iter': 25})
Jiri Borovec's avatar
Jiri Borovec committed
259 260

    l_params = [params]
Jiri Borovec's avatar
Jiri Borovec committed
261 262
    if isinstance(params['dataset'], list):
        l_params = expt_apd.extend_list_params(l_params, 'dataset', params['dataset'])
Jiri Borovec's avatar
Jiri Borovec committed
263
    l_params = expt_apd.extend_list_params(l_params, 'init_tp', INIT_TYPES)
Jiri Borovec's avatar
Jiri Borovec committed
264
    l_params = expt_apd.extend_list_params(l_params, 'ptn_split', [True, False])
265
    l_params = expt_apd.extend_list_params(l_params, 'ptn_compact', [True, False])
Jiri Borovec's avatar
Jiri Borovec committed
266
    l_params = expt_apd.extend_list_params(l_params, 'gc_regul', GRAPHCUT_REGUL)
Jiri Borovec's avatar
Jiri Borovec committed
267
    ptn_range = SYNTH_PTN_RANGE[os.path.basename(params['path_in'])]
Jiri Borovec's avatar
Jiri Borovec committed
268
    l_params = expt_apd.extend_list_params(l_params, 'nb_labels', ptn_range)
Jiri Borovec's avatar
Jiri Borovec committed
269

Jiri Borovec's avatar
Jiri Borovec committed
270
    logging.debug('list params: %i', len(l_params))
Jiri Borovec's avatar
Jiri Borovec committed
271

Jiri Borovec's avatar
Jiri Borovec committed
272
    tqdm_bar = tqdm.tqdm(total=len(l_params))
Jiri Borovec's avatar
Jiri Borovec committed
273
    for params in l_params:
Jiri Borovec's avatar
Jiri Borovec committed
274
        try:
Jiri Borovec's avatar
Jiri Borovec committed
275 276
            if params['nb_jobs'] > 1:
                expt = ExperimentAPDL(params, params['nb_jobs'])
Jiri Borovec's avatar
Jiri Borovec committed
277
            else:
278
                expt = ExperimentAPDL_base(params)
Jiri Borovec's avatar
Jiri Borovec committed
279 280
            expt.run(iter_var='case', iter_vals=range(params['nb_runs']))
            # exp.run(iter_var='nb_labels', iter_vals=ptn_range)
Jiri Borovec's avatar
Jiri Borovec committed
281 282
        except:
            logging.error(traceback.format_exc())
283
        del expt
Jiri Borovec's avatar
Jiri Borovec committed
284
        tqdm_bar.update(1)
Jiri Borovec's avatar
Jiri Borovec committed
285
        gc.collect(), time.sleep(1)
Jiri Borovec's avatar
Jiri Borovec committed
286 287


Jiri Borovec's avatar
Jiri Borovec committed
288
def experiments_real(params=REAL_PARAMS):
Jiri Borovec's avatar
Jiri Borovec committed
289 290
    """ run all experiments

Jiri Borovec's avatar
Jiri Borovec committed
291
    :param nb_jobs: int
Jiri Borovec's avatar
Jiri Borovec committed
292
    :param params: {str: value}
Jiri Borovec's avatar
Jiri Borovec committed
293
    """
Jiri Borovec's avatar
Jiri Borovec committed
294
    arg_params = expt_apd.parse_params(params)
Jiri Borovec's avatar
Jiri Borovec committed
295 296
    logging.info('PARAMS: \n%s', '\n'.join(['"{}": \n\t {}'.format(k, v)
                                            for k, v in arg_params.iteritems()]))
Jiri Borovec's avatar
Jiri Borovec committed
297
    params.update(arg_params)
Jiri Borovec's avatar
Jiri Borovec committed
298

Jiri Borovec's avatar
Jiri Borovec committed
299
    l_params = [copy.deepcopy(params)]
Jiri Borovec's avatar
Jiri Borovec committed
300 301
    if isinstance(params['dataset'], list):
        l_params = expt_apd.extend_list_params(l_params, 'dataset', params['dataset'])
302
    l_params = expt_apd.extend_list_params(l_params, 'init_tp', INIT_TYPES)
Jiri Borovec's avatar
Jiri Borovec committed
303
    # l_params = expt_apd.extend_list_params(l_params, 'ptn_split', [True, False])
304
    l_params = expt_apd.extend_list_params(l_params, 'ptn_compact', [True, False])
Jiri Borovec's avatar
Jiri Borovec committed
305
    l_params = expt_apd.extend_list_params(l_params, 'gc_regul', GRAPHCUT_REGUL)
Jiri Borovec's avatar
Jiri Borovec committed
306
    # l_params = expt_apd.extend_list_params(l_params, 'nb_labels',
Jiri Borovec's avatar
Jiri Borovec committed
307
    #                                           [5, 9, 12, 15, 20, 25, 30, 40])
Jiri Borovec's avatar
Jiri Borovec committed
308
    logging.debug('list params: %i', len(l_params))
Jiri Borovec's avatar
Jiri Borovec committed
309

Jiri Borovec's avatar
Jiri Borovec committed
310
    tqdm_bar = tqdm.tqdm(total=len(l_params))
Jiri Borovec's avatar
Jiri Borovec committed
311
    for params in l_params:
Jiri Borovec's avatar
Jiri Borovec committed
312 313
        if params['nb_jobs'] > 1:
            expt = ExperimentAPDL(params, params['nb_jobs'])
Jiri Borovec's avatar
Jiri Borovec committed
314
        else:
315
            expt = ExperimentAPDL_base(params)
Jiri Borovec's avatar
Jiri Borovec committed
316
        # exp.run(gt=False, iter_var='case', iter_values=range(params['nb_runs']))
Jiri Borovec's avatar
Jiri Borovec committed
317
        expt.run(gt=False, iter_var='nb_labels', iter_vals=NB_PATTERNS_REAL)
318
        del expt
Jiri Borovec's avatar
Jiri Borovec committed
319
        tqdm_bar.update(1)
Jiri Borovec's avatar
Jiri Borovec committed
320
        gc.collect(), time.sleep(1)
Jiri Borovec's avatar
Jiri Borovec committed
321 322


Jiri Borovec's avatar
Jiri Borovec committed
323
def main():
Jiri Borovec's avatar
Jiri Borovec committed
324
    logging.basicConfig(level=logging.DEBUG)
Jiri Borovec's avatar
Jiri Borovec committed
325
    logging.info('running...')
Jiri Borovec's avatar
Jiri Borovec committed
326 327 328

    # test_encoding(atlas, imgs, encoding)
    # test_atlasLearning(atlas, imgs, encoding)
Jiri Borovec's avatar
Jiri Borovec committed
329
    # experiments_test()
Jiri Borovec's avatar
Jiri Borovec committed
330
    # plt.show()
Jiri Borovec's avatar
Jiri Borovec committed
331

Jiri Borovec's avatar
Jiri Borovec committed
332 333 334 335 336
    arg_params = expt_apd.parse_params(SYNTH_PARAMS)
    if arg_params['type'] == 'synth':
        experiments_synthetic()
    elif arg_params['type'] == 'real':
        experiments_real()
Jiri Borovec's avatar
Jiri Borovec committed
337

Jiri Borovec's avatar
Jiri Borovec committed
338
    logging.info('DONE')
Jiri Borovec's avatar
Jiri Borovec committed
339 340 341 342


if __name__ == "__main__":
    main()