Exemplo n.º 1
0
def get_default_args():
    summary_args = utils.Foo(display_interval=1,
                             test_iters=26,
                             arop_full_summary_iters=14)

    control_args = utils.Foo(train=False,
                             test=False,
                             force_batchnorm_is_training_at_test=False,
                             reset_rng_seed=False,
                             only_eval_when_done=False,
                             test_mode=None)
    return summary_args, control_args
Exemplo n.º 2
0
def get_default_cmp_args():
    batch_norm_param = {
        'center': True,
        'scale': True,
        'activation_fn': tf.nn.relu
    }

    mapper_arch_args = utils.Foo(dim_reduce_neurons=64,
                                 fc_neurons=[1024, 1024],
                                 fc_out_size=8,
                                 fc_out_neurons=64,
                                 encoder='resnet_v2_50',
                                 deconv_neurons=[64, 32, 16, 8, 4, 2],
                                 deconv_strides=[2, 2, 2, 2, 2, 2],
                                 deconv_layers_per_block=2,
                                 deconv_kernel_size=4,
                                 fc_dropout=0.5,
                                 combine_type='wt_avg_logits',
                                 batch_norm_param=batch_norm_param)

    readout_maps_arch_args = utils.Foo(num_neurons=[],
                                       strides=[],
                                       kernel_size=None,
                                       layers_per_block=None)

    arch_args = utils.Foo(vin_val_neurons=8,
                          vin_action_neurons=8,
                          vin_ks=3,
                          vin_share_wts=False,
                          pred_neurons=[64, 64],
                          pred_batch_norm_param=batch_norm_param,
                          conv_on_value_map=0,
                          fr_neurons=16,
                          fr_ver='v2',
                          fr_inside_neurons=64,
                          fr_stride=1,
                          crop_remove_each=30,
                          value_crop_size=4,
                          action_sample_type='sample',
                          action_sample_combine_type='one_or_other',
                          sample_gt_prob_type='inverse_sigmoid_decay',
                          dagger_sample_bn_false=True,
                          vin_num_iters=36,
                          isd_k=750.,
                          use_agent_loc=False,
                          multi_scale=True,
                          readout_maps=False,
                          rom_arch=readout_maps_arch_args)

    return arch_args, mapper_arch_args
Exemplo n.º 3
0
def get_arch_vars(arch_str):
    if arch_str == '':
        vals = []
    else:
        vals = arch_str.split('_')
    ks = ['var1', 'var2', 'var3']
    ks = ks[:len(vals)]

    # Exp Ver.
    if len(vals) == 0:
        ks.append('var1')
        vals.append('v0')
    # custom arch.
    if len(vals) == 1:
        ks.append('var2')
        vals.append('')
    # map scape for projection baseline.
    if len(vals) == 2:
        ks.append('var3')
        vals.append('fr2')

    assert (len(vals) == 3)

    vars = utils.Foo()
    for k, v in zip(ks, vals):
        setattr(vars, k, v)

    logging.error('arch_vars: %s', vars)
    return vars
Exemplo n.º 4
0
def get_args_for_config(config_name):
    args = utils.Foo()

    args.summary, args.control = get_default_args()

    exp_name, mode_str = config_name.split('+')
    arch_str, solver_str, navtask_str = exp_name.split('.')
    logging.error('config_name: %s', config_name)
    logging.error('arch_str: %s', arch_str)
    logging.error('navtask_str: %s', navtask_str)
    logging.error('solver_str: %s', solver_str)
    logging.error('mode_str: %s', mode_str)

    args.solver = cc.process_solver_str(solver_str)
    args.navtask = cc.process_navtask_str(navtask_str)

    args = process_arch_str(args, arch_str)
    args.arch.isd_k = args.solver.isd_k

    # Train, test, etc.
    mode, imset = mode_str.split('_')
    args = cc.adjust_args_for_mode(args, mode)
    args.navtask.building_names = args.navtask.dataset.get_split(imset)
    args.control.test_name = '{:s}_on_{:s}'.format(mode, imset)

    # Log the arguments
    logging.error('%s', args)
    return args
