Пример #1
0
    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.Conv2dBlock(C_pp, C, 1, 1, 0, affine=False)
        self.preproc1 = ops.Conv2dBlock(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)
Пример #2
0
    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)
Пример #3
0
    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)
Пример #4
0
    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)
Пример #5
0
    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)
Пример #6
0
    def __init__(self, genotype, C_pp, C_p, C, reduction_p, reduction):
        super().__init__()
        self.reduction = reduction
        self.n_nodes = len(genotype.normal)

        if reduction_p:
            self.preproc0 = ops.FactorizedReduce(C_pp, C)
        else:
            self.preproc0 = ops.Conv2dBlock(C_pp, C, 1, 1, 0)
        self.preproc1 = ops.Conv2dBlock(C_p, C, 1, 1, 0)

        # 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)