Esempio n. 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
Esempio n. 2
0
def create_cell_1(input_nodes):
    """Create a cell with convolution.

    Args:
        input_nodes (list(Node)): a list of input_nodes for this cell.

    Returns:
        Cell: the corresponding cell.
    """
    cell = Cell(input_nodes)

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

        def create_conv_node(name):
            n = VariableNode(name)
            n.add_op(Identity())
            n.add_op(Conv1D(filter_size=3, num_filters=16))
            n.add_op(MaxPooling1D(pool_size=3, padding='same'))
            n.add_op(Dense(10, tf.nn.relu))
            n.add_op(Conv1D(filter_size=5, num_filters=16))
            n.add_op(MaxPooling1D(pool_size=5, padding='same'))
            n.add_op(Dense(100, tf.nn.relu))
            n.add_op(Conv1D(filter_size=10, num_filters=16))
            n.add_op(MaxPooling1D(pool_size=10, padding='same'))
            n.add_op(Dense(1000, tf.nn.relu))
            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

    block1 = create_conv_block(input_nodes)
    block2 = create_conv_block(input_nodes)
    block3 = create_conv_block(input_nodes)

    cell.add_block(block1)
    cell.add_block(block2)
    cell.add_block(block3)

    addNode = ConstantNode(name='Cell_out')
    addNode.set_op(AddByPadding(cell.graph, addNode, cell.get_blocks_output()))
    cell.set_outputs(node=addNode)
    return cell
