Beispiel #1
0
class Model_Performance():
    '''

    '''
    def __init__(self, checkpoint_path, model_name):
        self.chkpoint = checkpoint_path
        self.app = Application(load_path=checkpoint_path,
                               model_name=model_name)
        self.datahelper = DataHelper()

    def CrossArchTestFast(self, arch1, arch2):
        '''
        :param arch1: path to sqlite database
        :param arch2: path to sqlite database
        :return:
        '''
        pairs = self.datahelper.get_cross_archtecture_pair(arch1, arch2)

        result = []
        lables = []
        pool = mp.Pool(processes=10)
        start_time = datetime.now()
        pairs = pairs[0:10]
        for (source, target, label) in tqdm(pairs, desc="Sim Computing."):
            source_tree = source[-1]
            target_tree = target[-1]
            lables.append(label)
            result.append(
                pool.apply_async(self.app.similarity_tree, (
                    source_tree,
                    target_tree,
                )))
        pool.close()
        pool.join()
        predictions = []
        for res in result:
            predictions.append(res.get())
        time_cost = (datetime.now() - start_time).seconds
        fpr, tpr, thresholds = roc_curve(np.array(lables),
                                         np.array(predictions))
        logger.info("===> architecture info : %s vs %s" % (arch1, arch2))
        logger.info("===> time: %s" % (datetime.now()))
        logger.info("model: %s" % self.chkpoint)
        logger.info(
            "compute %d function pairs, which cost %d seconds; %f pairs per sec"
            % (len(pairs), time_cost, len(pairs) * 1.0 / time_cost))
        logger.info("predictions= %s" % json.dumps(predictions))
        logger.info("labels= %s" % json.dumps(lables))
        logger.info("fpr= %s" % json.dumps(fpr.tolist()))
        logger.info("tpr= %s" % json.dumps(tpr.tolist()))
        logger.info("thresholds= %s" % json.dumps(thresholds.tolist()))