def get_resnet18_inst_and_depth(which_encode_to_depth=9, depth_dataset_list=['pbrnet', 'scenenet']): ret_cfg = { "BATCH_SIZE": 8, "QUEUE_CAP": 2560, "network_list": ["encode", "up_projection", "depth", "category"], "imagenet_order": ["encode", "category"] } for depth_dataset in depth_dataset_list: order_name = '%s_order' % depth_dataset ret_cfg[order_name] = ["encode", "up_projection", "depth"] # Add encode ret_cfg["encode"] = shared_funcs.get_encode_resnet( func_kwargs={'num_layers': [2, 2, 2, 2]}) num_layers_enc = len(ret_cfg["encode"].keys()) ret_cfg["encode_depth"] = num_layers_enc # Add category here ret_cfg["category"] = shared_funcs.get_category( 128, "encode_%i" % num_layers_enc) ret_cfg["category_depth"] = 2 if which_encode_to_depth == 9: ret_cfg = other_tasks.add_depth_head( ret_cfg, 'encode_%i' % which_encode_to_depth) elif which_encode_to_depth == 7: ret_cfg = other_tasks.add_depth_head(ret_cfg, 'encode_%i' % which_encode_to_depth, first_upproj_filter=128, no_upproj_layers=3) else: raise NotImplementedError() return ret_cfg
def get_resnet_18_fx_encdX(no_layers_fixed=3): ret_cfg = { "BATCH_SIZE": 8, "QUEUE_CAP": 2560, "network_list": ["inst_encode", "inst_category"], "imagenet_order": ["inst_encode", "inst_category"], } # Add inst_encode here ret_cfg["inst_encode"] = shared_funcs.get_encode_resnet( func_kwargs={'num_layers': [2, 2, 2, 2]}) num_layers_enc = len(ret_cfg["inst_encode"].keys()) ret_cfg["inst_encode_depth"] = num_layers_enc # Add inst_category here ret_cfg["inst_category"] = shared_funcs.get_category( 128, "inst_encode_%i" % num_layers_enc) ret_cfg["inst_category_depth"] = 2 assert no_layers_fixed >= 1 ret_cfg["inst_encode"][1]["conv"]["trainable"] = 0 ret_cfg["inst_encode"][1]["conv"]["bn_trainable"] = 0 for idx_layer in range(2, no_layers_fixed + 1): ret_cfg["inst_encode"][idx_layer]["ResBlock_trainable"] = 0 ret_cfg["inst_encode"][idx_layer]["ResBlock_bn_trainable"] = 0 return ret_cfg
def get_rp_inst_resnet_18(dataset_prefix='rp_imagenet', rp_layer_offset=0): ret_cfg = { "BATCH_SIZE": 8, "QUEUE_CAP": 2560, "network_list": ["encode", "encode_head", "rp_category", "category"], "%s_order" % dataset_prefix: ["encode", "encode_head"], "imagenet_order": ["encode", "category"], } # Add encode ret_cfg["encode"] = shared_funcs.get_encode_resnet( func_kwargs={'num_layers': [2, 2, 2, 2]}) num_layers_enc = len(ret_cfg["encode"].keys()) ret_cfg["encode_depth"] = num_layers_enc # Add encode_head ret_cfg["encode_head"] = other_tasks.get_rp_resnet_18_encode_head( "encode_%i" % (num_layers_enc - rp_layer_offset)) ret_cfg["encode_head_depth"] = 2 # Add rp_category ret_cfg["rp_category"] = other_tasks.get_rp_resnet_18_rp_category() ret_cfg["rp_category_depth"] = 4 # Add category here ret_cfg["category"] = shared_funcs.get_category( 128, "encode_%i" % num_layers_enc) ret_cfg["category_depth"] = 2 return ret_cfg
def get_cpc_resnet_18(dataset_prefix='imagenet'): ret_cfg = { "BATCH_SIZE": 8, "QUEUE_CAP": 2560, "network_list": ["encode"], "%s_order" % dataset_prefix: ["encode"], } # Add encode ret_cfg["encode"] = shared_funcs.get_encode_resnet( func_kwargs={'num_layers': [2, 2, 2, 2]}) num_layers_enc = len(ret_cfg["encode"].keys()) ret_cfg["encode_depth"] = num_layers_enc ret_cfg["encode"]["as_output"] = 1 return ret_cfg
def get_resnet_18_fx_encd1(): ret_cfg = { "BATCH_SIZE": 8, "QUEUE_CAP": 2560, "network_list": ["inst_encode", "inst_category"], "imagenet_order": ["inst_encode", "inst_category"], } # Add inst_encode here ret_cfg["inst_encode"] = shared_funcs.get_encode_resnet( func_kwargs={'num_layers': [2, 2, 2, 2]}) num_layers_enc = len(ret_cfg["inst_encode"].keys()) ret_cfg["inst_encode_depth"] = num_layers_enc # Add inst_category here ret_cfg["inst_category"] = shared_funcs.get_category( 128, "inst_encode_%i" % num_layers_enc) ret_cfg["inst_category_depth"] = 2 ret_cfg["inst_encode"][1]["conv"]["trainable"] = 0 return ret_cfg
def get_rp_resnet_18_bg(dataset_prefix='rp_imagenet'): ret_cfg = { "BATCH_SIZE": 8, "QUEUE_CAP": 2560, "network_list": ["encode", "encode_head", "rp_category"], "%s_order" % dataset_prefix: ["encode", "encode_head"], } # Add encode ret_cfg["encode"] = shared_funcs.get_encode_resnet( func_kwargs={'num_layers': [2, 2, 2, 2]}) num_layers_enc = len(ret_cfg["encode"].keys()) ret_cfg["encode_depth"] = num_layers_enc # Add encode_head ret_cfg["encode_head"] = get_rp_resnet_18_encode_head_bg("encode_%i" % num_layers_enc) ret_cfg["encode_head_depth"] = 2 # Add rp_category ret_cfg["rp_category"] = get_rp_resnet_18_rp_category_bg() ret_cfg["rp_category_depth"] = 4 return ret_cfg
def get_ae_resnet_18(dataset_prefix='imagenet', head_dim=128): ret_cfg = { "BATCH_SIZE": 8, "QUEUE_CAP": 2560, "network_list": ["encode", "ae_head", "ae_decode", "ae_output"], "%s_order" % dataset_prefix: ["encode", "ae_head", "ae_decode", "ae_output"], } # Add encode ret_cfg["encode"] = shared_funcs.get_encode_resnet( func_kwargs={'num_layers': [2, 2, 2, 2]}) num_layers_enc = len(ret_cfg["encode"].keys()) ret_cfg["encode_depth"] = num_layers_enc ret_cfg["ae_head"] = { "input": "encode_%i" % num_layers_enc, 1: { "ae_head": { "dimension": head_dim } }, } ret_cfg["ae_head_depth"] = 1 ae_decode = {"input": "ae_head_1"} for idx in range(1, num_layers_enc): curr_encode = ret_cfg["encode"][num_layers_enc + 1 - idx] curr_resblock = copy.deepcopy(curr_encode["ResBlock"]) curr_resblock = list(reversed(curr_resblock)) for each_conv in curr_resblock: each_conv["upsample"] = each_conv["stride"] curr_decode = {"ResBlock": curr_resblock} ae_decode[idx] = curr_decode ret_cfg["ae_decode"] = ae_decode ret_cfg["ae_decode_depth"] = num_layers_enc - 1 ret_cfg["ae_output"] = { "input": "ae_decode_%i" % (num_layers_enc - 1), "as_output": 1, 1: { "conv": { "filter_size": 3, "stride": 2, "num_filters": 3, "upsample": 2 } }, 2: { "conv": { "filter_size": 7, "stride": 2, "num_filters": 3, "output": 1, "upsample": 2 } }, } ret_cfg["ae_output_depth"] = 2 return ret_cfg