Exemplo n.º 5
0
def get_default_baseline_args():
    batch_norm_param = {
        'center': True,
        'scale': True,
        'activation_fn': tf.nn.relu
    }
    arch_args = utils.Foo(pred_neurons=[],
                          goal_embed_neurons=[],
                          img_embed_neurons=[],
                          batch_norm_param=batch_norm_param,
                          dim_reduce_neurons=64,
                          combine_type='',
                          encoder='resnet_v2_50',
                          action_sample_type='sample',
                          action_sample_combine_type='one_or_other',
                          sample_gt_prob_type='inverse_sigmoid_decay',
                          dagger_sample_bn_false=True,
                          isd_k=750.,
                          use_visit_count=False,
                          lstm_output=False,
                          lstm_ego=False,
                          lstm_img=False,
                          fc_dropout=0.0,
                          embed_goal_for_state=False,
                          lstm_output_init_state_from_goal=False)
    return arch_args
Exemplo n.º 6
0
def process_arch_projected_map(args, arch_vars):
    # Single scale vision based system which does not use a mapper but instead
    # uses an analytically estimated map.
    ds = int(arch_vars.var3[2])
    args.navtask.task_params.input_type = 'analytical_counts'
    args.navtask.task_params.outputs.analytical_counts = True

    assert (args.navtask.task_params.modalities[0] == 'depth')
    args.navtask.camera_param.img_channels = None

    analytical_counts = utils.Foo(map_sizes=[512 / ds],
                                  xy_resolution=[5. * ds],
                                  z_bins=[[-10, 10, 150, 200]],
                                  non_linearity=[arch_vars.var2])
    args.navtask.task_params.analytical_counts = analytical_counts

    sc = 1. / ds
    args.arch.vin_num_iters = 36
    args.navtask.task_params.map_scales = [sc]
    args.navtask.task_params.map_crop_sizes = [512 / ds]

    args.arch.fr_stride = [1, 2]
    args.arch.vin_action_neurons = 8
    args.arch.vin_val_neurons = 3
    args.arch.fr_inside_neurons = 32

    map_channels = len(analytical_counts.z_bins[0]) + 1
    args.navtask.task_params.map_channels = map_channels
    args.solver.freeze_conv = False

    return args
Exemplo n.º 7
0
def adjust_args_for_mode(args, mode):
    if mode == 'train':
        args.control.train = True

    elif mode == 'val1':
        # Same settings as for training, to make sure nothing wonky is happening
        # there.
        args.control.test = True
        args.control.test_mode = 'val'
        args.navtask.task_params.batch_size = 32

    elif mode == 'val2':
        # No data augmentation, not sampling but taking the argmax action, not
        # sampling from the ground truth at all.
        args.control.test = True
        args.arch.action_sample_type = 'argmax'
        args.arch.sample_gt_prob_type = 'zero'
        args.navtask.task_params.data_augment = \
            utils.Foo(lr_flip=0, delta_angle=0, delta_xy=0, relight=False,
                      relight_fast=False, structured=False)
        args.control.test_mode = 'val'
        args.navtask.task_params.batch_size = 32

    elif mode == 'bench':
        # Actually testing the agent in settings that are kept same between
        # different runs.
        args.navtask.task_params.batch_size = 16
        args.control.test = True
        args.arch.action_sample_type = 'argmax'
        args.arch.sample_gt_prob_type = 'zero'
        args.navtask.task_params.data_augment = \
            utils.Foo(lr_flip=0, delta_angle=0, delta_xy=0, relight=False,
                      relight_fast=False, structured=False)
        args.summary.test_iters = 250
        args.control.only_eval_when_done = True
        args.control.reset_rng_seed = True
        args.control.test_mode = 'test'
    else:
        logging.fatal('Unknown mode: %s.', mode)
        assert False
    return args
