Created
February 15, 2017 11:47
-
-
Save madratman/5b58cd75b8c766d48ca75fe917ac8ce0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_dilated(**kwargs): | |
# print kwargs['key'] | |
return "net['{0}'] = DilatedConv2DLayer(net['{1}'], num_filters={2}, filter_size={3}, dilation={4}, name='{0}')".format( | |
kwargs['curr_layer_name'], kwargs['prev_layer_name'], kwargs['num_filters'], kwargs['filter_size'], kwargs['dilation']) | |
def add_vanilla(**kwargs): | |
# print kwargs['key'] | |
return "net['{0}'] = ConvLayer(net['{1}'], num_filters={2}, filter_size={3}, pad={4}, name='{0}')".format( | |
kwargs['curr_layer_name'], kwargs['prev_layer_name'], kwargs['num_filters'], kwargs['filter_size'], kwargs['pad']) | |
def add_pad(**kwargs): | |
# print kwargs['key'] | |
return "net['{0}'] = PadLayer(net['{1}'], width={2}, val=0, name='{0}')".format( | |
kwargs['curr_layer_name'], kwargs['prev_layer_name'], kwargs['width']) | |
def add_pool(**kwargs): | |
return "net['{0}'] = PoolLayer(net['{1}'], 2, name='{0}')".format( | |
kwargs['curr_layer_name'], kwargs['prev_layer_name']) | |
def make_net(architecture_string, dilated_channels): | |
layers = architecture_string.split('+') | |
prev_layer_name = None | |
meta_string = [] | |
for (layer_idx, curr_layer) in enumerate(layers): | |
# details = curr_layer.split('_') | |
# num_filters = int([each_param[1:] for each_param in details if 'k' in each_param][0]) | |
# filter_size = int([each_param[1:] for each_param in details if 'f' in each_param][0]) | |
if layer_idx==0: | |
prev_layer_name = 'input' | |
if curr_layer[0] == 'k': | |
if 'f' in curr_layer: | |
params = curr_layer.split('_') | |
filter_size = int([each_param[1:] for each_param in params if 'f' in each_param][0]) | |
num_filters = int([each_param[1:] for each_param in params if 'k' in each_param][0]) | |
else: | |
filter_size = 3 | |
num_filters = int(curr_layer[1:]) | |
meta_string.append( | |
add_vanilla(curr_layer_name='conv{}'.format(layer_idx+1), | |
prev_layer_name=prev_layer_name, | |
num_filters=num_filters, | |
filter_size=filter_size, | |
pad="'same'")) | |
prev_layer_name = 'conv{}'.format(layer_idx+1) | |
if curr_layer[0] == 'p': | |
meta_string.append( | |
add_pool(curr_layer_name='pool{}'.format(layer_idx+1), prev_layer_name=prev_layer_name)) | |
prev_layer_name = 'pool{}'.format(layer_idx+1) | |
if curr_layer[0] == 'd': | |
meta_string.append( | |
add_pad(curr_layer_name='pad{}'.format(layer_idx+1), | |
prev_layer_name=prev_layer_name, | |
width=int(curr_layer[1:]))) | |
prev_layer_name = 'pad{}'.format(layer_idx+1) | |
meta_string.append( | |
add_dilated(curr_layer_name='dil_conv{}'.format(layer_idx+1), | |
prev_layer_name=prev_layer_name, | |
num_filters=dilated_channels, | |
filter_size=3, | |
dilation=int(curr_layer[1:]))) | |
prev_layer_name = 'dil_conv{}'.format(layer_idx+1) | |
outfile = open('temp_'+architecture_string+'.py', 'w') | |
outfile.write("\n".join(meta_string)) | |
return meta_string | |
if __name__ =="__main__": | |
# b = add_dilated(curr_layer_name="conv2", prev_layer_name="conv1", num_filters=32, filter_size=3, dilation=1) | |
# c = add_pad(curr_layer_name="conv2", prev_layer_name="conv1", width=1, val=0) | |
# a = add_vanilla(curr_layer_name="conv2", prev_layer_name="conv1", num_filters=32, filter_size=3, pad='same') | |
# d = add_pool(curr_layer_name="conv2", prev_layer_name="conv1") | |
# print a+b+c+d | |
# from pprint import pprint | |
# vgg like | |
make_net('k64+k64+p2+k128+k128+d1', 128) | |
make_net('k64+k64+p2+k128+k128+d1+d1', 128) | |
make_net('k64+k64+p2+k128+k128+d1+d1+d1', 128) | |
make_net('k64+k64+p2+k128+k128+d1+d1+d2+d1', 128) | |
make_net('k64+k64+p2+k128+k128+d1+d1+d2+d4+d1', 128) | |
make_net('k64+k64+p2+k128+k128+d1+d1+d2+d4+d8+d1', 128) | |
make_net('k64+k64+p2+k128+k128+d1+d1+d2+d4+d8+d16+d1', 128) | |
make_net('k32+k32', 32) | |
make_net('k32+k32+d1', 32) | |
make_net('k32+k32+d1+d1', 32) | |
make_net('k32+k32+d1+d1+d1', 32) | |
make_net('k32+k32+d1+d1+d2+d1', 32) | |
make_net('k32+k32+d1+d1+d2+d4+d1', 32) | |
make_net('k32+k32+d1+d1+d2+d4+d8+d1', 32) | |
make_net('k32+k32+d1+d1+d2+d4+d8+d16+d1', 32) | |
make_net('k32+k32+k32+k32', 32) | |
make_net('k32+k32+k32+k32+d1', 32) | |
make_net('k32+k32+k32+k32+d1+d1', 32) | |
make_net('k32+k32+k32+k32+d1+d1+d1', 32) | |
make_net('k32+k32+k32+k32+d1+d1+d2+d1', 32) | |
make_net('k32+k32+k32+k32+d1+d1+d2+d4+d1', 32) | |
make_net('k32+k32+k32+k32+d1+d1+d2+d4+d8+d1', 32) | |
make_net('k32+k32+k32+k32+d1+d1+d2+d4+d8+d16+d1', 32) | |
# icra like | |
make_net('k32+k32+k32+k32+k32+k32', 32) | |
make_net('k32+k32+k32+k32+k32+k32+d1', 32) | |
make_net('k32+k32+k32+k32+k32+k32+d1+d1', 32) | |
make_net('k32+k32+k32+k32+k32+k32+d1+d1+d1', 32) | |
make_net('k32+k32+k32+k32+k32+k32+d1+d1+d2+d1', 32) | |
make_net('k32+k32+k32+k32+k32+k32+d1+d1+d2+d4+d1', 32) | |
make_net('k32+k32+k32+k32+k32+k32+d1+d1+d2+d4+d8+d1', 32) | |
make_net('k32+k32+k32+k32+k32+k32+d1+d1+d2+d4+d8+d16+d1', 32) | |
make_net('k32+k32+k64+k64', 64) | |
make_net('k32+k32+k64+k64+d1', 64) | |
make_net('k32+k32+k64+k64+d1+d1', 64) | |
make_net('k32+k32+k64+k64+d1+d1+d1', 64) | |
make_net('k32+k32+k64+k64+d1+d1+d2+d1', 64) | |
make_net('k32+k32+k64+k64+d1+d1+d2+d4+d1', 64) | |
make_net('k32+k32+k64+k64+d1+d1+d2+d4+d8+d1', 64) | |
make_net('k32+k32+k64+k64+d1+d1+d2+d4+d8+d16+d1', 64) | |
make_net('k32+k32+k64+k64+k64+k64', 64) | |
make_net('k32+k32+k64+k64+k64+k64+d1', 64) | |
make_net('k32+k32+k64+k64+k64+k64+d1+d1', 64) | |
make_net('k32+k32+k64+k64+k64+k64+d1+d1+d1', 64) | |
make_net('k32+k32+k64+k64+k64+k64+d1+d1+d2+d1', 64) | |
make_net('k32+k32+k64+k64+k64+k64+d1+d1+d2+d4+d1', 64) | |
make_net('k32+k32+k64+k64+k64+k64+d1+d1+d2+d4+d8+d1', 64) | |
make_net('k32+k32+k64+k64+k64+k64+d1+d1+d2+d4+d8+d16+d1', 64) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment