예제 #1
0
    def retrain(self, pre_block):
        tf.reset_default_graph()
        self.train_num = 50000
        self.block_num = len(pre_block)

        retrain_log = "-" * 20 + "retrain" + "-" * 20 + '\n'

        data_x, labels, block_input, train_flag = self._get_input('', [])
        for block in pre_block:
            self.block_num += 1
            cell_list = []
            for cell in block.cell_list:
                if cell.type == 'conv':
                    cell_list.append(Cell(cell.type, cell.filter_size * 2, cell.kernel_size, cell.activation))
                else:
                    cell_list.append(cell)
            # repeat search
            graph_full, cell_list = self._recode(block.graph, block.cell_list, NAS_CONFIG['nas_main']['repeat_num'])
            # add pooling layer only in last repeat block
            cell_list.append(Cell('pooling', 'max', 2))
            graph_full.append([])
            retrain_log = retrain_log + str(graph_full) + str(cell_list) + '\n'
            block_input = self._inference(block_input, graph_full, cell_list, train_flag)

        logits = tf.nn.dropout(block_input, keep_prob=1.0)
        # softmax
        logits = self._makedense(logits, ('', [256, self.output_shape[-1]], 'relu'))

        sess = tf.Session()
        precision, log = self._eval(sess, logits, data_x, labels, train_flag, retrain=True)
        retrain_log += log

        NAS_LOG << ('eva', retrain_log)
        return float(precision)
예제 #2
0
def _random_get_cell(_num):
    _dic = dict()
    _dic['conv'] = copy.deepcopy(NAS_CONFIG['spl']['conv_space'])
    tmp = []
    for i in NAS_CONFIG['spl']['conv_space']['filter_size']:
        tmp.extend(i)
    _dic['conv']['filter_size'] = tmp
    _dic['pooling'] = copy.deepcopy(NAS_CONFIG['spl']['pool_space'])
    res = []
    for _ in range(_num):
        _type = random.randint(0, 1)
        if _type == 0:
            tmp = ('conv', )
            for key in _dic['conv']:
                _r = random.randint(1, len(_dic['conv'][key]))
                tmp = tmp + (_dic['conv'][key][_r-1], )
            res.append(Cell(tmp[0], tmp[1], tmp[2], tmp[3]))
            # res.append(tmp)
        else:
            tmp = ('pooling', )
            for key in _dic['pooling']:
                _r = random.randint(1, len(_dic['pooling'][key]))
                tmp = tmp + (_dic['pooling'][key][_r-1],)
            res.append(Cell(tmp[0], tmp[1], tmp[2]))
            # res.append(tmp)
    return res
def test_random_cell() -> None:
    grid = Grid(2, 2)

    for _ in range(100):
        assert grid.randomCell() in [
            Cell(0, 0), Cell(0, 1),
            Cell(1, 0), Cell(1, 1)
        ]
