Beispiel #1
0
def create_structure(input_shape=[(2, ), (2, ), (2, )],
                     output_shape=(1, ),
                     *args,
                     **kwargs):

    network = KerasStructure(input_shape, output_shape)
    input_nodes = network.input_nodes

    cell1 = create_cell_1(input_nodes)
    network.add_cell(cell1)

    cell2 = create_cell_2([cell1.output])
    network.add_cell(cell2)

    cell3 = Cell(input_nodes + [cell1.output] + [cell2.output])
    cnode = VariableNode(name='SkipCo')
    nullNode = ConstantNode(op=Tensor([]), name='None')
    cnode.add_op(Connect(cell3.graph, nullNode, cnode))  # SAME
    cnode.add_op(Connect(cell3.graph, input_nodes[0], cnode))
    cnode.add_op(Connect(cell3.graph, input_nodes[1], cnode))
    cnode.add_op(Connect(cell3.graph, input_nodes[2], cnode))
    cnode.add_op(Connect(cell3.graph, cell1.output, cnode))
    cnode.add_op(Connect(cell3.graph, cell2.output, cnode))  # SAME
    cnode.add_op(Connect(cell3.graph, input_nodes, cnode))
    cnode.add_op(Connect(cell3.graph, [input_nodes[0], input_nodes[1]], cnode))
    cnode.add_op(Connect(cell3.graph, [input_nodes[1], input_nodes[2]], cnode))
    cnode.add_op(Connect(cell3.graph, [input_nodes[0], input_nodes[2]], cnode))

    block = Block()
    block.add_node(cnode)
    cell3.add_block(block)

    network.add_cell(cell3)

    return network
Beispiel #2
0
def create_structure(input_shape=[(2,), (2,), (2,)], output_shape=(1,),
                     num_cell=8, *args, **kwargs):

    # , output_op=AddByPadding)
    network = KerasStructure(input_shape, output_shape)
    input_nodes = network.input_nodes

    # CELL 1
    cell1 = create_cell_1(input_nodes)
    network.add_cell(cell1)

    # CELL Middle
    inputs_skipco = [input_nodes, input_nodes[0],
                     input_nodes[1], input_nodes[2], cell1.output]
    pred_cell = cell1
    n = num_cell
    for i in range(n):
        cell_i = Cell(input_nodes + [cell1.output])

        block1 = create_mlp_block(cell_i, pred_cell.output)
        cell_i.add_block(block1)

        cnode = VariableNode(name='SkipCo')
        nullNode = ConstantNode(op=Tensor([]), name='None')
        cnode.add_op(Connect(cell_i.graph, nullNode, cnode))  # SAME

        for inpt in inputs_skipco:
            cnode.add_op(Connect(cell_i.graph, inpt, cnode))

        block2 = Block()
        block2.add_node(cnode)
        cell_i.add_block(block2)
        # set_cell_output_add(cell2)
        cell_i.set_outputs()

        network.add_cell(cell_i)

        # prep. for next iter
        inputs_skipco.append(cell_i.output)
        pred_cell = cell_i

    # CELL LAST
    cell_last = Cell([pred_cell.output])
    block1 = create_mlp_block(cell_last, pred_cell.output)
    cell_last.add_block(block1)
    # set_cell_output_add(cell3)
    cell_last.set_outputs()
    network.add_cell(cell_last)

    return network
    def create_conv_block(input_nodes):
        # first node of block
        n1 = Node('N1')
        for inpt in input_nodes:
            n1.add_op(Connect(cell.graph, inpt, n1))

        def create_conv_node(name):
            n = Node(name)
            n.add_op(Identity())
            n.add_op(Conv1D(filter_size=3, num_filters=16))
            n.add_op(Conv1D(filter_size=5, num_filters=16))
            n.add_op(MaxPooling1D(pool_size=3, padding='same'))
            n.add_op(MaxPooling1D(pool_size=5, padding='same'))
            return n
        # second node of block
        n2 = create_conv_node('N2')

        n3 = create_conv_node('N3')

        block = Block()
        block.add_node(n1)
        block.add_node(n2)
        block.add_node(n3)

        block.add_edge(n1, n2)
        block.add_edge(n2, n3)
        return block