Exemplo n.º 8
0
def get_solver_vars(solver_str):
    if solver_str == '':
        vals = []
    else:
        vals = solver_str.split('_')
    ks = ['clip', 'dlw', 'long', 'typ', 'isdk', 'adam_eps', 'init_lr']
    ks = ks[:len(vals)]

    # Gradient clipping or not.
    if len(vals) == 0:
        ks.append('clip')
        vals.append('noclip')
    # data loss weight.
    if len(vals) == 1:
        ks.append('dlw')
        vals.append('dlw20')
    # how long to train for.
    if len(vals) == 2:
        ks.append('long')
        vals.append('nolong')
    # Adam
    if len(vals) == 3:
        ks.append('typ')
        vals.append('adam2')
    # reg loss wt
    if len(vals) == 4:
        ks.append('rlw')
        vals.append('rlw1')
    # isd_k
    if len(vals) == 5:
        ks.append('isdk')
        vals.append('isdk415')  # 415, inflexion at 2.5k.
    # adam eps
    if len(vals) == 6:
        ks.append('adam_eps')
        vals.append('aeps1en8')
    # init lr
    if len(vals) == 7:
        ks.append('init_lr')
        vals.append('lr1en3')
    assert (len(vals) == 8)

    vars = utils.Foo()
    for k, v in zip(ks, vals):
        setattr(vars, k, v)
    logging.error('solver_vars: %s', vars)
    return vars
Exemplo n.º 9
0
def get_arch_vars(arch_str):
    if arch_str == '':
        vals = []
    else:
        vals = arch_str.split('_')

    ks = ['ver', 'lstm_dim', 'dropout']

    # Exp Ver
    if len(vals) == 0: vals.append('v0')
    # LSTM dimentsions
    if len(vals) == 1: vals.append('lstm2048')
    # Dropout
    if len(vals) == 2: vals.append('noDO')

    assert (len(vals) == 3)

    vars = utils.Foo()
    for k, v in zip(ks, vals):
        setattr(vars, k, v)

    logging.error('arch_vars: %s', vars)
    return vars
Exemplo n.º 10
0
def nav_env_base_config():
    """Returns the base config for stanford navigation environment.

  Returns:
    Base config for stanford navigation environment.
  """
    robot = utils.Foo(radius=15,
                      base=10,
                      height=140,
                      sensor_height=120,
                      camera_elevation_degree=-15)

    env = utils.Foo(padding=10,
                    resolution=5,
                    num_point_threshold=2,
                    valid_min=-10,
                    valid_max=200,
                    n_samples_per_face=200)

    camera_param = utils.Foo(width=225,
                             height=225,
                             z_near=0.05,
                             z_far=20.0,
                             fov=60.,
                             modalities=['rgb'],
                             img_channels=3)

    data_augment = utils.Foo(
        lr_flip=0,
        delta_angle=0.5,
        delta_xy=4,
        relight=True,
        relight_fast=False,
        structured=False
    )  # if True, uses the same perturb for the whole episode.

    outputs = utils.Foo(images=True,
                        rel_goal_loc=False,
                        loc_on_map=True,
                        gt_dist_to_goal=True,
                        ego_maps=False,
                        ego_goal_imgs=False,
                        egomotion=False,
                        visit_count=False,
                        analytical_counts=False,
                        node_ids=True,
                        readout_maps=False)

    # class_map_names=['board', 'chair', 'door', 'sofa', 'table']
    class_map_names = ['chair', 'door', 'table']
    semantic_task = utils.Foo(class_map_names=class_map_names,
                              pix_distance=16,
                              sampling='uniform')

    # time per iteration for cmp is 0.82 seconds per episode with 3.4s overhead per batch.
    task_params = utils.Foo(max_dist=32,
                            step_size=8,
                            num_steps=40,
                            num_actions=4,
                            batch_size=4,
                            building_seed=0,
                            num_goals=1,
                            img_height=None,
                            img_width=None,
                            img_channels=None,
                            modalities=None,
                            outputs=outputs,
                            map_scales=[1.],
                            map_crop_sizes=[64],
                            rel_goal_loc_dim=4,
                            base_class='Building',
                            task='map+plan',
                            n_ori=4,
                            type='room_to_room_many',
                            data_augment=data_augment,
                            room_regex='^((?!hallway).)*$',
                            toy_problem=False,
                            map_channels=1,
                            gt_coverage=False,
                            input_type='maps',
                            full_information=False,
                            aux_delta_thetas=[],
                            semantic_task=semantic_task,
                            num_history_frames=0,
                            node_ids_dim=1,
                            perturbs_dim=4,
                            map_resize_method='linear_noantialiasing',
                            readout_maps_channels=1,
                            readout_maps_scales=[],
                            readout_maps_crop_sizes=[],
                            n_views=1,
                            reward_time_penalty=0.1,
                            reward_at_goal=1.,
                            discount_factor=0.99,
                            rejection_sampling_M=100,
                            min_dist=None)

    navtask_args = utils.Foo(
        building_names=['area1_gates_wingA_floor1_westpart'],
        env_class=nav_env.VisualNavigationEnv,
        robot=robot,
        task_params=task_params,
        env=env,
        camera_param=camera_param,
        cache_rooms=True)
    return navtask_args