예제 #4
0
    def evaluate(self,
                 network,
                 pre_block=[],
                 is_bestNN=False,
                 update_pre_weight=False):
        '''Method for evaluate the given network.
        Args:
            network: NetworkItem()
            pre_block: The pre-block structure, every block has two parts: graph_part and cell_list of this block.
            is_bestNN: Symbol for indicating whether the evaluating network is the best network of this round, default False.
            update_pre_weight: Symbol for indicating whether to update previous blocks' weight, default by False.
        Returns:
            Accuracy'''
        assert self.train_num >= self.batch_size
        tf.reset_default_graph()
        self.block_num = len(pre_block)

        self.log = "-" * 20 + str(network.id) + "-" * 20 + '\n'
        for block in pre_block:
            self.log = self.log + str(block.graph) + str(
                block.cell_list) + '\n'
        self.log = self.log + str(network.graph) + str(
            network.cell_list) + '\n'

        config = tf.ConfigProto()
        config.gpu_options.allow_growth = True
        with tf.Session(config=config) as sess:
            data_x, data_y, block_input, train_flag = self._get_input(
                sess, pre_block, update_pre_weight)

            graph_full, cell_list = self._recode(
                network.graph, network.cell_list,
                NAS_CONFIG['nas_main']['repeat_num'])
            # a pooling layer for last repeat block
            graph_full = graph_full + [[]]
            if NAS_CONFIG['nas_main']['link_node']:
                # a pooling layer for last repeat block
                cell_list = cell_list + [Cell('pooling', 'max', 2)]
            else:
                cell_list = cell_list + [Cell('id', 'max', 1)]
            logits = self._inference(block_input, graph_full, cell_list,
                                     train_flag)

            precision, log = self._eval(sess, logits, data_x, data_y,
                                        train_flag)
            self.log += log

            saver = tf.train.Saver(tf.global_variables())

            if is_bestNN:  # save model
                if not os.path.exists(os.path.join(self.model_path)):
                    os.makedirs(os.path.join(self.model_path))
                saver.save(
                    sess,
                    os.path.join(self.model_path, 'model' + str(network.id)))
        NAS_LOG = Logger()
        NAS_LOG << ('eva_eva', self.log)
        return precision
    def evaluate(self,
                 network,
                 pre_block=[],
                 is_bestNN=False,
                 update_pre_weight=False):
        '''Method for evaluate the given network.
        Args:
            network: NetworkItem()
            pre_block: The pre-block structure, every block has two parts: graph_part and cell_list of this block.
            is_bestNN: Symbol for indicating whether the evaluating network is the best network of this round, default False.
            update_pre_weight: Symbol for indicating whether to update previous blocks' weight, default by False.
        Returns:
            Accuracy'''
        assert self.train_num >= self.batch_size
        tf.reset_default_graph()
        self.block_num = len(
            pre_block) * NAS_CONFIG['nas_main']['repeat_search']

        # print("-" * 20, network.id, "-" * 20)
        # print(network.graph, network.cell_list, Network.pre_block)
        self.log = "-" * 20 + str(network.id) + "-" * 20 + '\n'
        for block in pre_block:
            self.log = self.log + str(block.graph) + str(
                block.cell_list) + '\n'
        self.log = self.log + str(network.graph) + str(
            network.cell_list) + '\n'

        with tf.Session() as sess:
            data_x, data_y, block_input, train_flag = self._get_input(
                sess, pre_block, update_pre_weight)

            for _ in range(NAS_CONFIG['nas_main']['repeat_search'] - 1):
                graph_full = network.graph + [[]]
                cell_list = network.cell_list + [Cell('pooling', 'max', 1)]
                block_input = self._inference(block_input, graph_full,
                                              cell_list, train_flag)
                self.block_num += 1
            # a pooling layer for last repeat block
            graph_full = network.graph + [[]]
            cell_list = network.cell_list + [Cell('pooling', 'max', 2)]
            logits = self._inference(block_input, graph_full, cell_list,
                                     train_flag)

            logits = tf.nn.dropout(logits, keep_prob=1.0)
            logits = self._makedense(logits, ('', [self.NUM_CLASSES], ''))

            precision, saver, log = self._eval(sess, data_x, data_y, logits,
                                               train_flag)
            self.log += log

            if is_bestNN:  # save model
                saver.save(
                    sess,
                    os.path.join(self.model_path, 'model' + str(network.id)))

        NAS_LOG << ('eva', self.log)
        return precision
예제 #6
0
def test_links_listing() -> None:
    a_cell = Cell(1, 1)
    another_cell = Cell(1, 2)
    yet_another_cell = Cell(2, 1)

    a_cell += another_cell
    a_cell += yet_another_cell

    assert set(a_cell.links).intersection([another_cell, yet_another_cell
                                           ]) == set(a_cell.links)
    assert another_cell.links == [a_cell]
    assert yet_another_cell.links == [a_cell]
def test_cell_access() -> None:
    grid = Grid(2, 2)

    assert grid[0, 0] == Cell(0, 0)
    assert grid[0, 1] == Cell(0, 1)
    assert grid[1, 0] == Cell(1, 0)
    assert grid[1, 1] == Cell(1, 1)

    assert grid[-1, 0] is None
    assert grid[0, -1] is None  # noqa: E201
    assert grid[4, 0] is None  # noqa: E201
    assert grid[0, 4] is None  # noqa: E201
예제 #8
0
def test_index_access() -> None:
    a_cell = Cell(0, 0)
    distances = Distances(a_cell)

    assert distances[a_cell] == 0

    another_cell = Cell(0, 1)
    distance = 13
    distances[another_cell] = distance
    assert distances[another_cell] == distance

    assert distances[Cell(2, 2)] is None
