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 test_mirror_node(): vnode = VariableNode() vop = Dense(10) vnode.add_op(vop) vnode.add_op(Dense(20)) mnode = MirrorNode(vnode) vnode.set_op(0) assert vnode.op == vop assert mnode.op == vop
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