Exemplo n.º 11
0
def get_default_args():
    robot = utils.Foo(radius=15,
                      base=10,
                      height=140,
                      sensor_height=120,
                      camera_elevation_degree=-15)

    camera_param = utils.Foo(width=225,
                             height=225,
                             z_near=0.05,
                             z_far=20.0,
                             fov=60.,
                             modalities=['rgb', 'depth'])

    env = utils.Foo(padding=10,
                    resolution=5,
                    num_point_threshold=2,
                    valid_min=-10,
                    valid_max=200,
                    n_samples_per_face=200)

    data_augment = utils.Foo(lr_flip=0,
                             delta_angle=1,
                             delta_xy=4,
                             relight=False,
                             relight_fast=False,
                             structured=False)

    task_params = utils.Foo(num_actions=4,
                            step_size=4,
                            num_steps=0,
                            batch_size=32,
                            room_seed=0,
                            base_class='Building',
                            task='mapping',
                            n_ori=6,
                            data_augment=data_augment,
                            output_transform_to_global_map=False,
                            output_canonical_map=False,
                            output_incremental_transform=False,
                            output_free_space=False,
                            move_type='shortest_path',
                            toy_problem=0)

    buildinger_args = utils.Foo(
        building_names=['area1_gates_wingA_floor1_westpart'],
        env_class=None,
        robot=robot,
        task_params=task_params,
        env=env,
        camera_param=camera_param)

    solver_args = utils.Foo(seed=0,
                            learning_rate_decay=0.1,
                            clip_gradient_norm=0,
                            max_steps=120000,
                            initial_learning_rate=0.001,
                            momentum=0.99,
                            steps_per_decay=40000,
                            logdir=None,
                            sync=False,
                            adjust_lr_sync=True,
                            wt_decay=0.0001,
                            data_loss_wt=1.0,
                            reg_loss_wt=1.0,
                            num_workers=1,
                            task=0,
                            ps_tasks=0,
                            master='local')

    summary_args = utils.Foo(display_interval=1, test_iters=100)

    control_args = utils.Foo(train=False,
                             test=False,
                             force_batchnorm_is_training_at_test=False)

    arch_args = utils.Foo(rgb_encoder='resnet_v2_50', d_encoder='resnet_v2_50')

    return utils.Foo(solver=solver_args,
                     summary=summary_args,
                     control=control_args,
                     arch=arch_args,
                     buildinger=buildinger_args)