예제 #9
0
def test_linking() -> None:
    a_cell = Cell(1, 1)
    another_cell = Cell(1, 2)
    yet_another_cell = Cell(2, 1)

    assert not a_cell & another_cell
    assert not another_cell & a_cell
    assert not a_cell & yet_another_cell
    assert not another_cell & yet_another_cell

    a_cell += another_cell

    assert a_cell & another_cell
    assert another_cell & a_cell
    assert not a_cell & yet_another_cell
    assert not another_cell & yet_another_cell
예제 #10
0
    def retrain(self, pre_block):
        '''
        Method for retrain the whole network
        :param pre_block:
        :return:
        '''
        tf.reset_default_graph()
        self.train_num = 50000
        self.block_num = len(pre_block) * NAS_CONFIG['nas_main']['repeat_num']

        retrain_log = "-" * 20 + "retrain" + "-" * 20 + '\n'

        data_x, labels, block_input, train_flag = self._get_input('', [])
        for block in pre_block:
            self.block_num += 1
            cell_list = []
            for cell in block.cell_list:
                if cell.type == 'conv':
                    cell_list.append(
                        Cell(cell.type, cell.filter_size * 2, cell.kernel_size,
                             cell.activation))
                else:
                    cell_list.append(cell)
            # repeat search
            graph_full, cell_list = self._recode(
                block.graph, block.cell_list,
                NAS_CONFIG['nas_main']['repeat_num'])
            # add pooling layer only in last repeat block
            cell_list.append(Cell('pooling', 'max', 2))
            graph_full.append([])
            retrain_log = retrain_log + str(graph_full) + str(cell_list) + '\n'
            block_input = self._inference(block_input, graph_full, cell_list,
                                          train_flag)

        sess = tf.Session()
        precision, log = self._eval(sess,
                                    block_input,
                                    data_x,
                                    labels,
                                    train_flag,
                                    retrain=True)
        sess.close()
        retrain_log += log
        NAS_LOG = Logger()
        NAS_LOG << ('eva_eva', retrain_log)
        return float(precision)
예제 #11
0
 def _construct_nblks(self, mid_plug, blks, first_blk_id):
     blk_id = first_blk_id
     for blk in blks:
         graph_full, cell_list = blk
         graph_full, cell_list = self._recode_repeat_blk(
             graph_full, cell_list, self.repeat_num)
         # add the last node
         graph_full = graph_full + [[]]
         if self.use_pooling_blk_end:
             cell_list = cell_list + [Cell('pooling', 'max', 2)]
         else:
             cell_list = cell_list + [Cell('id', 'max', 1)]
         mid_plug = self._construct_blk(mid_plug, graph_full, cell_list,
                                        self.train_flag, blk_id)
         self.run_ops['block{}_end'.format(blk_id)] = mid_plug
         blk_id += 1
     return mid_plug
예제 #12
0
def test_has_neighbors() -> None:
    a_cell = Cell(1, 1)
    another_cell = Cell(1, 2)
    yet_another_cell = Cell(2, 1)

    a_cell.north = another_cell
    another_cell.south = yet_another_cell
    yet_another_cell.east = another_cell
    yet_another_cell.west = a_cell

    assert another_cell in a_cell.neighbours
    assert yet_another_cell not in a_cell.neighbours
    assert a_cell.nNeighbours == 1
    assert a_cell not in another_cell.neighbours
    assert yet_another_cell in another_cell.neighbours
    assert another_cell.nNeighbours == 1
    assert a_cell in yet_another_cell.neighbours
    assert another_cell in yet_another_cell.neighbours
    assert yet_another_cell.nNeighbours == 2
예제 #13
0
    def retrain(self, pre_block):
        tf.reset_default_graph()
        assert self.train_num >= self.batch_size
        self.block_num = len(
            pre_block) * NAS_CONFIG['eva']['repeat_search'] + 1

        retrain_log = "-" * 20 + "retrain" + "-" * 20 + '\n'
        for block in pre_block:
            retrain_log = retrain_log + str(block.graph) + str(
                block.cell_list) + '\n'

        with tf.Session() as sess:
            data_x, labels, logits, train_flag = self._get_input(sess, [])

            for i, block in enumerate(pre_block):
                graph = block.graph + [[]]
                cell_list = []
                for cell in block.cell_list:
                    if cell.type == 'conv':
                        cell_list.append(
                            Cell(cell.type, cell.filter_size * 2,
                                 cell.kernel_size, cell.activation))
                    else:
                        cell_list.append(cell)
                cell_list.append(Cell('pooling', 'max', 2))
                logits = self._inference(logits, graph, cell_list, train_flag)
                self.block_num += 1

            logits = tf.nn.dropout(logits, keep_prob=1.0)
            # softmax
            logits = self._makedense(logits,
                                     ('', [256, self.NUM_CLASSES], 'relu'))

            precision, _, log = self._eval(sess,
                                           data_x,
                                           labels,
                                           logits,
                                           train_flag,
                                           retrain=True)
            retrain_log += log

        NAS_LOG << ('eva', retrain_log)
        return float(precision)
