Beispiel #1
0
    def build_normal_layers(self, candidate_ops, input_channel, out_channel,
                            num_layers, f):
        layer_list = []
        f_list = []
        for num_edges in range(num_layers):
            layer = []
            f_sub_list = []
            for _ in range(num_edges + 1):
                if self.mixedge_ver == 1:
                    edge = MixedEdge(candidate_ops=build_candidate_ops(
                        candidate_ops, input_channel, out_channel, 1,
                        'weight_bn_act'))
                elif self.mixedge_ver == 2:
                    edge = MixedEdge_v2(candidate_ops=build_candidate_ops(
                        candidate_ops, input_channel, out_channel, 1,
                        'weight_bn_act'),
                                        threshold=self.threshold)
                else:
                    raise NotImplementedError

                layer += [edge]
                f_sub_list += [f]
            layer_list += [nn.ModuleList(layer)]
            f_list += [f_sub_list]

        return layer_list, f_list
Beispiel #2
0
    def build_reduction_layers(reduction_ops, normal_ops, input_channel,
                               out_channel, num_layers):
        layer_list = []
        for num_edges in range(num_layers):
            layer = []
            for edge_idx in range(num_edges + 1):
                if edge_idx == 0:
                    ops = reduction_ops
                    in_C = input_channel
                    out_C = out_channel
                    S = 2
                else:
                    ops = normal_ops
                    in_C = out_channel
                    out_C = out_channel
                    S = 1

                edge = MixedEdge(candidate_ops=build_candidate_ops(
                    ops, in_C, out_C, S, 'weight_bn_act'), )

                layer += [edge]

                # for e in layer:
                #     print(e.AP_path_alpha)

            layer_list += [nn.ModuleList(layer)]

        return layer_list
Beispiel #3
0
    def build_normal_layers(candidate_ops, input_channel, out_channel,
                            num_layers):
        """
            TODO: apply MixedEdge_v2
            build normal layers for one block.
        :return: layer_list will be args for DartsRecastingBlock(arg)
        """
        layer_list = []
        for num_edges in range(num_layers):
            layer = []
            for _ in range(num_edges + 1):
                edge = MixedEdge(candidate_ops=build_candidate_ops(
                    candidate_ops, input_channel, out_channel, 1,
                    'weight_bn_act'), )

                layer += [edge]

            layer_list += [nn.ModuleList(layer)]

        return layer_list
Beispiel #4
0
    def build_reduction_layers(self, reduction_ops, normal_ops, input_channel, out_channel, num_layers, f):
        layer_list = []
        f_list = []
        for num_edges in range(num_layers):
            layer = []
            f_sub_list = []
            for edge_idx in range(num_edges + 1):
                if edge_idx == 0:
                    ops = reduction_ops
                    in_C = input_channel
                    out_C = out_channel
                    S = 2
                    f_sub_list += [f]
                else:
                    ops = normal_ops
                    in_C = out_channel
                    out_C = out_channel
                    S = 1
                    f_sub_list += [f // 2]

                if self.mixedge_ver == 1:
                    edge = MixedEdge(candidate_ops=build_candidate_ops(ops,
                                                                       in_C,
                                                                       out_C,
                                                                       S,
                                                                       'weight_bn_act'))
                elif self.mixedge_ver == 2:
                    edge = MixedEdge_v2(candidate_ops=build_candidate_ops(ops,
                                                                          in_C,
                                                                          out_C,
                                                                          S,
                                                                          'weight_bn_act'),
                                        threshold=self.threshold)
                else:
                    raise NotImplementedError

                layer += [edge]
            layer_list += [nn.ModuleList(layer)]
            f_list += [f_sub_list]

        return layer_list, f_list