def _build_cell(self, cell_desc: CellDesc, rand_ops: RandOps) -> None: # sanity check: we have random ops for each node assert len(cell_desc.nodes()) == len(rand_ops.ops_and_ins) reduction = (cell_desc.cell_type == CellType.Reduction) # Add random op for each edge for node, (op_names, to_states) in zip(cell_desc.nodes(), rand_ops.ops_and_ins): # as we want cell to be completely random, remove previous edges node.edges.clear() # add random edges for op_name, to_state in zip(op_names, to_states): op_desc = OpDesc(op_name, params={ 'conv': cell_desc.conv_params, 'stride': 2 if reduction and to_state < 2 else 1 }, in_len=1, trainables=None, children=None) edge = EdgeDesc(op_desc, input_ids=[to_state]) node.edges.append(edge)
def _build_cell(self, cell_desc: CellDesc) -> None: for i, node in enumerate(cell_desc.nodes()): input_ids = [] first_proj = False # if input node is connected then it needs projection if self._cell_matrix[0, i + 1]: # nadbench internal node starts at 1 input_ids.append(0) # connect to s0 first_proj = True for j in range(i): # look at all internal vertex before us if self._cell_matrix[j + 1, i + 1]: # if there is connection input_ids.append(j + 2) # offset because of s0, s1 op_desc = OpDesc( 'nasbench101_op', params={ 'conv': cell_desc.conv_params, 'stride': 1, 'vertex_op': self._vertex_ops[i + 1], # offset because of input node 'first_proj': first_proj }, in_len=len(input_ids), trainables=None, children=None) # TODO: should we pass children here? edge = EdgeDesc(op_desc, input_ids=input_ids) node.edges.append(edge)
def _build_cell(self, cell_desc: CellDesc) -> None: reduction = (cell_desc.cell_type == CellType.Reduction) self._ensure_nonempty_nodes(cell_desc) # we operate on last node, inserting another node before it new_nodes = [n.clone() for n in cell_desc.nodes()] petridish_node = NodeDesc(edges=[]) new_nodes.insert(len(new_nodes) - 1, petridish_node) input_ids = list(range(len(new_nodes))) # 2 + len-2 assert len(input_ids) >= 2 op_desc = OpDesc('petridish_reduction_op' if reduction else 'petridish_normal_op', params={ 'conv': cell_desc.conv_params, # specify strides for each input, later we will # give this to each primitive '_strides':[2 if reduction and j < 2 else 1 \ for j in input_ids], }, in_len=len(input_ids), trainables=None, children=None) edge = EdgeDesc(op_desc, input_ids=input_ids) petridish_node.edges.append(edge) # note that post op will be recreated which means there is no # warm start for post op when number of nodes changes cell_desc.reset_nodes(new_nodes, cell_desc.node_ch_out, cell_desc.post_op.name)
def _build_cell(self, cell_desc:CellDesc)->None: reduction = (cell_desc.cell_type==CellType.Reduction) # add xnas op for each edge for i, node in enumerate(cell_desc.nodes()): for j in range(i+2): op_desc = OpDesc('xnas_op', params={ 'conv': cell_desc.conv_params, 'stride': 2 if reduction and j < 2 else 1 }, in_len=1, trainables=None, children=None) edge = EdgeDesc(op_desc, input_ids=[j]) node.edges.append(edge)
def __init__(self, desc: CellDesc, affine: bool, droppath: bool, template_cell: Optional['Cell'] ): # template cell, if any, to use for arch params super().__init__() # some of these members are public as finalizer needs access self.desc = desc self.s0_op = Op.create(desc.s0_op, affine=affine) self.s1_op = Op.create(desc.s1_op, affine=affine) self.dag = Cell._create_dag(desc.nodes(), affine=affine, droppath=droppath, template_cell=template_cell) self.post_op = Op.create(desc.post_op, affine=affine)
def __init__(self, desc:CellDesc, affine:bool, droppath:bool, trainables_from:Optional['Cell']): # template cell, if any, to use for arch params super().__init__() # some of these members are public as finalizer needs access self.desc = desc # TODO: support any number of stems assert len(desc.stems)==2, "Cell compiler currently only supports 2 stems" self.s0_op = Op.create(desc.stems[0], affine=affine) self.s1_op = Op.create(desc.stems[1], affine=affine) self.dag = Cell._create_dag(desc.nodes(), affine=affine, droppath=droppath, trainables_from=trainables_from) self.post_op = Op.create(desc.post_op, affine=affine)
def _build_cell(self, cell_desc: CellDesc) -> None: reduction = (cell_desc.cell_type == CellType.Reduction) # add mixed op for each edge in each node # how does the stride works? For all ops connected to s0 and s1, we apply # reduction in WxH. All ops connected elsewhere automatically gets # reduced WxH (because all subsequent states are derived from s0 and s1). # Note that channel is increased via conv_params for the cell for i, node in enumerate(cell_desc.nodes()): for j in range(i + 2): op_desc = OpDesc('mixed_op', params={ 'conv': cell_desc.conv_params, 'stride': 2 if reduction and j < 2 else 1 }, in_len=1, trainables=None, children=None) edge = EdgeDesc(op_desc, input_ids=[j]) node.edges.append(edge)
def _ensure_nonempty_nodes(self, cell_desc: CellDesc): assert len(cell_desc.nodes()) > 0 for node in cell_desc.nodes(): assert len(node.edges) > 0