예제 #14
0
def test_max_distance() -> None:
    cell_1 = Cell(0, 0)
    distances = Distances(cell_1)

    cell_2 = Cell(0, 1)
    distance_from_2_to_1 = 4
    distances[cell_2] = distance_from_2_to_1

    cell_3 = Cell(1, 0)
    distance_from_3_to_1 = 5
    distances[cell_3] = distance_from_3_to_1

    cell_4 = Cell(2, 0)
    distance_from_4_to_1 = 8
    distances[cell_4] = distance_from_4_to_1

    assert distances.max == (
        cell_4,
        distance_from_4_to_1,
    )
예제 #15
0
    def convert(self, table_tmp):
        """Search corresponding operation configuration based on table."""
        self._p_table = copy.deepcopy(table_tmp)
        res = []
        l = 0
        r = 0
        graph_part_sample = copy.deepcopy(self._graph_part)
        for num in range(self._node_number):
            l = r
            r = l + len(self._dic_index) + self._cross_node_number
            p_node = self._p_table[l:r]  # Take the search space of a node
            node_cross_tmp = list(
                set(copy.deepcopy(p_node[len(self._dic_index):])))
            for i in node_cross_tmp:
                if i != 0:
                    graph_part_sample[num].append(self._crosslayer[num][i - 1])
            if not graph_part_sample[num]:
                graph_part_sample[num].append(self._node_number)

            first = p_node[self._dic_index['conv'][-1]]
            tmp = ()
            if self._pattern == "Block":
                first = 0
            if first == 0:  # Search operation under conv
                tmp = tmp + ('conv', )
                space_conv = ['filter_size', 'kernel_size', 'activation']
                for key in space_conv:
                    # for key in self._setting['conv']:
                    tmp = tmp + (self._setting['conv'][key][p_node[
                        self._dic_index['conv ' + key][-1]]], )
                tmp = Cell(tmp[0], tmp[1], tmp[2], tmp[3])
            else:  # Search operation under pooling
                tmp = tmp + ('pooling', )
                space_pool = ['pooling_type', 'kernel_size']
                for key in space_pool:
                    # for key in self._setting['pooling']:
                    tmp = tmp + (self._setting['pooling'][key][p_node[
                        self._dic_index['pooling ' + key][-1]]], )
                tmp = Cell(tmp[0], tmp[1], tmp[2])
            res.append(tmp)
        return res, graph_part_sample
예제 #16
0
def lifegame_next(matrix):
    new = {}
    for point, cell in matrix.cells.items():
        sub = matrix.get_area(point, 1)
        for x, line in enumerate(sub):
            for y, cell in enumerate(line):
                abspoint = Point(point.x + x - 1, point.y + y - 1)
                num = area_lifenum(matrix.get_area(abspoint, 1))
                if cell:
                    num -= 1
                if num == 3 or (cell and num == 2):
                    new[abspoint] = Cell(abspoint, True)
    return new
예제 #17
0
    def convert(self, table_tmp):
        """Search corresponding operation configuration based on table."""
        self._p_table = copy.deepcopy(table_tmp)
        res = []
        l = 0
        r = 0
        graph_part_sample = copy.deepcopy(self._graph_part)
        for num in range(self._node_number):
            l = r
            r = l + len(self._dic_index)
            if self._graph_part_invisible_node_flag[num] == 1:
                r = r + self._cross_node_number

            p_node = self._p_table[l:r]  # Take the search space of a node
            # print(p_node)
            node_cross_tmp = list(set(copy.deepcopy(p_node[len(self._dic_index):])))
            for i in node_cross_tmp:
                if i != 0:
                    graph_part_sample[num].append(self._crosslayer[num][i - 1])
            if not graph_part_sample[num]:
                graph_part_sample[num].append(self._node_number)

            for cnt, key_type in enumerate(self._setting):
                if p_node[self._dic_index['type'][-1]] == cnt:
                    tmp = (key_type,)

                    item_list = Cell.get_format(key_type)

                    for key_item in item_list:
                        tmp = tmp + (self._setting[key_type][key_item]
                                     [p_node[self._dic_index[key_type + ' ' + key_item][-1]]],)
            # print(tmp)
            tmp = Cell(tmp)
            res.append(tmp)

        return res, graph_part_sample
