當前位置: 首頁>>代碼示例>>Python>>正文


Python genotypes.Genotype方法代碼示例

本文整理匯總了Python中genotypes.Genotype方法的典型用法代碼示例。如果您正苦於以下問題:Python genotypes.Genotype方法的具體用法?Python genotypes.Genotype怎麽用?Python genotypes.Genotype使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在genotypes的用法示例。


在下文中一共展示了genotypes.Genotype方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: genotype

# 需要導入模塊: import genotypes [as 別名]
# 或者: from genotypes import Genotype [as 別名]
def genotype(self):

      def _parse(probs):
        gene = []
        start = 0
        for i in range(STEPS):
          end = start + i + 1
          W = probs[start:end].copy()
          j = sorted(range(i + 1), key=lambda x: -max(W[x][k] for k in range(len(W[x])) if k != PRIMITIVES.index('none')))[0]
          k_best = None
          for k in range(len(W[j])):
            if k != PRIMITIVES.index('none'):
              if k_best is None or W[j][k] > W[j][k_best]:
                k_best = k
          gene.append((PRIMITIVES[k_best], j))
          start = end
        return gene

      gene = _parse(F.softmax(self.weights, dim=-1).data.cpu().numpy())
      genotype = Genotype(recurrent=gene, concat=range(STEPS+1)[-CONCAT:])
      return genotype 
開發者ID:quark0,項目名稱:darts,代碼行數:23,代碼來源:model_search.py

示例2: parse_results

# 需要導入模塊: import genotypes [as 別名]
# 或者: from genotypes import Genotype [as 別名]
def parse_results(results, n_nodes):
    concat = range(2, 2 + n_nodes)
    normal_gene = []
    reduction_gene = []
    for i in range(n_nodes):
        normal_node = []
        reduction_node = []
        for j in range(2 + i):
            normal_key = 'normal_n{}_p{}'.format(i + 2, j)
            reduction_key = 'reduce_n{}_p{}'.format(i + 2, j)
            normal_op = results[normal_key].cpu().numpy()
            reduction_op = results[reduction_key].cpu().numpy()
            if sum(normal_op == 1):
                normal_index = np.argmax(normal_op)
                normal_node.append((PRIMITIVES[normal_index], j))
            if sum(reduction_op == 1):
                reduction_index = np.argmax(reduction_op)
                reduction_node.append((PRIMITIVES[reduction_index], j))
        normal_gene.append(normal_node)
        reduction_gene.append(reduction_node)

    genotypes = Genotype(normal=normal_gene, normal_concat=concat,
                         reduce=reduction_gene, reduce_concat=concat)
    return genotypes 
開發者ID:microsoft,項目名稱:nni,代碼行數:26,代碼來源:utils.py

示例3: parse_arch

# 需要導入模塊: import genotypes [as 別名]
# 或者: from genotypes import Genotype [as 別名]
def parse_arch(arch):
    arch = list(map(int, arch.split()))
    lenth = len(arch) // 2
    recurrent = []
    concat = [i for i in range(lenth+1)]
    ACT = {
        0: 'tanh',
        1: 'relu',
        2: 'identity',
        3: 'sigmoid'
    }
    for i in range(lenth):
        pre_node = arch[2*i]
        activation = ACT[arch[2*i+1]]
        recurrent.append((activation, pre_node))
        """
        if pre_node in concat:
            concat.remove(pre_node)"""
    concat = range(1, lenth+1)
    return Genotype(recurrent=recurrent, concat=concat) 
開發者ID:renqianluo,項目名稱:NAO,代碼行數:22,代碼來源:utils.py

示例4: get_genotype

# 需要導入模塊: import genotypes [as 別名]
# 或者: from genotypes import Genotype [as 別名]
def get_genotype(self, force=False):
        if force:
          gene_normal = self.parse_gene_force(self.normal_candidate_flags,
                                              self.normal_selected_idxs,
                                              self.alphas_normal)
          gene_reduce = self.parse_gene_force(self.reduce_candidate_flags,
                                              self.reduce_selected_idxs,
                                              self.alphas_reduce)
        else:
          gene_normal = self.parse_gene(self.normal_selected_idxs)
          gene_reduce = self.parse_gene(self.reduce_selected_idxs)
        n = 2
        concat = range(n + self._steps - self._multiplier, self._steps + n)
        genotype = Genotype(
            normal=gene_normal, normal_concat=concat,
            reduce=gene_reduce, reduce_concat=concat
        )
        return genotype 
