Esempio n. 1
0
 def __init__(self, pool):
     NAS_LOG << "init_ing"
     self.enu = Enumerater()
     self.eva = Evaluator()
     self.com = Communication()
     self.ds = DataSize(self.eva)
     self.pool = pool
Esempio n. 2
0
def _module_init():
    enu = Enumerater(depth=NAS_CONFIG["depth"],
                     width=NAS_CONFIG["width"],
                     max_branch_depth=NAS_CONFIG["max_depth"])
    eva = Evaluator()

    return enu, eva
Esempio n. 3
0
class Nas:
    def __init__(self, pool):
        NAS_LOG << "init_ing"
        self.enu = Enumerater()
        self.eva = Evaluator()
        self.com = Communication()
        self.ds = DataSize(self.eva)
        self.pool = pool

    def run(self):
        NAS_LOG << 'enuming'
        network_pool_tem = self.enu.enumerate()
        start_search = time.time()
        for i in range(MAIN_CONFIG["block_num"]):
            NAS_LOG << ('search_blk', i + 1, MAIN_CONFIG["block_num"])
            start_block = time.time()
            network_item = algo(i, self.eva, self.com, self.ds,
                                network_pool_tem, self.pool)
            Network.pre_block.append(network_item)
            NAS_LOG << ('search_blk_end', time.time() - start_block)
        NAS_LOG << ('nas_end', time.time() - start_search)
        for block in Network.pre_block:
            NAS_LOG << ('pre_block', str(block.graph), str(block.cell_list))
        start_retrain = time.time()
        retrain_score = _retrain(self.eva, self.com, self.pool)
        NAS_LOG << ('retrain_end', retrain_score, time.time() - start_retrain)
        return Network.pre_block, retrain_score
Esempio n. 4
0
class Nas:
    def __init__(self):
        _check_log()
        NAS_LOG << "nas_init_ing"
        self.enu = Enumerater()
        self.eva = Evaluator() if not MAIN_CONFIG['eva_mask'] else None
        self.ds = DataSize(self.eva)

    def run(self):
        NAS_LOG << 'nas_enuming'
        network_pool_tem = self.enu.enumerate()
        time_search = TimeCnt()
        start_search = time_search.start()
        NAS_LOG << ('nas_start_search', start_search)
        Stage_Info['nas_start'] = start_search
        for i in range(MAIN_CONFIG["block_num"]):
            network_item = _search_blk(i, self.eva, self.ds, network_pool_tem)
            Network.pre_block.append(network_item)
        end_search = time_search.stop()
        NAS_LOG << ('nas_search_end', end_search)
        Stage_Info['nas_cost'] = end_search
        _dump_stage(Stage_Info)

        _retrain(self.eva, self.ds)
        for block in Network.pre_block:
            NAS_LOG << ('nas_pre_block', str(block.graph), str(
                block.cell_list))
        return Network.pre_block
Esempio n. 5
0
 def test_predictor(self):
     pred = Predictor()
     _depth = random.randint(0, 25)
     _width = random.randint(0, 1)
     _max_depth = random.randint(0, _depth)
     # print('##', self._depth, self._width, self._max_depth)
     NAS_CONFIG['enum']['depth'] = _depth
     NAS_CONFIG['enum']['width'] = _width
     NAS_CONFIG['enum']['max_depth'] = _max_depth
     enum = Enumerater()
     network_pool = enum.enumerate()
     blocks, graph = self._data_sample(network_pool)
     ops = pred.predictor(blocks, graph)
     self.assertEqual(list, type(ops))
     self.assertTrue(len(ops) == len(graph))
     for op in ops:
         if op[0] != 'pooling':
             self.assertGreater(int(op[0]), 1)
             self.assertLessEqual(int(op[0]), 1024)
             self.assertGreater(int(op[1]), 0)
             self.assertLessEqual(int(op[1]), 11)