예제 #18
0
def test_distances() -> None:
    a_cell = Cell(0, 0)
    another_cell = Cell(0, 1)
    yet_another_cell = Cell(0, 2)

    a_cell.east = another_cell
    a_cell += another_cell
    another_cell.east = yet_another_cell
    another_cell += yet_another_cell
    distances = a_cell.distances
    assert set(distances.cells) == {yet_another_cell, another_cell, a_cell}
    assert distances[a_cell] == 0
    assert distances[another_cell] == 1
    assert distances[yet_another_cell] == 2
예제 #19
0
    def evaluate(self, network, pre_block=[], is_bestNN=False, update_pre_weight=False):
        '''Method for evaluate the given network.
            
        :param network: NetworkItem()
        :param pre_block: The pre-block structure, every block has two parts 'graph_part' and 'cell_list' of this block.
        :param is_bestNN: Symbol for indicating whether the evaluating network is the best network of this round.
        :param update_pre_weight: Symbol for indicating whether to update previous blocks' weight.
        :return: accuracy, float.
        '''
        assert self.train_num >= self.batch_size
        tf.reset_default_graph()
        self.block_num = len(pre_block)

        self.log = "-" * 20 + str(network.id) + "-" * 20 + '\n'
        for block in pre_block:
            self.log = self.log + str(block.graph) + str(block.cell_list) + '\n'
        self.log = self.log + str(network.graph) + str(network.cell_list) + '\n'


        with tf.Session() as sess:
            data_x, data_y, block_input, train_flag = self._get_input(sess, pre_block, update_pre_weight)

            graph_full, cell_list = self._recode(network.graph, network.cell_list,
                                                 NAS_CONFIG['nas_main']['repeat_num'])
            # a pooling layer for last repeat block
            graph_full = graph_full + [[]]
            cell_list = cell_list + [Cell('pooling', 'max', 2)]
            logits = self._inference(block_input, graph_full, cell_list, train_flag)

            logits = tf.nn.dropout(logits, keep_prob=1.0)
            logits = self._makedense(logits, ('', [self.output_shape[-1]], ''))

            precision, log = self._eval(sess, logits, data_x, data_y, train_flag)
            self.log += log

            saver = tf.train.Saver(tf.global_variables())

            if is_bestNN:  # save model
                if not os.path.exists(os.path.join(self.model_path)):
                    os.makedirs(os.path.join(self.model_path))
                saver.save(sess, os.path.join(self.model_path, 'model' + str(network.id)))

        NAS_LOG << ('eva', self.log)
        return precision
def test_neighbors_setup_when_grid_is_created() -> None:
    grid = Grid(2, 2)

    assert grid[0, 0].north is None  # type: ignore
    assert grid[0, 0].south == Cell(1, 0)  # type: ignore
    assert grid[0, 0].east == Cell(0, 1)  # type: ignore
    assert grid[0, 0].west is None  # type: ignore

    assert grid[0, 1].north is None  # type: ignore
    assert grid[0, 1].south == Cell(1, 1)  # type: ignore
    assert grid[0, 1].east is None  # type: ignore
    assert grid[0, 1].west == Cell(0, 0)  # type: ignore

    assert grid[1, 0].north == Cell(0, 0)  # type: ignore
    assert grid[1, 0].south is None  # type: ignore
    assert grid[1, 0].east == Cell(1, 1)  # type: ignore
    assert grid[1, 0].west is None  # type: ignore

    # TODO: None Cell class
    assert grid[1, 1].north == Cell(0, 1)  # type: ignore
    assert grid[1, 1].south is None  # type: ignore
    assert grid[1, 1].east is None  # type: ignore
    assert grid[1, 1].west == Cell(1, 0)  # type: ignore