開發者ID:lightaime,項目名稱:sgas,代碼行數:20,代碼來源:model_search.py

示例5: genotype

# 需要導入模塊: import genotypes [as 別名]
# 或者: from genotypes import Genotype [as 別名]
def genotype(self):
        gene_normal = gt.parse(self.alpha_normal, k=2)
        gene_reduce = gt.parse(self.alpha_reduce, k=2)
        concat = range(2, 2+self.n_nodes) # concat all intermediate nodes

        return gt.Genotype(normal=gene_normal, normal_concat=concat,
                           reduce=gene_reduce, reduce_concat=concat) 
開發者ID:khanrc,項目名稱:pt.darts,代碼行數:9,代碼來源:search_cnn.py

示例6: genotype

# 需要導入模塊: import genotypes [as 別名]
# 或者: from genotypes import Genotype [as 別名]
def genotype(self):

    def _parse(weights):
      gene = []
      n = 2
      start = 0
      for i in range(self._steps):
        end = start + n
        W = weights[start:end].copy()
        edges = sorted(range(i + 2), key=lambda x: -max(W[x][k] for k in range(len(W[x])) if k != PRIMITIVES.index('none')))[:2]
        for j in edges:
          k_best = None
          for k in range(len(W[j])):
            if k != PRIMITIVES.index('none'):
              if k_best is None or W[j][k] > W[j][k_best]:
                k_best = k
          gene.append((PRIMITIVES[k_best], j))
        start = end
        n += 1
      return gene

    gene_normal = _parse(F.softmax(self.alphas_normal, dim=-1).data.cpu().numpy())
    gene_reduce = _parse(F.softmax(self.alphas_reduce, dim=-1).data.cpu().numpy())

    concat = range(2+self._steps-self._multiplier, self._steps+2)
    genotype = Genotype(
      normal=gene_normal, normal_concat=concat,
      reduce=gene_reduce, reduce_concat=concat
    )
    return genotype 
開發者ID:quark0,項目名稱:darts,代碼行數:32,代碼來源:model_search.py

示例7: parse_network

# 需要導入模塊: import genotypes [as 別名]
# 或者: from genotypes import Genotype [as 別名]
def parse_network(switches_normal, switches_reduce):

    def _parse_switches(switches):
        n = 2
        start = 0
        gene = []
        step = 4
        for i in range(step):
            end = start + n
            for j in range(start, end):
                for k in range(len(switches[j])):
                    if switches[j][k]:
                        gene.append((PRIMITIVES[k], j - start))
            start = end
            n = n + 1
        return gene
    gene_normal = _parse_switches(switches_normal)
    gene_reduce = _parse_switches(switches_reduce)
    
    concat = range(2, 6)
    
    genotype = Genotype(
        normal=gene_normal, normal_concat=concat, 
        reduce=gene_reduce, reduce_concat=concat
    )
    
    return genotype 
開發者ID:antoyang,項目名稱:NAS-Benchmark,代碼行數:29,代碼來源:train_search.py

示例8: get_genotype

# 需要導入模塊: import genotypes [as 別名]
# 或者: from genotypes import Genotype [as 別名]
def get_genotype(self, force=False):
        if force:
            gene_normal = self.parse_gene_force(self.normal_candidate_flags,
                                                self.normal_selected_idxs,
                                                self.alphas_normal)
        else:
            gene_normal = self.parse_gene(self.normal_selected_idxs)
        n = 2
        concat = range(n + self._steps - self._multiplier, self._steps + n)
        genotype = Genotype(
            normal=gene_normal, normal_concat=concat
        )
        return genotype 
開發者ID:lightaime,項目名稱:sgas,代碼行數:15,代碼來源:model_search.py

示例9: get_genotype

# 需要導入模塊: import genotypes [as 別名]
# 或者: from genotypes import Genotype [as 別名]
def get_genotype(self, force=False):
        if force:
            gene_normal = self.parse_gene_force(self.normal_candidate_flags,
                                                self.normal_selected_idxs,
                                                self.alphas_normal)
        else:
            gene_normal = self.parse_gene(self.normal_selected_idxs)
        n = 2
        concat = range(n + self._steps - self._multiplier, self._steps + n)
        genotype = Genotype(normal=gene_normal, normal_concat=concat)
        return genotype 
開發者ID:lightaime,項目名稱:sgas,代碼行數:13,代碼來源:model_search.py

示例10: genotype

