In [1]:
!pip install oyaml


Requirement already satisfied: oyaml in /home/femianjc/anaconda3/lib/python3.6/site-packages (0.5)
Requirement already satisfied: pyyaml in /home/femianjc/anaconda3/lib/python3.6/site-packages (from oyaml) (3.12)

In [2]:
""" Generate modules for all combinations of settings we plan to test.

"""
from collections import OrderedDict
import itertools
import pandas as pd

# List options in the order that you want to test.
# Put the hypothetical best values first; that way 
# the first experments will assume the best values
# for all options

OPTIONS = OrderedDict()  # for python2 compatability

OPTIONS['FUSION'] = ['early_fusion', 'late_fusion_add', 'late_fusion_cat']

OPTIONS['OBB_PARAMETRIZATION'] = [ 'vector_and_width', 'angle_length_width', 'four_points', 'two_vectors']

OPTIONS['SYNTHETIC'] = ['no_pretrain', 'pretrain']

OPTIONS['CHANNEL_DROPOUT'] = ['cdrop', 'no_cdrop']

OPTIONS['CLASS_LOSS'] = ['hinge_loss', 'xent_loss']

OPTIONS['REGRESSION_LOSS'] = ['smooth_L1', 'L2']

OPTIONS['AUG_JITTER'] = ['no_jitter', 'jitter']


COMBOS = [ reversed(combo) for combo in itertools.product(*reversed(OPTIONS.values()))]

In [6]:
ops = list(OPTIONS.values())

In [7]:
sum([len(ops[i])*len(ops[i+1]) for i in range(len(OPTIONS.values())-1)])


Out[7]:
36

In [ ]:


In [96]:
EXPERIMENTS = pd.DataFrame(COMBOS, columns=OPTIONS.keys())
EXPERIMENTS


