コード例 #1
0
def create_structure(input_shape=(2,), output_shape=(1,), *args, **kwargs):
    network = KerasStructure(input_shape, output_shape) #, output_op=AddByPadding)
    input_nodes = network.input_nodes

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

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

    network = KerasStructure(input_shape,
                             output_shape)  #, output_op=AddByPadding)
    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
コード例 #3
0
def create_struct_full_skipco(input_shape, output_shape, create_cell,
                              num_cells):
    """
        Create a SequentialStructure object.

        Args:
            input_shape (tuple): shape of input tensor
            output_shape (tuple): shape of output tensor
            create_cell (function): function that create a cell, take one argument (inputs: list(None))
            num_cells (int): number of cells in the sequential structure

        Return:
            KerasStructure: the corresponding built structure.
    """

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

    func = lambda: create_cell(input_nodes)
    network.add_cell_f(func)

    func = lambda x: create_cell(x)
    for i in range(num_cells - 1):
        network.add_cell_f(func, num=None)

    return network
コード例 #4
0
def create_structure(input_shape=[(2, ) for _ in range(4)],
                     output_shape=(1, ),
                     num_cell=8,
                     *args,
                     **kwargs):

    network = KerasStructure(input_shape,
                             output_shape)  #, output_op=AddByPadding)
    input_nodes = network.input_nodes
    print('input_nodes: ', 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

    # CELL LAST
    cell_last = Cell([pred_cell.output])
    first_node = create_mlp_block(cell_last, pred_cell.output)
    set_cell_output_add(cell_last)

    network.add_cell(cell_last)

    return network
コード例 #5
0
def create_structure(input_shape=(2, ), output_shape=(1, ), *args, **kwargs):
    network = KerasStructure(input_shape,
                             output_shape)  #, output_op=AddByPadding)
    input_nodes = network.input_nodes

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

    # CELL 2
    cell2 = create_cell_conv([cell1.output])
    network.add_cell(cell2)

    # CELL 3
    cell3 = create_cell_mlp([cell2.output])
    network.add_cell(cell3)

    # CELL 4
    cell4 = create_cell_mlp([cell3.output])
    network.add_cell(cell4)

    return network
コード例 #6
0
def create_structure(input_shape=[(2, ), (2, ), (2, )],
                     output_shape=(1, ),
                     *args,
                     **kwargs):

    network = KerasStructure(input_shape,
                             output_shape)  #, output_op=AddByPadding)
    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
コード例 #7
0
def create_structure(input_shape=[(2,) for _ in range(4)], output_shape=(1,), num_cell=8, *args, **kwargs):

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

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

    # # CELL Middle
    pred_cell = cell1
    skipco_inputs = [
        input_nodes,
        [input_nodes[0], input_nodes[1], input_nodes[2]],
        [input_nodes[0], input_nodes[1], input_nodes[3]],
        [input_nodes[0], input_nodes[2], input_nodes[3]],
        [input_nodes[1], input_nodes[2], input_nodes[3]],
        [input_nodes[0], input_nodes[1]],
        [input_nodes[0], input_nodes[2]],
        [input_nodes[0], input_nodes[3]],
        [input_nodes[1], input_nodes[2]],
        [input_nodes[1], input_nodes[3]],
        [input_nodes[2], input_nodes[3]],
        input_nodes[0],
        input_nodes[1],
        input_nodes[2],
        input_nodes[3],
        ]

    for _ in range(8):
        curr_cell = Cell([pred_cell.output])# + skipco_inputs) # current cell
        dense_node = create_mlp_block(curr_cell, pred_cell.output, skipco_inputs)
        set_cell_output_add(curr_cell)
        network.add_cell(curr_cell)

        # preparing next iter
        skipco_inputs.append(pred_cell.output)
        skipco_inputs.append(dense_node)
        pred_cell = curr_cell


    return network
コード例 #8
0
def create_structure(input_shape=[(2, ), (2, ), (2, )],
                     output_shape=(1, ),
                     *args,
                     **kwargs):

    network = KerasStructure(input_shape,
                             output_shape)  #, output_op=AddByPadding)
    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
コード例 #9
0
def create_seq_struct(input_shape, output_shape, create_cell, num_cells):
    """
        Create a KerasStructure object.

        Args:
            input_tensor (tensor): a tensorflow tensor object
            create_cell (function): function that create a cell, take one argument (inputs: list(None))
            num_cells (int): number of cells in the sequential structure

        Return:
            KerasStructure: the corresponding built structure.
    """

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

    func = lambda: create_cell(input_nodes)
    network.add_cell_f(func)

    func = lambda x: create_cell(x)
    for _ in range(num_cells - 1):
        network.add_cell_f(func, num=1)

    return network