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
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) addNode = ConstantNode(name='Merging') addNode.set_op(AddByPadding(cell.graph, addNode, cell.get_blocks_output())) cell.set_outputs(node=addNode) return cell