# 需要導入模塊: import genotypes [as 別名]
# 或者: from genotypes import Genotype [as 別名]
def genotype(self):

    def _parse(weights,weights2):
      gene = []
      n = 2
      start = 0
      for i in range(self._steps):
        end = start + n
        W = weights[start:end].copy()
        W2 = weights2[start:end].copy()
        for j in range(n):
          W[j,:]=W[j,:]*W2[j]
        edges = sorted(range(i + 2), key=lambda x: -max(W[x][k] for k in range(len(W[x])) if k != PRIMITIVES.index('none')))[:2]
        
        #edges = sorted(range(i + 2), key=lambda x: -W2[x])[:2]
        for j in edges:
          k_best = None
          for k in range(len(W[j])):
            if k != PRIMITIVES.index('none'):
              if k_best is None or W[j][k] > W[j][k_best]:
                k_best = k
          gene.append((PRIMITIVES[k_best], j))
        start = end
        n += 1
      return gene
    n = 3
    start = 2
    weightsr2 = F.softmax(self.betas_reduce[0:2], dim=-1)
    weightsn2 = F.softmax(self.betas_normal[0:2], dim=-1)
    for i in range(self._steps-1):
      end = start + n
      tw2 = F.softmax(self.betas_reduce[start:end], dim=-1)
      tn2 = F.softmax(self.betas_normal[start:end], dim=-1)
      start = end
      n += 1
      weightsr2 = torch.cat([weightsr2,tw2],dim=0)
      weightsn2 = torch.cat([weightsn2,tn2],dim=0)
    gene_normal = _parse(F.softmax(self.alphas_normal, dim=-1).data.cpu().numpy(),weightsn2.data.cpu().numpy())
    gene_reduce = _parse(F.softmax(self.alphas_reduce, dim=-1).data.cpu().numpy(),weightsr2.data.cpu().numpy())

    concat = range(2+self._steps-self._multiplier, self._steps+2)
    genotype = Genotype(
      normal=gene_normal, normal_concat=concat,
      reduce=gene_reduce, reduce_concat=concat
    )
    return genotype 
開發者ID:antoyang,項目名稱:NAS-Benchmark,代碼行數:48,代碼來源:model_search.py

示例11: genotype

# 需要導入模塊: import genotypes [as 別名]
# 或者: from genotypes import Genotype [as 別名]
def genotype(self):

    def _parse(weights,weights2):
      gene = []
      n = 2
      start = 0
      for i in range(self._steps):
        end = start + n
        W = weights[start:end].copy()
        W2 = weights2[start:end].copy()
        for j in range(n):
          W[j,:]=W[j,:]*W2[j]
        edges = sorted(range(i + 2), key=lambda x: -max(W[x][k] for k in range(len(W[x])) if k != PRIMITIVES.index('none')))[:2]
        
        #edges = sorted(range(i + 2), key=lambda x: -W2[x])[:2]
        for j in edges:
          k_best = None
          for k in range(len(W[j])):
            if k != PRIMITIVES.index('none'):
              if k_best is None or W[j][k] > W[j][k_best]:
                k_best = k
          gene.append((PRIMITIVES[k_best], j))
        start = end
        n += 1
      return gene
    n = 3
    start = 2
    weightsr2 = F.softmax(self.betas_reduce[0:2], dim=-1)
    weightsn2 = F.softmax(self.betas_normal[0:2], dim=-1)
    for i in range(self._steps-1):
      end = start + n
      #print(self.betas_reduce[start:end])
      tw2 = F.softmax(self.betas_reduce[start:end], dim=-1)
      tn2 = F.softmax(self.betas_normal[start:end], dim=-1)
      start = end
      n += 1
      weightsr2 = torch.cat([weightsr2,tw2],dim=0)
      weightsn2 = torch.cat([weightsn2,tn2],dim=0)
    gene_normal = _parse(F.softmax(self.alphas_normal, dim=-1).data.cpu().numpy(),weightsn2.data.cpu().numpy())
    gene_reduce = _parse(F.softmax(self.alphas_reduce, dim=-1).data.cpu().numpy(),weightsr2.data.cpu().numpy())

    concat = range(2+self._steps-self._multiplier, self._steps+2)
    genotype = Genotype(
      normal=gene_normal, normal_concat=concat,
      reduce=gene_reduce, reduce_concat=concat
    )
    return genotype 
開發者ID:antoyang,項目名稱:NAS-Benchmark,代碼行數:49,代碼來源:model_search_random.py


注:本文中的genotypes.Genotype方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。