Out[96]:
FUSION OBB_PARAMETRIZATION SYNTHETIC CHANNEL_DROPOUT CLASS_LOSS REGRESSION_LOSS AUG_JITTER
0 early_fusion vector_and_width no_pretrain cdrop hinge_loss smooth_L1 no_jitter
1 late_fusion_add vector_and_width no_pretrain cdrop hinge_loss smooth_L1 no_jitter
2 late_fusion_cat vector_and_width no_pretrain cdrop hinge_loss smooth_L1 no_jitter
3 early_fusion angle_length_width no_pretrain cdrop hinge_loss smooth_L1 no_jitter
4 late_fusion_add angle_length_width no_pretrain cdrop hinge_loss smooth_L1 no_jitter
5 late_fusion_cat angle_length_width no_pretrain cdrop hinge_loss smooth_L1 no_jitter
6 early_fusion four_points no_pretrain cdrop hinge_loss smooth_L1 no_jitter
7 late_fusion_add four_points no_pretrain cdrop hinge_loss smooth_L1 no_jitter
8 late_fusion_cat four_points no_pretrain cdrop hinge_loss smooth_L1 no_jitter
9 early_fusion two_vectors no_pretrain cdrop hinge_loss smooth_L1 no_jitter
10 late_fusion_add two_vectors no_pretrain cdrop hinge_loss smooth_L1 no_jitter
11 late_fusion_cat two_vectors no_pretrain cdrop hinge_loss smooth_L1 no_jitter
12 early_fusion vector_and_width pretrain cdrop hinge_loss smooth_L1 no_jitter
13 late_fusion_add vector_and_width pretrain cdrop hinge_loss smooth_L1 no_jitter
14 late_fusion_cat vector_and_width pretrain cdrop hinge_loss smooth_L1 no_jitter
15 early_fusion angle_length_width pretrain cdrop hinge_loss smooth_L1 no_jitter
16 late_fusion_add angle_length_width pretrain cdrop hinge_loss smooth_L1 no_jitter
17 late_fusion_cat angle_length_width pretrain cdrop hinge_loss smooth_L1 no_jitter
18 early_fusion four_points pretrain cdrop hinge_loss smooth_L1 no_jitter
19 late_fusion_add four_points pretrain cdrop hinge_loss smooth_L1 no_jitter
20 late_fusion_cat four_points pretrain cdrop hinge_loss smooth_L1 no_jitter
21 early_fusion two_vectors pretrain cdrop hinge_loss smooth_L1 no_jitter
22 late_fusion_add two_vectors pretrain cdrop hinge_loss smooth_L1 no_jitter
23 late_fusion_cat two_vectors pretrain cdrop hinge_loss smooth_L1 no_jitter
24 early_fusion vector_and_width no_pretrain no_cdrop hinge_loss smooth_L1 no_jitter
25 late_fusion_add vector_and_width no_pretrain no_cdrop hinge_loss smooth_L1 no_jitter
26 late_fusion_cat vector_and_width no_pretrain no_cdrop hinge_loss smooth_L1 no_jitter
27 early_fusion angle_length_width no_pretrain no_cdrop hinge_loss smooth_L1 no_jitter
28 late_fusion_add angle_length_width no_pretrain no_cdrop hinge_loss smooth_L1 no_jitter
29 late_fusion_cat angle_length_width no_pretrain no_cdrop hinge_loss smooth_L1 no_jitter
... ... ... ... ... ... ... ...
354 early_fusion four_points pretrain cdrop xent_loss L2 jitter
355 late_fusion_add four_points pretrain cdrop xent_loss L2 jitter
356 late_fusion_cat four_points pretrain cdrop xent_loss L2 jitter
357 early_fusion two_vectors pretrain cdrop xent_loss L2 jitter
358 late_fusion_add two_vectors pretrain cdrop xent_loss L2 jitter
359 late_fusion_cat two_vectors pretrain cdrop xent_loss L2 jitter
360 early_fusion vector_and_width no_pretrain no_cdrop xent_loss L2 jitter
361 late_fusion_add vector_and_width no_pretrain no_cdrop xent_loss L2 jitter
362 late_fusion_cat vector_and_width no_pretrain no_cdrop xent_loss L2 jitter
363 early_fusion angle_length_width no_pretrain no_cdrop xent_loss L2 jitter
364 late_fusion_add angle_length_width no_pretrain no_cdrop xent_loss L2 jitter
365 late_fusion_cat angle_length_width no_pretrain no_cdrop xent_loss L2 jitter
366 early_fusion four_points no_pretrain no_cdrop xent_loss L2 jitter
367 late_fusion_add four_points no_pretrain no_cdrop xent_loss L2 jitter
368 late_fusion_cat four_points no_pretrain no_cdrop xent_loss L2 jitter
369 early_fusion two_vectors no_pretrain no_cdrop xent_loss L2 jitter
370 late_fusion_add two_vectors no_pretrain no_cdrop xent_loss L2 jitter
371 late_fusion_cat two_vectors no_pretrain no_cdrop xent_loss L2 jitter
372 early_fusion vector_and_width pretrain no_cdrop xent_loss L2 jitter
373 late_fusion_add vector_and_width pretrain no_cdrop xent_loss L2 jitter
374 late_fusion_cat vector_and_width pretrain no_cdrop xent_loss L2 jitter
375 early_fusion angle_length_width pretrain no_cdrop xent_loss L2 jitter
376 late_fusion_add angle_length_width pretrain no_cdrop xent_loss L2 jitter
377 late_fusion_cat angle_length_width pretrain no_cdrop xent_loss L2 jitter
378 early_fusion four_points pretrain no_cdrop xent_loss L2 jitter
379 late_fusion_add four_points pretrain no_cdrop xent_loss L2 jitter
380 late_fusion_cat four_points pretrain no_cdrop xent_loss L2 jitter
381 early_fusion two_vectors pretrain no_cdrop xent_loss L2 jitter
382 late_fusion_add two_vectors pretrain no_cdrop xent_loss L2 jitter
383 late_fusion_cat two_vectors pretrain no_cdrop xent_loss L2 jitter

