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
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
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_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
def create_structure(input_shape=[(2,), (2,), (2,)], output_shape=(1,), *args, **kwargs): network = KerasStructure(input_shape, output_shape) input_nodes = network.input_nodes func = lambda: create_cell_1(input_nodes) network.add_cell_f(func) func = lambda x: create_cell_2(x) network.add_cell_f(func, num=1) return network
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
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