Exemplo n.º 12
0
def get_navtask_vars(navtask_str):
    if navtask_str == '':
        vals = []
    else:
        vals = navtask_str.split('_')

    ks_all = [
        'dataset_name', 'modality', 'task', 'history', 'max_dist', 'num_steps',
        'step_size', 'n_ori', 'aux_views', 'data_aug'
    ]
    ks = ks_all[:len(vals)]

    # All data or not.
    if len(vals) == 0:
        ks.append('dataset_name')
        vals.append('sbpd')
    # modality
    if len(vals) == 1:
        ks.append('modality')
        vals.append('rgb')
    # semantic task?
    if len(vals) == 2:
        ks.append('task')
        vals.append('r2r')
    # number of history frames.
    if len(vals) == 3:
        ks.append('history')
        vals.append('h0')
    # max steps
    if len(vals) == 4:
        ks.append('max_dist')
        vals.append('32')
    # num steps
    if len(vals) == 5:
        ks.append('num_steps')
        vals.append('40')
    # step size
    if len(vals) == 6:
        ks.append('step_size')
        vals.append('8')
    # n_ori
    if len(vals) == 7:
        ks.append('n_ori')
        vals.append('4')
    # Auxiliary views.
    if len(vals) == 8:
        ks.append('aux_views')
        vals.append('nv0')
    # Normal data augmentation as opposed to structured data augmentation (if set
    # to straug.
    if len(vals) == 9:
        ks.append('data_aug')
        vals.append('straug')

    assert (len(vals) == 10)
    for i in range(len(ks)):
        assert (ks[i] == ks_all[i])

    vars = utils.Foo()
    for k, v in zip(ks, vals):
        setattr(vars, k, v)
    logging.error('navtask_vars: %s', vals)
    return vars
Exemplo n.º 13
0
def process_solver_str(solver_str):
    solver = utils.Foo(seed=0,
                       learning_rate_decay=None,
                       clip_gradient_norm=None,
                       max_steps=None,
                       initial_learning_rate=None,
                       momentum=None,
                       steps_per_decay=None,
                       logdir=None,
                       sync=False,
                       adjust_lr_sync=True,
                       wt_decay=0.0001,
                       data_loss_wt=None,
                       reg_loss_wt=None,
                       freeze_conv=True,
                       num_workers=1,
                       task=0,
                       ps_tasks=0,
                       master='local',
                       typ=None,
                       momentum2=None,
                       adam_eps=None)

    # Clobber with overrides from solver str.
    solver_vars = get_solver_vars(solver_str)

    solver.data_loss_wt = float(solver_vars.dlw[3:].replace('x', '.'))
    solver.adam_eps = float(solver_vars.adam_eps[4:].replace('x', '.').replace(
        'n', '-'))
    solver.initial_learning_rate = float(solver_vars.init_lr[2:].replace(
        'x', '.').replace('n', '-'))
    solver.reg_loss_wt = float(solver_vars.rlw[3:].replace('x', '.'))
    solver.isd_k = float(solver_vars.isdk[4:].replace('x', '.'))

    long = solver_vars.long
    if long == 'long':
        solver.steps_per_decay = 40000
        solver.max_steps = 120000
    elif long == 'long2':
        solver.steps_per_decay = 80000
        solver.max_steps = 120000
    elif long == 'nolong' or long == 'nol':
        solver.steps_per_decay = 20000
        solver.max_steps = 60000
    else:
        logging.fatal('solver_vars.long should be long, long2, nolong or nol.')
        assert False

    clip = solver_vars.clip
    if clip == 'noclip' or clip == 'nocl':
        solver.clip_gradient_norm = 0
    elif clip[:4] == 'clip':
        solver.clip_gradient_norm = float(clip[4:].replace('x', '.'))
    else:
        logging.fatal('Unknown solver_vars.clip: %s', clip)
        assert False

    typ = solver_vars.typ
    if typ == 'adam':
        solver.typ = 'adam'
        solver.momentum = 0.9
        solver.momentum2 = 0.999
        solver.learning_rate_decay = 1.0
    elif typ == 'adam2':
        solver.typ = 'adam'
        solver.momentum = 0.9
        solver.momentum2 = 0.999
        solver.learning_rate_decay = 0.1
    elif typ == 'sgd':
        solver.typ = 'sgd'
        solver.momentum = 0.99
        solver.momentum2 = None
        solver.learning_rate_decay = 0.1
    else:
        logging.fatal('Unknown solver_vars.typ: %s', typ)
        assert False

    logging.error('solver: %s', solver)
    return solver