def __init__(self, genotype, C_pp, C_p, C, reduction_p, reduction, layer_id, n_layers): super().__init__() self.reduction = reduction self.n_nodes = len(genotype.normal1) self.layer_id = layer_id if reduction_p: self.preproc0 = ops.FactorizedReduce(C_pp, C) else: self.preproc0 = ops.StdConv(C_pp, C, 1, 1, 0) self.preproc1 = ops.StdConv(C_p, C, 1, 1, 0) if self.layer_id < n_layers // 3: gene = genotype.normal1 self.concat = genotype.normal1_concat elif self.layer_id == n_layers // 3: gene = genotype.reduce1 self.concat = genotype.reduce1_concat elif self.layer_id < 2 * n_layers // 3: gene = genotype.normal2 self.concat = genotype.normal2_concat elif self.layer_id == 2 * n_layers // 3: gene = genotype.reduce2 self.concat = genotype.reduce2_concat elif self.layer_id > 2 * n_layers // 3: gene = genotype.normal3 self.concat = genotype.normal3_concat self.dag = gt.to_dag(C, gene, reduction)
def __init__(self, n_nodes, C_pp, C_p, C, reduction_p, reduction): """ Args: n_nodes: # of intermediate n_nodes C_pp: C_out[k-2] C_p : C_out[k-1] C : C_in[k] (current) reduction_p: flag for whether the previous cell is reduction cell or not reduction: flag for whether the current cell is reduction cell or not """ super().__init__() self.reduction = reduction self.n_nodes = n_nodes # If previous cell is reduction cell, current input size does not match with # output size of cell[k-2]. So the output[k-2] should be reduced by preprocessing. if reduction_p: self.preproc0 = ops.FactorizedReduce(C_pp, C, affine=False) else: self.preproc0 = ops.StdConv(C_pp, C, 1, 1, 0, affine=False) self.preproc1 = ops.StdConv(C_p, C, 1, 1, 0, affine=False) # generate dag self.dag = nn.ModuleList() for i in range(self.n_nodes): self.dag.append(nn.ModuleList()) for j in range(2 + i): # include 2 input nodes # reduction should be used only for input node stride = 2 if reduction and j < 2 else 1 op = ops.MixedOp(C, stride) self.dag[i].append(op)
def __init__(self, genotype, i, C_pp, C_p, C, reduction_p, reduction, SSC): super().__init__() self.reduction = reduction try: self.n_nodes = len(genotype.normal) except: self.n_nodes = len(genotype["cell_0"]) if reduction_p: self.preproc0 = ops.FactorizedReduce(C_pp, C) else: self.preproc0 = ops.StdConv(C_pp, C, 1, 1, 0) self.preproc1 = ops.StdConv(C_p, C, 1, 1, 0) # generate dag if reduction: try: gene = genotype.reduce self.concat = genotype.reduce_concat except: gene = genotype["cell_%d" % i] self.concat = range(2, 2 + self.n_nodes) else: try: gene = genotype.normal self.concat = genotype.normal_concat except: gene = genotype["cell_%d" % i] self.concat = range(2, 2 + self.n_nodes) self.dag = gt.to_dag(C, gene, SSC, reduction)
def __init__(self, genotype, C_pp, C_p, C, reduction_p, reduction, bn_affine=True): super().__init__() self.reduction = reduction self.n_nodes = len(genotype.normal) if reduction_p: self.preproc0 = ops.FactorizedReduce(C_pp, C, affine=bn_affine) else: self.preproc0 = ops.StdConv(C_pp, C, 1, 1, 0, affine=bn_affine) self.preproc1 = ops.StdConv(C_p, C, 1, 1, 0, affine=bn_affine) # generate dag if reduction: gene = genotype.reduce self.concat = genotype.reduce_concat else: gene = genotype.normal self.concat = genotype.normal_concat self.dag = gt.to_dag(C, gene, reduction, bn_affine)
def __init__(self, genotype, C_pp, C_p, C, reduction): super().__init__() self.reduction = reduction self.n_nodes = len(genotype.normal) self.preproc0 = ops.StdConv(C_pp, C, 1, 1, 0) self.preproc1 = ops.StdConv(C_p, C, 1, 1, 0) if reduction: gene = genotype.reduce self.concat = genotype.reduce_concat else: gene = genotype.normal self.concat = genotype.normal_concat self.dag = gt.to_dag(C, gene, reduction)
def __init__(self, n_nodes, C_pp, C_p, C, reduction_p, reduction): super().__init__() self.reduction = reduction self.n_nodes = n_nodes if reduction_p: self.preproc0 = ops.FactorizedReduce(C_pp, C, affine=False) else: self.preproc0 = ops.StdConv(C_pp, C, 1, 1, 0, affine=False) self.preproc1 = ops.StdConv(C_p, C, 1, 1, 0, affine=False) self.dag = nn.ModuleList() for i in range(self.n_nodes): self.dag.append(nn.ModuleList()) for j in range(2 + i): stride = 2 if reduction and j < 2 else 1 op = ops.MixedOp2(C, stride) self.dag[i].append(op)
def __init__(self, DAG, cells, start_p, end_p, C_pp, C_p, C): super().__init__() self.DAG = DAG self.cells = cells self.preproc0 = ops.StdConv(C_pp, C, 1, 1, 0, affine=True) self.preproc1 = ops.StdConv(C_p, C, 1, 1, 0, affine=True) if start_p == 0: gene = DAG.DAG1 self.concat = DAG.DAG1_concat elif start_p == len(DAG.DAG1) + 1: gene = DAG.DAG2 self.concat = DAG.DAG2_concat elif start_p == len(DAG.DAG1) + len(DAG.DAG2) + 2: gene = DAG.DAG3 self.concat = DAG.DAG3_concat self.bigDAG = gt.to_dag(C, gene, False) for k in range(start_p, end_p + 1): # 4 self.bigDAG.append(cells[k])
def __init__(self, n_big_nodes, cells, start_p, end_p, C): super().__init__() self.n_big_nodes = n_big_nodes self.preproc0 = ops.StdConv(C, C, 1, 1, 0, affine=False) self.preproc1 = ops.StdConv(C, C, 1, 1, 0, affine=False) self.DAG = nn.ModuleList() for i in range(self.n_big_nodes): self.DAG.append(nn.ModuleList()) if i < 1: for _ in range(2 + i): stride = 1 op = ops.MixedOp(C, stride) self.DAG[i].append(op) else: for _ in range(3): stride = 1 op = ops.MixedOp(C, stride) self.DAG[i].append(op) for k in range(start_p, end_p): self.DAG.append(cells[k])