Esempio n. 6
0
class Test_spl(unittest.TestCase):
    global test_info
    test_info = []
    for i in range(1000):
        _depth = random.randint(3, 25)
        _width = random.randint(0, 1)
        _max_depth = random.randint(0, _depth)
        # print('##', self._depth, self._width, self._max_depth)
        NAS_CONFIG['enum']['depth'] = _depth
        NAS_CONFIG['enum']['width'] = _width
        NAS_CONFIG['enum']['max_depth'] = _max_depth
        enum = Enumerater()
        _network_list = enum.enumerate()
        ind = random.randint(0, len(_network_list)-1)
        _graph_part = _network_list[ind].graph_template
        test_info.append([_graph_part])

    with open('./test/test_spl.txt', 'w') as op:
        for i in test_info:
            op.writelines('graph:' + str(i[0]) + '\n')
            op.writelines('###'*20 + '\n')

    def _run_module(self, graph_part):
        spl = Sampler(graph_part, 0)
        cell, graph, table = spl.sample()
        # pred = Predictor()
        # ops = pred.predictor([], graph_part)
        # table_ops = spl.ops2table(ops, table)
        # return cell, graph, table, table_ops
        return cell, graph, table

    def _judge_cell(self, cell):
        self.assertEqual(list, type(cell))
        for i in cell:
            self.assertEqual(Cell, type(i))

    def _judge_graph(self, graph):
        self.assertEqual(list, type(graph))

    def _judge_table(self, table):
        self.assertEqual(list, type(table))

    @data(*test_info)
    def test_res(self, para):
        # print('####', para[0])
        # cell, graph, table, table_ops = self._run_module(para[0])
        cell, graph, table = self._run_module(para[0])
        self._judge_cell(cell)
        self._judge_graph(graph)
        self._judge_table(table)
Esempio n. 7
0
class Test_eva(unittest.TestCase):
    global test_info
    test_info = []
    for i in range(10):
        _depth = random.randint(3, 25)
        _width = random.randint(0, 1)
        _max_depth = random.randint(0, _depth)
        # print('##', self._depth, self._width, self._max_depth)
        NAS_CONFIG['enum']['depth'] = _depth
        NAS_CONFIG['enum']['width'] = _width
        NAS_CONFIG['enum']['max_depth'] = _max_depth
        enum = Enumerater()
        _network_list = enum.enumerate()
        ind = random.randint(0, len(_network_list)-1)
        _graph_part = _network_list[ind].graph_template
        # for i in self._network_list[ind].graph_template:
        #     if i:
        #         self._graph_part.append(i)
        #     else:
        #         self._graph_part.append([len(self._network_list[ind].graph_template)])
        # print(self._graph_part)
        _cell_list = _random_get_cell(len(_graph_part))
        test_info.append((_graph_part, _cell_list))

    with open('./test/test_eva.txt', 'w') as op:
        for i in test_info:
            op.writelines('graph:' + str(i[0]) + '\n')
            op.writelines('cell_list:' + str(i[1]) + '\n')
            op.writelines('###'*20 + '\n')

    def _run_module(self, _graph_part, _cell_list):
        eva = Evaluator()
        eva.add_data(500)
        tmp = NetworkItem(0, _graph_part, _cell_list, "")
        return eva.evaluate(tmp, is_bestNN=True)

    def _judge_score(self, score):
        self.assertEqual(float, type(score))

    @data(*test_info)
    def test_res(self, para):
        print(para[0])
        print(para[1])
        score = self._run_module(para[0], para[1])
        self._judge_score(score)
Esempio n. 8
0
        self._save_model(model=self.model,
                         json_path=model_json_path,
                         weights_path=model_weights_path)

        self._save_data(x_train, y_train)


if __name__ == '__main__':
    # graph = [[[1], [2], [3], [4], [5], []]]
    # cell_list = [[('conv', 256, 3, 'relu'), ('conv', 192, 3, 'relu'), ('conv', 512, 1, 'relu'), ('pooling', 'max', 4)
    #                  , ('conv', 128, 1, 'relu'), ('conv', 512, 5, 'relu')]]
    # pred = Predictor()
    # Blocks = []
    # pred.train([], [])

    enu = Enumerater(depth=6, width=3)
    network_pool = enu.enumerate()
    print(len(network_pool))
    start = time.time()
    i = 0
    pred = Predictor()
    for ind in range(2, len(network_pool)):
        gra = network_pool[ind].graph_part

        #Blocks = [network_pool[ind - 2].graph_part, network_pool[ind - 1].graph_part]
        Blocks = []
        cell_list = pred.predictor(Blocks, gra)
        if i % 100 == 0:
            print("iterator:", i)
        i += 1
        print(gra)
Esempio n. 9
0
 def _run_module(self):
     enum = Enumerater()
     return enum.enumerate()
Esempio n. 10
0
 def __init__(self):
     _check_log()
     NAS_LOG << "nas_init_ing"
     self.enu = Enumerater()
     self.eva = Evaluator() if not MAIN_CONFIG['eva_mask'] else None
     self.ds = DataSize(self.eva)