Exemplo n.º 1
0
def Eval(path, net_path=None):
    img, expand, scale = resize(cv2.imread(path))
    data = torch.tensor(img.transpose([2, 0, 1]) / 255 - 0.5,
                        dtype=torch.float32).unsqueeze(dim=0)
    setting = init_settings()
    if net_path:
        setting['net_path'] = net_path
        print('[{}]指定的网络文件路径已起效'.format(datetime.datetime.now()))
    yolo = Detector(setting['net_path'])

    startTime = time.time()
    boxes = yolo.detect(
        data, 0.5, setting['anchors'])  # Box <- [batch,confi,cx,cy,w,h,cls]
    boxes = boxes.cpu()
    stopTime = time.time()
    print('* ------------------------------------------ *')
    print('* PROCESSING TIME COST : {}'.format(stopTime - startTime))

    if boxes.size()[0] == 0:
        print('* NO THINGS CAUGHT')
        return boxes.numpy()

    frame = nms(
        boxes, 0.5,
        True).cpu().detach().numpy()  # box_idx, [N, IOU, CX, CY, W, H, CLS]
    frame[:, 2:6] = return2RealPosition(frame[:, 2:6], expand, scale)
    print('* NUM OF BOXES : {} / {}'.format(frame.shape[0], boxes.size()[0]))
    return frame
Exemplo n.º 2
0
 def __init__(self):
     app = wx.App(False)
     settings = utils.init_settings()
     if settings['storepages']:
         win_info, page_dict = utils.init_page_dict()
     else:
         win_info = (wx.DefaultPosition, wx.DefaultSize)
         page_dict = {}
     frame = MainFrame(None, sys.argv[1:], settings,
                       win_info[0], win_info[1],
                       page_dict)
     frame.Show()
     app.MainLoop()
Exemplo n.º 3
0
def Eval(path, net_path=None, img=None):
    """
    网络的使用函数
    :param img: 可选参数,可传入图片数据
    :param path: 图片文件路径
    :param net_path: 网络文件路径
    :return: 侦测到的物体的位置、IOU、和分类信息
    """
    if img:
        img, expand, scale = resize(img)
    else:
        img, expand, scale = resize(cv2.imread(path))

    # 数据转换, 转换图像数组数据为tensor且数据缩放到-0.5~0.5
    data = torch.tensor(img.transpose([2, 0, 1]) / 255 - 0.5,
                        dtype=torch.float32).unsqueeze(dim=0)
    # 初始化设置
    setting = init_settings()
    # 检查是否有试着网络路径
    if net_path:
        setting['net_path'] = net_path
        print('[{}]指定的网络文件路径已起效'.format(datetime.datetime.now()))
    # 获取侦测类对象
    yolo = Detector(setting['net_path'])

    startTime = time.time()
    # 调用侦测类中的侦测处理函数
    boxes = yolo.detect(
        data, 0.5, setting['anchors'])  # Box <- [batch,confi,cx,cy,w,h,cls]
    # 数据取到cpu(如果本来就在CPU也不会有问题)
    boxes = boxes.cpu()
    stopTime = time.time()
    print('* ------------------------------------------ *')
    print('* PROCESSING TIME COST : {}'.format(stopTime - startTime))

    if boxes.size()[0] == 0:
        print('* NO THINGS CAUGHT')
        return boxes.numpy()

    # 合并重合框
    frame = nms(
        boxes, 0.5,
        True).cpu().detach().numpy()  # box_idx, [N, IOU, CX, CY, W, H, CLS]
    # 反算416*416下的位置到图片的实际位置
    frame[:, 2:6] = return2RealPosition(frame[:, 2:6], expand, scale)
    print('* NUM OF BOXES : {} / {}'.format(frame.shape[0], boxes.size()[0]))
    return frame
Exemplo n.º 4
0
    settings['user_exceptions'].append(current_user.id)

    for group_entity in settings['target_groups']:
        try:
            number_of_users = await process_group(group_entity)
            total_users_scraped += number_of_users
            total_groups_scraped += 1
        except (ChannelPrivateError, UsernameInvalidError,
                UsernameNotOccupiedError, ValueError) as e:
            logger.error(f"{stringify_group_entity(group_entity)}: {e}")
            continue

    time_delta = datetime.now() - start_time
    logger.info('Statistics')
    logger.info(f'Total users scraped: {total_users_scraped}')
    logger.info(f'Total groups scraped: {total_groups_scraped}')
    logger.info(f'Total time: {time_delta}')


if __name__ == '__main__':
    makedirs(data_path, exist_ok=True)
    settings = init_settings(settings_file_path)
    logger.debug(f'Settings loaded: {settings}')

    with TelegramClient('iron_dome',
                        settings['api_id'],
                        settings['api_hash'],
                        flood_sleep_threshold=86400,
                        base_logger='telethon') as client:
        client.loop.run_until_complete(main(settings, client))
Exemplo n.º 5
0
 def __init__(self, settings=None):
     # 初始化设置
     self.settings = init_settings()
     # 有效化控制台输入的新设置
     self.check_new_settings(settings)
Exemplo n.º 6
0
 def __init__(self, settings=None):
     self.settings = init_settings()
     self.check_new_settings(settings)