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
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=5, num_filters=2)) n.add_op(Conv1D(filter_size=5, num_filters=3)) 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
def create_cell_conv(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) n1 = ConstantNode(op=Conv1D(filter_size=20, num_filters=128), name='N1') cell.graph.add_edge(input_nodes[0], n1) # fixed input connection n2 = ConstantNode(op=Activation(activation='relu'), name='N2') n3 = ConstantNode(op=MaxPooling1D(pool_size=1, padding='same'), name='N3') n4 = ConstantNode(op=Conv1D(filter_size=10, num_filters=128),name='N4') n5 = ConstantNode(op=Activation(activation='relu'), name='N5') n6 = ConstantNode(op=MaxPooling1D(pool_size=10, padding='same'), name='N6') n7 = ConstantNode(op=Flatten(), name='N7') n8 = ConstantNode(op=Dense(units=200), name='N8') n9 = ConstantNode(op=Activation(activation='relu'), name='N9') n10 = ConstantNode(op=Dropout(rate=0.1), name='N10') n11 = ConstantNode(op=Dense(units=20), name='N11') n12 = ConstantNode(op=Activation(activation='relu'), name='N12') n13 = ConstantNode(op=Dropout(rate=0.1), name='N13') block = Block() block.add_node(n1) block.add_node(n2) block.add_node(n3) block.add_node(n4) block.add_node(n5) block.add_node(n6) block.add_node(n7) block.add_node(n8) block.add_node(n9) block.add_node(n10) block.add_node(n11) block.add_node(n12) block.add_node(n13) block.add_edge(n1, n2) block.add_edge(n2, n3) block.add_edge(n3, n4) block.add_edge(n4, n5) block.add_edge(n5, n6) block.add_edge(n6, n7) block.add_edge(n7, n8) block.add_edge(n8, n9) block.add_edge(n9, n10) block.add_edge(n10, n11) block.add_edge(n11, n12) block.add_edge(n12, n13) cell.add_block(block) cell.set_outputs() return cell