Пример #1
0
    def __init__(self,
                 stem,
                 cells,
                 head,
                 init_channels,
                 num_classes,
                 auxiliary,
                 search,
                 aux_size=8,
                 auxiliary_layer=13,
                 drop_path_prob=0):
        """Create layers."""
        super(DartsNetwork, self).__init__()
        self.is_search = search
        self._auxiliary = auxiliary
        self.drop_path_prob = drop_path_prob
        if auxiliary:
            self._aux_size = aux_size
            self._auxiliary_layer = auxiliary_layer
        # Build stems part
        self.pre_stems = ClassFactory.get_instance(ClassType.NETWORK, stem)
        # Build cells part
        c_curr = self.pre_stems.output_channel
        self.cells_ = Cells(cells,
                            c_curr,
                            init_channels,
                            auxiliary=auxiliary,
                            auxiliary_layer=auxiliary_layer)
        # output params
        self.len_alpha = self.cells_.len_alpha
        self.num_ops = self.cells_.num_ops
        self.steps = self.cells_.steps
        c_prev, c_aux = self.cells_.output_channels()
        if not search and auxiliary:
            self.auxiliary_head = AuxiliaryHead(c_aux, num_classes, aux_size)
        # head
        self.head = ClassFactory.get_instance(ClassType.NETWORK,
                                              head,
                                              base_channel=c_prev,
                                              num_classes=num_classes)

        # Initialize architecture parameters
        self.set_parameters(
            'alphas_normal',
            1e-3 * ops.random_normal(self.len_alpha, self.num_ops))
        self.set_parameters(
            'alphas_reduce',
            1e-3 * ops.random_normal(self.len_alpha, self.num_ops))

        self.cell_list = self.cells_.children()
        self.name_list = []
        for tmp_cell in self.cells_.children():
            self.name_list.append(tmp_cell.__class__.__name__)
Пример #2
0
 def __init__(self,
              stem,
              cells,
              head,
              init_channels,
              num_classes,
              auxiliary,
              search,
              aux_size=8,
              auxiliary_layer=13,
              drop_path_prob=0):
     """Create layers."""
     super(DartsNetwork, self).__init__()
     self.is_search = search
     self._auxiliary = auxiliary
     self.drop_path_prob = drop_path_prob
     self._cells = cells
     if auxiliary:
         self._aux_size = aux_size
         self._auxiliary_layer = auxiliary_layer
     # Build stems part
     self.pre_stems = ClassFactory.get_instance(ClassType.SEARCH_SPACE,
                                                stem)
     # Build cells part
     c_curr = self.pre_stems.output_channel
     self.cells_ = Cells(cells,
                         c_curr,
                         init_channels,
                         auxiliary=auxiliary,
                         auxiliary_layer=auxiliary_layer)
     # output params
     self.len_alpha = self.cells_.len_alpha
     self.num_ops = self.cells_.num_ops
     self.steps = self.cells_.steps
     c_prev, c_aux = self.cells_.output_channels()
     if not search and auxiliary:
         self.auxiliary_head = AuxiliaryHead(c_aux, num_classes, aux_size)
     # head
     self.head = ClassFactory.get_instance(ClassType.SEARCH_SPACE,
                                           head,
                                           base_channel=c_prev,
                                           num_classes=num_classes)
     self.initializer()