コード例 #1
0
ファイル: firefoxutil.py プロジェクト: 18811358710/JD
    def GetWindowPages(self):
        filepath = "E:/PycharmProjects/jd-login/screenshot/"
        rq = time.strftime('%Y%m%d%H%M', time.localtime(time.time()))
        filename = filepath + rq + '.png'

        self.driver.get_screenshot_as_file(filename)
        logger.info("Had taken screenshot and save to folder : /screenshot")
コード例 #2
0
ファイル: firefoxutil.py プロジェクト: 18811358710/JD
    def OpenFirefox(self, url):
        self.driver = webdriver.Firefox()
        logger.info("starting firefox browser")

        self.driver.maximize_window()
        logger.info("maximize the current window")
        self.driver.get(url)
        logger.info("open the url:%s" % url)
        time.sleep(2)
        logger.info("set time sleep 2 seconds")
コード例 #3
0
def boot(script: str, config: str, gpu: str, push_message: bool):
    """
    启动入口,运行script,把config传给它。
    :param script: exp_multi_points.unet_split_rgb_casia2_multi_point_400_input_relation_evaluate
    :param config: 例如 exp_test.print_config
    :param gpu: 快速覆盖gpu的设置
    :param push_message: 是否推送崩溃消息
    """
    if push_message:
        logger.info('push service on crash: ON!')
    if '/' in config or config.endswith('.py'):
        config = path_to_package(config)
    if '/' in script or script.endswith('.py'):
        script = path_to_package(script)
    config_mod = importlib.import_module(config)
    assert hasattr(config_mod, 'get_config'), logger.error(f'no module {config}')
    config = config_mod.get_config()
    assert isinstance(config, BasicConfig)

    if gpu:
        config.gpu = gpu
    config.build()

    if not script:
        script = config.script

    script_mod = importlib.import_module(script)
    assert hasattr(script_mod, 'main'), logger.error(f'no module {script}')
    try:
        script_mod.main(config)
    except Exception as e:
        if push_message:
            framework.notification.crash_push_service.push(
                title=f'Crash on task',
                message=f'Crash on task {script}\n\n{e}',
                push_service_token=sendkey,
            )
コード例 #4
0
ファイル: al_metrics.py プロジェクト: yuzhiw/ALFramework
def dpc_entropy_fusion(model, data_container, num_select):
    features = data_container.unlabeled_features
    labels = np.array(data_container.all_data['label'].tolist())
    embeddings = data_container.unlabeled_embeddings
    # _preds shape:(num_samples, num_classes)
    # _entropys shape: (num_samples,)
    _preds, _entropys = model.get_entropy(features)

    # Select 'num_select' samples.
    if np.alen(_entropys) > num_select * 3:
        _max_entropy_indices = np.argsort(_entropys)[-num_select * 3:]
    else:
        _max_entropy_indices = np.array([i for i in range(len(_entropys))])

    logger.info('Max entropy distribution: %s' % Counter(labels[_max_entropy_indices]))

    if np.alen(_max_entropy_indices) > num_select:
        # Cluster
        # embeddings = model.embedding(features[_max_entropy_indices])
        dpc = DensityPeaksCluster(num_select, auto_choose_dc=True)
        dpc.fit(embeddings[_max_entropy_indices])

        # Max rho selection.
        # _max_rho_indices = np.argsort(dpc.rho, axis=0)[-num_select:]
        # _selected = _max_entropy_indices[_max_rho_indices]

        # Cluster centers selection.
        # _center_indices = [int(i) for i in dpc.cluster_center.values()]
        # _selected = _max_entropy_indices[_center_indices]

        # Max delta and centers selection
        _center_indices = [int(i) for i in dpc.cluster_center.values()]
        _center_indices = np.random.choice(_center_indices, 150, replace=False)
        _left_indices = np.array(list(set([i for i in range(len(_max_entropy_indices))]) - set(_center_indices)))
        _sorted_delta = np.argsort(-dpc.delta)  # Descending sort
        _max_delta_indices = list(set(_left_indices).intersection(set(_sorted_delta)))[:50]
        _selected = np.concatenate([_center_indices, _max_delta_indices])
        _selected = _max_entropy_indices[_selected]
    else:
        _selected = _max_entropy_indices

    # logger.info('DPC-Entropy distribution: %s' % Counter(labels[_center_indices]))
    logger.info('DPC-Entropy distribution: %s' % Counter(labels[_selected]))
    logger.info('DPC-Entropy finished,%d selected.' % len(_selected))

    return ActiveSamples(
        selected=np.squeeze(_selected),
        pseudo_labeled=None,
        pseudo_labels=None)
コード例 #5
0
 def build(self):
     self.init_path()
     self.path_to_package()
     os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
     os.environ["CUDA_VISIBLE_DEVICES"] = self.gpu
     logger.info('------experiment overview------')
     logger.info(f'script name: {self.script}')
     logger.info(f'save_path: {self.save_path}')
     logger.info(f'visdom_env: {self.visdom_env}')
     logger.info(f'input size: {self.input_size}')
     logger.info(f'batch size: {self.batch_size}')
     logger.info(f'gpu use: {self.gpu}')
コード例 #6
0
ファイル: firefoxutil.py プロジェクト: 18811358710/JD
 def GetTitle(self):
     return self.driver.title
     logger.info("get the title of current page")
コード例 #7
0
ファイル: firefoxutil.py プロジェクト: 18811358710/JD
 def ClearKeys(self, widget):
     self.Findid(widget).clear()
     logger.info("now clear the keys of inputbox ")
コード例 #8
0
ファイル: firefoxutil.py プロジェクト: 18811358710/JD
 def SendKeys(self, tab, text):
     tab = self.Findid(tab)
     tab.send_keys(text)
     logger.info("send %s into the inputbox" % text)
コード例 #9
0
ファイル: firefoxutil.py プロジェクト: 18811358710/JD
 def Click(self, tab):
     tabr = self.FindClassname(tab)
     tabr.click()
     logger.info("click the login tab")
コード例 #10
0
ファイル: firefoxutil.py プロジェクト: 18811358710/JD
 def CloseFirfox(self):
     self.driver.quit()
     logger.info("now,quit the browser")
コード例 #11
0
 def TitleAssert(self, self1, excepts):
     title = self.driver.GetTitle()
     self1.assertEqual(title, excepts)
     logger.info("add the assert of %s" % excepts)
コード例 #12
0
 def ClassNameAssert(self, self1, excepts, classname):
     message = self.driver.FindClassname(classname).text
     self1.assertEqual(message, excepts)
     logger.info("add the assert of %s" % excepts)