예제 #21
0
if __name__ == '__main__':
    os.environ["CUDA_VISIBLE_DEVICES"] = "0"
    eval = Evaluator()
    eval.set_data_size(5000)
    eval.set_epoch(1)
    # graph_full = [[1], [2], [3], []]
    # cell_list = [Cell('conv', 64, 5, 'relu'), Cell('pooling', 'max', 3), Cell('conv', 64, 5, 'relu'),
    #              Cell('pooling', 'max', 3)]
    # lenet = NetworkItem(0, graph_full, cell_list, "")
    # e = eval.evaluate(lenet, [], is_bestNN=True)
    # Network.pre_block.append(lenet)

    graph_full = [[1, 3], [2, 3], [3], [4]]
    cell_list = [
        Cell('conv', 24, 3, 'relu'),
        Cell('conv', 32, 3, 'relu'),
        Cell('conv', 24, 3, 'relu'),
        Cell('conv', 32, 3, 'relu')
    ]
    network1 = NetworkItem(0, graph_full, cell_list, "")
    network2 = NetworkItem(1, graph_full, cell_list, "")
    e = eval.evaluate(network1, is_bestNN=True)
    print(e)
    eval.set_data_size(500)
    e = eval.evaluate(network2, [network1], is_bestNN=True)
    print(e)
    eval.set_epoch(2)
    print(eval.retrain([network1, network2]))
    # eval.add_data(5000)
    # print(eval._toposort([[1, 3, 6, 7], [2, 3, 4], [3, 5, 7, 8], [
예제 #22
0
def lifegame_init(matrix):
    matrix.put(Cell(Point(0, 1), True))
    matrix.put(Cell(Point(1, 1), True))
    matrix.put(Cell(Point(2, 1), True))
예제 #23
0
    def _train_op(self, global_step, loss):
        # TODO change here for learning rate and optimizer
        return train_op

    def _cal_multi_target(self, precision, time):
        # TODO change here for target calculating
        return target

    def set_data_size(self, num):
        if num > len(list(self.train_label)) or num < 0:
            num = len(list(self.train_label))
            print('Warning! Data size has been changed to', num, ', all data is loaded.')
        self.train_num = num
        return


if __name__ == '__main__':
    os.environ["CUDA_VISIBLE_DEVICES"] = "1"
    eval = Evaluator()
    eval.set_data_size(50000)
    eval.set_epoch(10)

    graph_full = [[1, 3], [2, 3], [3], [4]]
    cell_list = [Cell('conv', 24, 3, 'relu'), Cell('conv', 32, 3, 'relu'), Cell('conv', 24, 3, 'relu'),
                 Cell('conv', 32, 3, 'relu')]
    network1 = NetworkItem(0, graph_full, cell_list, "")
    network2 = NetworkItem(1, graph_full, cell_list, "")
    e = eval.evaluate(network1, is_bestNN=True)
    eval.set_data_size(500)
    e = eval.evaluate(network2, [network1], is_bestNN=True)
예제 #24
0
    eval = Evaluator()
    eval._set_data_size(1000)
    eval._set_epoch(10)
    # graph_full = [[1], [2], [3], []]
    # cell_list = [Cell('conv', 64, 5, 'relu'), Cell('pooling', 'max', 3), Cell('conv', 64, 5, 'relu'),
    #              Cell('pooling', 'max', 3)]
    # lenet = NetworkItem(0, graph_full, cell_list, "")
    # e = eval.evaluate(lenet, [], is_bestNN=True)
    # Network.pre_block.append(lenet)

    # graph_full = [[1, 3], [2, 3], [3], [4]]
    # cell_list = [Cell('conv', 24, 3, 'relu'), Cell('conv', 32, 3, 'relu'), Cell('conv', 24, 3, 'relu'),
    #              Cell('conv', 32, 3, 'relu')]
    graph_full = [[1, 3], [2, 4], [4], [2]]
    cell_list = [
        Cell('sep_conv', 32, 5, 'relu6'),
        Cell('sep_conv', 32, 3, 'relu6'),
        Cell('pooling', 'avg', 3),
        Cell('pooling', 'avg', 8)
    ]
    network1 = NetworkItem(0, graph_full, cell_list, "")
    network2 = NetworkItem(1, graph_full, cell_list, "")
    e = eval.evaluate(network1, is_bestNN=True)
    print(e)
    # eval.set_data_size(10000)
    # e = eval.evaluate(network2, [network1], is_bestNN=True)
    # print(e)
    eval._set_epoch(1)
    print(eval.retrain([network1, network2]))
    # eval.add_data(5000)
    # print(eval._toposort([[1, 3, 6, 7], [2, 3, 4], [3, 5, 7, 8], [
예제 #25
0
 def __setstate__(self, state):
     self = Cell(*state)
