Пример #1
0
def run_annotator():
    parser = argparse.ArgumentParser(description='')
    parser.add_argument('--source-files',
                        dest='source_files',
                        type=str,
                        nargs='+',
                        help='')
    args = parser.parse_args()
    anno = Annotator()
    anno.annotate(args.source_files)
Пример #2
0
def start_loop(stream_name=None,
               network='s3fd',
               redis_host='localhost',
               redis_port=6379):
    """
    Starts the processing loop
    """
    killer = GracefulKiller()

    LOG.info('Initializing Redis cache...')
    cache = redis.StrictRedis(host=redis_host, port=redis_port, db=0)

    LOG.info('Initializing annotator...')
    annotator = Annotator(network=network)

    LOG.info('Starting processing loop...')
    while True:
        # Get next available frame from the cache
        image_bytes = cache.get('{}_raw'.format(stream_name))
        if image_bytes is None:
            continue

        # Annotate with bounding boxes
        # TODO: Get size from feed configs
        image = Image.frombytes('RGB', (1920, 1080), image_bytes)
        image = annotator.annotate(image)

        # Save frame to cache as raw bytes
        cache.set('{}_annotated'.format(stream_name), image.tobytes())

        # Capture kill signals and terminate loop
        if killer.kill_now:
            LOG.info('Shutting down gracefully...')
            break
Пример #3
0
    def generate_annotator(self, event):
        annotation = Annotator(self.channel_fnames, self.probability_table,
                               self.output_dir)
        new_table = annotation.annotate([self.x0, self.y0], [self.x1, self.y1])

        # add the new table to the groundtruth table
        self.groundtruth_table.loc[
            new_table.index,
            self.column_names] = new_table.loc[:, self.column_names]
Пример #4
0
class Caption(Resource):
    """REST end point for the captioning service.
    
    Accepts images (via HTTP POST requests) and returns corresponding captions.
    """
    def __init__(self):
        self.annotator = Annotator()

    def post(self):
        """Create caption for an image.
        
        The POST request should include either an image or a url pointing to an image.

        Parameters
        ----------
        image
            Image data send with the request.
        url
            URL of the image to be processed.
        """
        parser = reqparse.RequestParser()
        parser.add_argument("image",
                            type=datastructures.FileStorage,
                            location='files')
        parser.add_argument("url")
        args = parser.parse_args()
        if args.image:
            image = Image.open(args.image)
        else:
            ssl._create_default_https_context = ssl._create_unverified_context
            with urllib.request.urlopen(args.url) as url:
                f = io.BytesIO(url.read())

            image = Image.open(f)

        annotation = self.annotator.annotate(image)
        data = {
            "annotation": annotation,
        }
        return data, 201
