Ejemplo n.º 1
0
def main():
    charts_cfg = cfg.clone()
    tables_cfg = cfg.clone()
    charts_cfg.merge_from_file(charts_path)
    tables_cfg.merge_from_file(tables_path)
    model_charts = ChataDemo(charts_cfg, "charts")
    model_tables = ChataDemo(tables_cfg, "tables")
    
    client = ApiClient()
    client.login()
    newest_ids = client.get_new_publications()
    for pub_id in newest_ids:
        pages = client.get_pages(pub_id)
        print(pub_id)
        for id, url in pages:
            print(id)
            print(url)
            resp = urllib.request.urlopen(url)
            image = np.asarray(bytearray(resp.read()), dtype="uint8")
            image = cv2.imdecode(image, cv2.IMREAD_COLOR)
            predictions_charts = model_charts.get_predictions(image)
            predictions_tables = model_tables.get_predictions(image)
            annotations_charts = annotate(predictions_charts)
            annotations_tables = annotate(predictions_tables)
            annotations = annotations_charts+annotations_tables
            print(annotations)
            if annotations:
                client.add_annotation(id, annotations)
Ejemplo n.º 2
0
def main():
    if len(sys.argv) < 3:
        print(
            'Usage: Path to model config path to model last_checkpoint model type'
        )
    output_dir = sys.argv[2]
    model_type = sys.argv[3]
    cfg.merge_from_file(sys.argv[1])
    cfg.merge_from_list(["OUTPUT_DIR", output_dir])
    model = ChataDemo(cfg, model_type)

    client = ApiClient()
    client.login()
    #latest_id = client.get_latest()
    newest_ids = client.get_new_publications()
    for pub_id in newest_ids:
        pages = client.get_pages(pub_id)
        print(pub_id)
        for id, url in pages:
            print(id)
            print(url)
            resp = urllib.request.urlopen(url)
            image = np.asarray(bytearray(resp.read()), dtype="uint8")
            image = cv2.imdecode(image, cv2.IMREAD_COLOR)
            predictions = model.get_predictions(image)
            annotations = annotate(predictions)
            print(annotations)
            if annotations:
                print('writing annotation...')
                for annotation in annotations:
                    client.add_annotation(id, annotation)