예제 #26
0
    eval = Evaluator()
    cur_data_size = eval._set_data_size(10000)
    cur_epoch = eval._set_epoch(1)

    # graph_full = [[1]]
    # cell_list = [Cell('conv', 64, 3, 'relu')]
    # network1 = NetworkItem(0, graph_full, cell_list, "")
    # task_item = EvaScheduleItem(nn_id=0, alig_id=0, graph_template=[], item=network1,\
    #      pre_blk=[], ft_sign=True, bestNN=True, rd=0, nn_left=0, spl_batch_num=6, epoch=20, data_size=cur_data_size)
    # e = eval.evaluate(task_item)
    # print(e)

    graph_full = [[1, 6, 2, 3], [2, 3, 4], [3, 8, 5], [4, 5], [5], [10], [7],
                  [5], [9], [5]]
    cell_list = [
        Cell('conv', 64, 3, 'leakyrelu'),
        Cell('sep_conv', 32, 3, 'relu'),
        Cell('conv', 64, 3, 'leakyrelu'),
        Cell('conv', 32, 3, 'relu'),
        Cell('conv', 64, 1, 'relu6'),
        Cell('conv', 48, 3, 'relu'),
        Cell('sep_conv', 64, 3, 'relu6'),
        Cell('sep_conv', 32, 1, 'leakyrelu'),
        Cell('sep_conv', 64, 5, 'leakyrelu'),
        Cell('conv', 48, 1, 'relu')
    ]
    network1 = NetworkItem(0, graph_full, cell_list, "")
    graph_full = [[1, 6, 7, 2, 3], [2, 3], [3, 4, 5], [4, 5], [5], [9], [3],
                  [8], [3]]
    cell_list = [
        Cell('conv', 128, 3, 'relu6'),
예제 #27
0
def test_equality() -> None:
    a_cell = Cell(1, 1)
    another_cell = Cell(1, 1)
    assert a_cell == another_cell
예제 #28
0
            num = len(list(self.train_label))
            print('Warning! Data size has been changed to', num,
                  ', all data is loaded.')
        self.train_num = num
        return


if __name__ == '__main__':
    os.environ["CUDA_VISIBLE_DEVICES"] = "1"
    eval = Evaluator()
    eval._set_data_size(-1)
    eval._set_epoch(50)
    eval._load_data()

    graph_full = [[1]]
    cell_list = [Cell('conv', 128, 3, 'relu')]
    for i in range(2, 19):
        graph_full.append([i])
        cell_list.append(Cell('conv', 64, 3, 'relu'))
    graph_full.append([])
    cell_list.append(Cell('conv', 64, 3, 'relu'))

    # graph_full = [[1, 3], [2, 3], [3], [4]]
    # cell_list = [Cell('conv', 128, 3, 'relu'), Cell('conv', 32, 3, 'relu'), Cell('conv', 24, 3, 'relu'),
    #              Cell('conv', 32, 3, 'relu')]
    network1 = NetworkItem(0, graph_full, cell_list, "")
    network2 = NetworkItem(1, graph_full, cell_list, "")
    e = eval.evaluate(network1, is_bestNN=True)
    eval._set_data_size(500)
    e = eval.evaluate(network2, [network1], is_bestNN=True)
예제 #29
0
def test_cell(item):
    print("子进程", item.cell_list, item.graph,type(item.cell_list[0]))


if __name__ == "__main__":
    from base import Network, NetworkItem, Cell
    #初始化一个Network
    Net = Network(0, [[1], [2], [3], []])


    cellist = [('conv', 512, 5, 'relu'), ('pooling',
                                        'max', 3), ('pooling', 'max', 2), ]
    cell_list = []
    for x in cellist:
        if len(x) == 4:
            cell_list.append(Cell(x[0], x[1], x[2], x[3]))
        else:
            cell_list.append(Cell(x[0], x[1], x[2]))
    #初始化一个NetworkItem
    item = NetworkItem(0, [[1], [2], [3], []], cell_list, "")
    print(type(cell_list))
    Net.item_list.append(item)

    print(Net.item_list[0])
    print("主进程", Net.item_list[0].cell_list)
    #测试子进程的cell_list


    pool = Pool(2)
    result = pool.apply_async(test_cell, args=(Net.item_list[0],))
    pool.close()
예제 #30
0
def test_has_no_neighbors() -> None:
    assert Cell(1, 1).neighbours == []