Beispiel #4
0
    def create_block():
        # first node of block
        n1 = Node('N1')
        for inpt in input_nodes:
            n1.add_op(Connect(cell.graph, inpt, n1))

        # second node of block
        mlp_op_list = list()
        mlp_op_list.append(Identity())
        mlp_op_list.append(Dense(5, tf.nn.relu))
        mlp_op_list.append(Dense(5, tf.nn.tanh))
        mlp_op_list.append(Dense(10, tf.nn.relu))
        mlp_op_list.append(Dense(10, tf.nn.tanh))
        mlp_op_list.append(Dense(20, tf.nn.relu))
        mlp_op_list.append(Dense(20, tf.nn.tanh))
        n2 = Node('N2')
        for op in mlp_op_list:
            n2.add_op(op)

        # third node of block
        n3 = Node('N3')
        for op in dropout_ops:
            n3.add_op(op)

        # 5 Blocks
        block = Block()
        block.add_node(n1)
        block.add_node(n2)
        block.add_node(n3)

        block.add_edge(n1, n2)
        block.add_edge(n2, n3)
        return block
Beispiel #5
0
def create_structure(input_shape=[(2, ), (2, ), (2, )],
                     output_shape=(1, ),
                     *args,
                     **kwargs):

    # , output_op=AddByPadding)
    network = KerasStructure(input_shape, output_shape)
    input_nodes = network.input_nodes

    # CELL 1
    cell1 = create_cell_1(input_nodes)
    network.add_cell(cell1)

    # CELL 2
    cell2 = Cell(input_nodes + [cell1.output])

    block1 = create_mlp_block(cell2, cell1.output)
    cell2.add_block(block1)

    cnode = VariableNode(name='SkipCo')
    nullNode = ConstantNode(op=Tensor([]), name='None')
    cnode.add_op(Connect(cell2.graph, nullNode, cnode))  # SAME
    cnode.add_op(Connect(cell2.graph, input_nodes[0], cnode))
    cnode.add_op(Connect(cell2.graph, input_nodes[1], cnode))
    cnode.add_op(Connect(cell2.graph, input_nodes[2], cnode))
    cnode.add_op(Connect(cell2.graph, cell1.output, cnode))
    cnode.add_op(Connect(cell2.graph, input_nodes, cnode))
    cnode.add_op(Connect(cell2.graph, [input_nodes[0], input_nodes[1]], cnode))
    cnode.add_op(Connect(cell2.graph, [input_nodes[1], input_nodes[2]], cnode))
    cnode.add_op(Connect(cell2.graph, [input_nodes[0], input_nodes[2]], cnode))
    block2 = Block()
    block2.add_node(cnode)
    cell2.add_block(block2)
    # set_cell_output_add(cell2)
    cell2.set_outputs()
    network.add_cell(cell2)

    # CELL 3
    cell3 = Cell([cell2.output])
    block1 = create_mlp_block(cell3, cell2.output)
    cell3.add_block(block1)
    # set_cell_output_add(cell3)
    cell3.set_outputs()
    network.add_cell(cell3)

    return network
Beispiel #6
0
def create_dense_cell_type2(input_nodes):
    """MLP type 2

    Args:
        input_nodes (list(Node)): possible inputs of the current cell.

    Returns:
        Cell: a Cell instance.
    """
    cell = Cell(input_nodes)

    # first node of block
    n1 = Node('N_0')
    for inpt in input_nodes:
        n1.add_op(Connect(cell.graph, inpt, n1))

    # second node of block
    mlp_op_list = list()
    mlp_op_list.append(Identity())
    mlp_op_list.append(Dense(5, tf.nn.relu))
    mlp_op_list.append(Dense(10, tf.nn.relu))
    mlp_op_list.append(Dense(20, tf.nn.relu))
    mlp_op_list.append(Dense(40, tf.nn.relu))
    mlp_op_list.append(Dense(80, tf.nn.relu))
    mlp_op_list.append(Dense(160, tf.nn.relu))
    mlp_op_list.append(Dense(320, tf.nn.relu))
    n2 = Node('N_1')
    for op in mlp_op_list:
        n2.add_op(op)

    # third
    n3 = Node('N_2')
    drop_ops = []
    drop_ops.extend(dropout_ops)
    for op in drop_ops:
        n3.add_op(op)

    # 1 Blocks
    block1 = Block()
    block1.add_node(n1)
    block1.add_node(n2)
    block1.add_node(n3)

    block1.add_edge(n1, n2)
    block1.add_edge(n2, n3)

    cell.add_block(block1)

    cell.set_outputs()
    return cell
    def create_conv_block(input_nodes):
        # first node of block
        n1 = Node('N1')
        for inpt in input_nodes:
            n1.add_op(Connect(cell.graph, inpt, n1))

        # second node of block
        n2 = Node('N2')
        n2.add_op(Conv1D(filter_size=5, num_filters=2))


        block = Block()
        block.add_node(n1)
        block.add_node(n2)

        block.add_edge(n1, n2)
        return block