384 rows × 7 columns


In [119]:
combo = EXPERIMENTS.iloc[10]

In [120]:
dict(combo)


Out[120]:
{'FUSION': 'late_fusion_add',
 'OBB_PARAMETRIZATION': 'two_vectors',
 'SYNTHETIC': 'no_pretrain',
 'CHANNEL_DROPOUT': 'cdrop',
 'CLASS_LOSS': 'hinge_loss',
 'REGRESSION_LOSS': 'smooth_L1',
 'AUG_JITTER': 'no_jitter'}

In [121]:
def save_options(f):
    for k, v in combo.items():
        print('{}: {}'.format(k,v), file=f)

import sys        
save_options(sys.stdout)


FUSION: late_fusion_add
OBB_PARAMETRIZATION: two_vectors
SYNTHETIC: no_pretrain
CHANNEL_DROPOUT: cdrop
CLASS_LOSS: hinge_loss
REGRESSION_LOSS: smooth_L1
AUG_JITTER: no_jitter

In [171]:
import oyaml as yaml
rec = OrderedDict()
rec['EXPERIMENT'] = combo.name
rec.update(combo)
print(yaml.dump(rec, default_flow_style=False))


EXPERIMENT: 10
FUSION: late_fusion_add
OBB_PARAMETRIZATION: two_vectors
SYNTHETIC: no_pretrain
CHANNEL_DROPOUT: cdrop
CLASS_LOSS: hinge_loss
REGRESSION_LOSS: smooth_L1
AUG_JITTER: no_jitter


In [140]:
import os
def make_relpath(combo):
    return '-'.join(('{:05}'.format(combo.name),)+ tuple(combo))

In [142]:
make_relpath(combo)


Out[142]:
'00010-late_fusion_add-two_vectors-no_pretrain-cdrop-hinge_loss-smooth_L1-no_jitter'

In [178]:
INT_DATA = '../data/interim/'

In [179]:
print(yaml.dump(OPTIONS))


FUSION: [early_fusion, late_fusion_add, late_fusion_cat]
OBB_PARAMETRIZATION: [vector_and_width, angle_length_width, four_points, two_vectors]
SYNTHETIC: [no_pretrain, pretrain]
CHANNEL_DROPOUT: [cdrop, no_cdrop]
CLASS_LOSS: [hinge_loss, xent_loss]
REGRESSION_LOSS: [smooth_L1, L2]
AUG_JITTER: [no_jitter, jitter]


In [192]:
from tqdm import tqdm

In [209]:
import oyaml as yaml

def make_experiments(options):
    # Save the options 
    with open(os.path.join(INT_DATA, 'options.yml'), 'w') as f:
        yaml.dump(options, f, default_flow_style=False)
        
    # Save the master list of experiments
    combos = [ reversed(combo) for combo in itertools.product(*reversed(options.values()))]
    experiments = pd.DataFrame(combos, columns=options.keys())
    experiments.to_csv(os.path.join(INT_DATA, 'experiments.csv'))
    
    # Make s folder and config file for each experiment
    for i, combo in tqdm(experiments.iterrows(), "generating configs"):
        dirname = '{:05}'.format(combo.name)

        rec = OrderedDict()
        rec['NUMBER'] = combo.name
        rec['NAME'] = '-'.join((dirname,)+ tuple(combo))
        rec.update(combo)
        
        os.makedirs(os.path.join(INT_DATA, 'experiments', dirname), exist_ok=True)
        with open(os.path.join(INT_DATA, 'experiments', dirname, 'config.yml'), 'w') as f:
            yaml.dump(rec, f, default_flow_style=False)

In [210]:
make_experiments(OPTIONS)


generating configs: 384it [00:00, 825.37it/s]

In [ ]: