def generate_mlp_architectures(class_or_reg='reg'): """ pylint: disable=bad-whitespace. """ # pylint: disable=bad-whitespace all_layer_label_classes = get_mlp_layer_labels(class_or_reg) last_layer_label = 'linear' if class_or_reg == 'reg' else 'softmax' # Network 1 layer_labels = [ 'ip', 'op', 'tanh', 'logistic', 'softplus', 'relu', 'elu', last_layer_label ] num_units_each_layer = [None, None, 32, 64, 16, 8, 8, None] A = get_dok_mat_with_set_coords(8, [(0, 4), (2, 3), (3, 7), (4, 5), (4, 6), (5, 2), (6, 2), (7, 1)]) mlp_1 = MultiLayerPerceptron(class_or_reg, layer_labels, A, num_units_each_layer, all_layer_label_classes) # Network 2 layer_labels = [ 'ip', 'softplus', 'elu', 'tanh', 'logistic', last_layer_label, 'op' ] num_units_each_layer = [None, 16, 16, 32, 64, None, None] A = get_dok_mat_with_set_coords(7, [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]) mlp_2 = MultiLayerPerceptron(class_or_reg, layer_labels, A, num_units_each_layer, all_layer_label_classes) # Network 3 layer_labels = [ 'ip', 'tanh', 'logistic', 'logistic', 'tanh', 'elu', 'relu', last_layer_label, 'op' ] num_units_each_layer = [None, 8, 8, 8, 8, 16, 16, None, None] A = get_dok_mat_with_set_coords(9, [(0, 1), (0, 2), (1, 3), (2, 4), (3, 5), (3, 6), (4, 5), (4, 6), (5, 7), (6, 7), (7, 8)]) mlp_3 = MultiLayerPerceptron(class_or_reg, layer_labels, A, num_units_each_layer, all_layer_label_classes) # Network 4 layer_labels = [ 'ip', 'logistic', 'relu', 'softplus', last_layer_label, 'op', 'relu', 'tanh' ] num_units_each_layer = [None, 8, 8, 16, None, None, 16, 8] A = get_dok_mat_with_set_coords(8, [(0, 1), (0, 7), (1, 2), (2, 3), (2, 6), (7, 6), (7, 3), (3, 4), (6, 4), (4, 5)]) mlp_4 = MultiLayerPerceptron(class_or_reg, layer_labels, A, num_units_each_layer, all_layer_label_classes) return [ mlp_1, mlp_2, mlp_3, mlp_4, get_blocked_mlp(class_or_reg, 4, 3), get_blocked_mlp(class_or_reg, 8, 2), get_multidepth_mlp_eg1(class_or_reg), get_multidepth_mlp_eg2(class_or_reg), ]
def get_multidepth_mlp_eg1(class_or_reg): """ Multi depth MLP eg 1. """ layer_labels, num_units_in_each_layer, edges, mlp_layer_labels = \ _get_multidepth_mlp_eg12_common(class_or_reg) conn_mat = get_dok_mat_with_set_coords(len(layer_labels), edges) return MultiLayerPerceptron(class_or_reg, layer_labels, conn_mat, num_units_in_each_layer, mlp_layer_labels)
def get_multidepth_cnn_eg1(): """ A network with 2 softmax layers mostly for debugging. """ layer_labels, edges, num_filters_each_layer, cnn_layer_labels, strides = \ _get_multidepth_cnn_eg12_common() edges.append((3, 4)) conn_mat = get_dok_mat_with_set_coords(len(layer_labels), edges) strides[9] = 2 return ConvNeuralNetwork(layer_labels, conn_mat, num_filters_each_layer, strides, cnn_layer_labels)
def generate_cnn_architectures(): # pylint: disable=bad-whitespace """ Generates 4 neural networks. """ all_layer_label_classes = get_cnn_layer_labels() # Network 1 layer_labels = [ 'ip', 'op', 'conv3', 'fc', 'conv3', 'conv3', 'conv3', 'softmax', 'max-pool' ] num_filters_each_layer = [None, None, 32, 16, 16, 8, 8, None, None] A = get_dok_mat_with_set_coords(9, [(0, 4), (3, 7), (4, 5), (4, 6), (5, 2), (6, 2), (7, 1), (2, 8), (8, 3)]) strides = [ None if ll in ['ip', 'op', 'fc', 'softmax', 'max-pool'] else 1 for ll in layer_labels ] cnn_1 = ConvNeuralNetwork(layer_labels, A, num_filters_each_layer, strides, all_layer_label_classes) # Network 2 layer_labels = [ 'ip', 'conv3', 'conv3', 'conv3', 'fc', 'softmax', 'op', 'max-pool' ] num_filters_each_layer = [None, 16, 16, 32, 16, None, None, None] A = get_dok_mat_with_set_coords(8, [(0, 1), (1, 2), (2, 3), (4, 5), (5, 6), (3, 7), (7, 4)]) strides = [ None if ll in ['ip', 'op', 'fc', 'softmax', 'max-pool'] else 1 for ll in layer_labels ] cnn_2 = ConvNeuralNetwork(layer_labels, A, num_filters_each_layer, strides, all_layer_label_classes) # Network 3 layer_labels = [ 'ip', 'conv3', 'conv3', 'conv5', 'conv3', 'max-pool', 'fc', 'softmax', 'op' ] num_filters_each_layer = [None, 16, 16, 16, 32, None, 32, None, None] A = get_dok_mat_with_set_coords(9, [(0, 1), (1, 2), (1, 3), (1, 4), (2, 5), (3, 5), (4, 6), (5, 6), (6, 7), (7, 8)]) strides = [ None if ll in ['ip', 'op', 'fc', 'softmax', 'max-pool'] else 1 for ll in layer_labels ] strides[4] = 2 cnn_3 = ConvNeuralNetwork(layer_labels, A, num_filters_each_layer, strides, all_layer_label_classes) # Network 4 layer_labels = [ 'ip', 'conv3', 'conv3', 'conv5', 'conv3', 'avg-pool', 'conv5', 'fc', 'softmax', 'op' ] num_filters_each_layer = [None, 16, 16, 16, 32, None, 32, 32, None, None] A = get_dok_mat_with_set_coords(10, [(0, 1), (1, 2), (1, 3), (1, 4), (2, 5), (3, 5), (4, 6), (5, 7), (6, 7), (7, 8), (8, 9)]) strides = [ None if ll in ['ip', 'op', 'fc', 'softmax', 'max-pool', 'avg-pool'] else 1 for ll in layer_labels ] strides[4] = 2 cnn_4 = ConvNeuralNetwork(layer_labels, A, num_filters_each_layer, strides, all_layer_label_classes) # Network 5 layer_labels = [ 'ip', 'conv3', 'conv3', 'conv5', 'conv5', 'avg-pool', 'fc', 'softmax', 'op', 'conv3' ] num_filters_each_layer = [None, 16, 16, 16, 32, None, 32, None, None, 16] A = get_dok_mat_with_set_coords(10, [(0, 1), (1, 2), (1, 3), (2, 5), (3, 5), (4, 6), (5, 6), (6, 7), (7, 8), (0, 9), (9, 4)]) strides = [ None if ll in ['ip', 'op', 'fc', 'softmax', 'avg-pool'] else 1 for ll in layer_labels ] strides[4] = 2 cnn_5 = ConvNeuralNetwork(layer_labels, A, num_filters_each_layer, strides, all_layer_label_classes) # Network 6 layer_labels = [ 'ip', 'conv3', 'conv3', 'conv3', 'fc', 'fc', 'op', 'max-pool', 'fc', 'softmax' ] num_filters_each_layer = [None, 16, 16, 32, 32, 32, None, None, 32, None] A = get_dok_mat_with_set_coords(10, [(0, 1), (1, 2), (2, 3), (4, 5), (5, 9), (3, 7), (7, 4), (4, 8), (8, 9), (9, 6)]) strides = [ None if ll in ['ip', 'op', 'fc', 'softmax', 'max-pool'] else 1 for ll in layer_labels ] cnn_6 = ConvNeuralNetwork(layer_labels, A, num_filters_each_layer, strides, all_layer_label_classes) # Network 7 - Two softmax layers both pointing to output layer_labels = [ 'ip', 'conv3', 'conv3', 'conv3', 'fc', 'fc', 'op', 'max-pool', 'fc', 'softmax', 'softmax' ] num_filters_each_layer = [ None, 16, 16, 32, 32, 32, None, None, 32, None, None ] A = get_dok_mat_with_set_coords(11, [(0, 1), (1, 2), (2, 3), (4, 5), (5, 9), (3, 7), (7, 4), (4, 8), (8, 9), (9, 6), (8, 10), (10, 6)]) strides = [ None if ll in ['ip', 'op', 'fc', 'softmax', 'max-pool'] else 1 for ll in layer_labels ] cnn_7 = ConvNeuralNetwork(layer_labels, A, num_filters_each_layer, strides, all_layer_label_classes) # Network 8 - Similar to previous, except with residual layers layer_labels = [ 'ip', 'conv3', 'res3', 'res5', 'fc', 'fc', 'op', 'max-pool', 'fc', 'softmax', 'softmax' ] num_filters_each_layer = [ None, 16, 16, 32, 32, 32, None, None, 32, None, None ] A = get_dok_mat_with_set_coords(11, [(0, 1), (1, 2), (2, 3), (4, 5), (5, 9), (3, 7), (7, 4), (4, 8), (8, 9), (9, 6), (8, 10), (10, 6)]) strides = [ None if ll in ['ip', 'op', 'fc', 'softmax', 'max-pool'] else 1 for ll in layer_labels ] cnn_8 = ConvNeuralNetwork(layer_labels, A, num_filters_each_layer, strides, all_layer_label_classes) # Network 9 - Similar to previous, except decreasing units for residual layers layer_labels = [ 'ip', 'conv3', 'res3', 'res5', 'res7', 'fc', 'op', 'max-pool', 'fc', 'softmax', 'softmax' ] num_filters_each_layer = [ None, 16, 32, 8, 32, 128, None, None, 256, None, None ] A = get_dok_mat_with_set_coords(11, [(0, 1), (1, 2), (2, 3), (4, 5), (5, 9), (3, 7), (7, 4), (4, 8), (8, 9), (9, 6), (8, 10), (10, 6)]) strides = [ None if ll in ['ip', 'op', 'fc', 'softmax', 'max-pool'] else 1 for ll in layer_labels ] cnn_9 = ConvNeuralNetwork(layer_labels, A, num_filters_each_layer, strides, all_layer_label_classes) return [ cnn_1, cnn_2, cnn_3, cnn_4, cnn_5, cnn_6, cnn_7, cnn_8, cnn_9, get_vgg_net(2), get_blocked_cnn(3, 4, 1), get_resnet_cnn(3, 2, 1), get_multidepth_cnn_eg1(), get_multidepth_cnn_eg2(), ]