Esempio n. 3
0
def create_cell_1(input_nodes):
    """Create a cell with convolution.

    Args:
        input_nodes (list(Node)): a list of input_nodes for this cell.

    Returns:
        Cell: the corresponding cell.
    """
    cell = Cell(input_nodes)

    def create_block(input_node):

        # first node of block
        n1 = ConstantNode(op=Dense(1000, tf.nn.relu), name='N1')
        cell.graph.add_edge(input_node, n1)  # fixed input of current block

        # second node of block
        n2 = ConstantNode(op=Dense(1000, tf.nn.relu), name='N2')

        # third node of the block
        n3 = ConstantNode(op=Dense(1000, tf.nn.relu), name='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, (n1, n2, n3)

    block1, _ = create_block(input_nodes[0])
    block2, (vn1, vn2, vn3) = create_block(input_nodes[1])

    # first node of block
    m_vn1 = MirrorNode(node=vn1)
    cell.graph.add_edge(input_nodes[2], m_vn1)  # fixed input of current block

    # second node of block
    m_vn2 = MirrorNode(node=vn2)

    # third node of the block
    m_vn3 = MirrorNode(node=vn3)

    block3 = Block()
    block3.add_node(m_vn1)
    block3.add_node(m_vn2)
    block3.add_node(m_vn3)

    block3.add_edge(m_vn1, m_vn2)
    block3.add_edge(m_vn2, m_vn3)

    cell.add_block(block1)
    cell.add_block(block2)
    cell.add_block(block3)

    # set_cell_output_add(cell)
    cell.set_outputs()
    return cell
def create_dense_cell(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)

    node = VariableNode(name='N')
    node.add_op(Dense(10, tf.nn.relu))
    node.add_op(Dense(10, tf.nn.relu))
    node.add_op(Dense(10, tf.nn.relu))
    node.add_op(Dense(10, tf.nn.relu))
    cell.graph.add_edge(input_nodes[0], node)

    # Block
    block = Block()
    block.add_node(node)

    cell.add_block(block)

    cell.set_outputs()
    return cell
Esempio n. 5
0
def create_cell_1(input_nodes):
    """Create a cell with convolution.

    Args:
        input_nodes (list(Node)): a list of input_nodes for this cell.

    Returns:
        Cell: the corresponding cell.
    """
    cell = Cell(input_nodes)

    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

    block1 = create_conv_block(input_nodes)
    block2 = create_conv_block(input_nodes)
    block3 = create_conv_block(input_nodes)

    cell.add_block(block1)
    cell.add_block(block2)
    cell.add_block(block3)

    cell.set_outputs()
    return cell
Esempio n. 6
0
def create_cell_2(input_nodes):
    """Create a cell with convolution.

    Args:
        input_nodes (list(Node)): a list of input_nodes for this cell.

    Returns:
        Cell: the corresponding cell.
    """
    cell = Cell(input_nodes)

    def create_block(input_node):
        def create_mlp_node(name):

            n = VariableNode(name)
            n.add_op(Identity())
            n.add_op(Dense(100, tf.nn.relu))
            n.add_op(Dense(100, tf.nn.tanh))
            n.add_op(Dense(100, tf.nn.sigmoid))
            n.add_op(Dropout(0.05))
            n.add_op(Dense(500, tf.nn.relu))
            n.add_op(Dense(500, tf.nn.tanh))
            n.add_op(Dense(500, tf.nn.sigmoid))
            n.add_op(Dropout(0.1))
            n.add_op(Dense(1000, tf.nn.relu))
            n.add_op(Dense(1000, tf.nn.tanh))
            n.add_op(Dense(1000, tf.nn.sigmoid))
            n.add_op(Dropout(0.2))

            return n

        # first node of block
        n1 = create_mlp_node('N1')
        cell.graph.add_edge(input_node, n1)  # fixed input of current block

        # second node of block
        n2 = create_mlp_node('N2')

        n3 = create_mlp_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

    block = create_block(input_nodes[0])

    cell.add_block(block)

    cell.set_outputs()
    return cell
Esempio n. 7
0
def create_dense_cell_type1(input_nodes):
    """Dense type 1

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

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

    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

    block1 = create_block()
    block2 = create_block()

    cell.add_block(block1)
    cell.add_block(block2)

    cell.set_outputs()
    return cell
Esempio n. 8
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
Esempio n. 9
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([cell1.output])
    block1 = create_mlp_block(cell2, cell1.output)
    cell2.add_block(block1)
    cell2.set_outputs()
    network.add_cell(cell2)

    return network
Esempio n. 10
0
def create_cell_1(input_nodes):
    """Create a cell with convolution.

    Args:
        input_nodes (list(Node)): a list of input_nodes for this cell.

    Returns:
        Cell: the corresponding cell.
    """
    cell = Cell(input_nodes)

    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

    block1 = create_conv_block(input_nodes)
    # block2 = create_conv_block(input_nodes)

    cell.add_block(block1)
    # cell.add_block(block2)

    cell.set_outputs()
    return cell
Esempio n. 11
0
def create_cell_1(input_nodes):
    """Create a cell with convolution.

    Args:
        input_nodes (list(Node)): a list of input_nodes for this cell.

    Returns:
        Cell: the corresponding cell.
    """
    cell = Cell(input_nodes)

    def create_block(input_node):
        def add_mlp_ops_to(vnode):
            # REG_L1 = 1.
            # REG_L2 = 1.

            vnode.add_op(Identity())
            vnode.add_op(Dense(100, tf.nn.relu))
            vnode.add_op(Dense(100, tf.nn.tanh))
            vnode.add_op(Dense(100, tf.nn.sigmoid))
            vnode.add_op(Dropout(0.05))
            vnode.add_op(Dense(500, tf.nn.relu))
            vnode.add_op(Dense(500, tf.nn.tanh))
            vnode.add_op(Dense(500, tf.nn.sigmoid))
            vnode.add_op(Dropout(0.1))
            vnode.add_op(Dense(1000, tf.nn.relu))
            vnode.add_op(Dense(1000, tf.nn.tanh))
            vnode.add_op(Dense(1000, tf.nn.sigmoid))
            vnode.add_op(Dropout(0.2))

        # first node of block
        n1 = VariableNode('N1')
        add_mlp_ops_to(n1)
        cell.graph.add_edge(input_node, n1)  # fixed input of current block

        # second node of block
        n2 = VariableNode('N2')
        add_mlp_ops_to(n2)

        # third node of the block
        n3 = VariableNode('N3')
        add_mlp_ops_to(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, (n1, n2, n3)

    block1, _ = create_block(input_nodes[0])
    block2, (vn1, vn2, vn3) = create_block(input_nodes[1])

    # first node of block
    m_vn1 = MirrorNode(node=vn1)
    cell.graph.add_edge(input_nodes[2], m_vn1)  # fixed input of current block

    # second node of block
    m_vn2 = MirrorNode(node=vn2)

    # third node of the block
    m_vn3 = MirrorNode(node=vn3)

    block3 = Block()
    block3.add_node(m_vn1)
    block3.add_node(m_vn2)
    block3.add_node(m_vn3)

    block3.add_edge(m_vn1, m_vn2)
    block3.add_edge(m_vn2, m_vn3)

    cell.add_block(block1)
    cell.add_block(block2)
    cell.add_block(block3)

    cell.set_outputs()
    return cell
Esempio n. 12
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
Esempio n. 13
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