Пример #5
0
def test(nlp,
         src,
         gen,
         bert=False,
         print_annotations=False,
         print_latex=False,
         verbose=False):
    if print_annotations:
        print("source:", src_line[:50])
        print("summary:", gen_line[:50])
    src = nlp(src)
    gen = nlp(gen)
    if verbose:
        print("clusters:", src._.coref_clusters, gen._.coref_clusters)
    ce = CompoundEquivalency()
    spe = SpeakerPronounEquivalency()
    spe.register(src)
    spe.register(gen)
    kg = KnowledgeGraph(nlp,
                        use_bert=bert,
                        equivalencies=[ce, spe],
                        verbose=verbose)
    if print_annotations:
        annotator = Annotator(src, gen, latex=print_latex)
    kg.add_document(src)
    contained = 0
    contained_bert = 0
    missing = 0
    missing_verb = 0
    missing_actors = 0
    missing_acteds = 0
    contradiction = 0
    contradiction_bert = 0
    invalid_simplification = 0
    total = 0
    for token in gen:
        if token.pos_ == "VERB":
            total += 1
            relation = kg.get_relation(token)
            r = kg.query_relation(relation)
            if r[0] == KnowledgeGraph.entailment:
                if print_annotations:
                    print(util.format("contained", "blue", latex=print_latex),
                          "|", relation, "|", r[1])
                contained += 1
            if r[0] == KnowledgeGraph.entailment_bert:
                if print_annotations:
                    print(
                        util.format("contained (BERT)",
                                    "blue",
                                    latex=print_latex), "|", relation, "|",
                        r[1])
                contained_bert += 1
            if r[0] == KnowledgeGraph.contradiction_bert:
                if print_annotations:
                    print(
                        util.format("contradiction (BERT)",
                                    "red",
                                    latex=print_latex), "|", relation, "|",
                        r[1])
                contradiction_bert += 1
            elif r[0] == KnowledgeGraph.missing_dependencies:
                missing += 1
                if print_annotations:
                    print(
                        util.format("generic missing dependency",
                                    "yellow",
                                    latex=print_latex), "|", relation, "|",
                        r[1])
            elif r[0] == KnowledgeGraph.missing_actors:
                missing_actors += 1
                if print_annotations:
                    print(
                        util.format("missing actors",
                                    "magenta",
                                    latex=print_latex), "|", relation, "|",
                        r[1])
            elif r[0] == KnowledgeGraph.missing_acteds:
                missing_acteds += 1
                if print_annotations:
                    print(
                        util.format("missing acteds",
                                    "magenta",
                                    latex=print_latex), "|", relation, "|",
                        r[1])
            elif r[0] == KnowledgeGraph.missing_verb:
                missing_verb += 1
                if print_annotations:
                    print(
                        util.format("missing verb",
                                    "magenta",
                                    latex=print_latex), "|", relation, "|",
                        r[1])
            elif r[0] == KnowledgeGraph.invalid_simplification:
                invalid_simplification += 1
                if print_annotations:
                    print(
                        util.format("invalid simplification",
                                    "magenta",
                                    latex=print_latex), "|", relation, "|",
                        r[1])
            elif r[0] == KnowledgeGraph.contradiction:
                contradiction += 1
                if print_annotations:
                    print(
                        util.format("contradiction", "red", latex=print_latex),
                        "|", relation, "|", r[1])
            if print_annotations:
                annotator.annotate(relation, r)
    if print_annotations:
        annotated_document, annotated_summary = annotator.annotated()
        print("Document:", " ".join(annotated_document))
        print("Summary:", " ".join(annotated_summary))
    if total == 0:
        return 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
    return 100.0 * contained / total, \
            100.0 * contained_bert / total, \
            100.0 * missing / total, \
            100.0 * missing_verb / total, \
            100.0 * missing_actors / total, \
            100.0 * missing_acteds / total, \
            100.0 * contradiction / total, \
            100.0 * contradiction_bert / total, \
            100.0 * invalid_simplification / total
#Testing of the Annotator script

from annotator import Annotator

#Example region that has all features
annotator = Annotator()
region = dict()
region['chromosome'] = 'chr1'
region['chromosome2'] = 'chr1'
region['start'] = '3541566'
region['end'] = '3541586'

annotator.annotate(region)

Пример #7
0
"""	
	Input: tab-delimited file with variants (or simply, regions). Required format: columns chr 1, s1, e1, chr2, s2, e2, somatic (yes/no) per region on the rows. 
	Output: null
	Functionality: starting point of the annotation pipeline. Sorts the input file and starts the annotation process.
	
	TODO:
		- Update input data format
"""

### Imports ###
import sys
import numpy as np
from inputDataParser import InputDataParser
from annotator import Annotator

### Code ###

#1. Initialize
annotator = Annotator()

#2. Read input data
inFile = sys.argv[1]
inputDataParser = InputDataParser()
inputData = inputDataParser.parseInputData(inFile)

#3. Prepare input data, including sorting for speed
preparedInputData = inputDataParser.prepareInputData(inputData)

#4. Do the annotation
annotator.annotate(preparedInputData)