Ejemplo n.º 1
0
def ci():
    """
    Used in conjunction with travis for Continuous Integration testing
    :return:
    """
    import django
    sys.path.append(os.path.dirname(__file__))
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
    django.setup()
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.views import handle_uploaded_file, handle_youtube_video
    from dvaapp.models import Video
    from dvaapp.tasks import extract_frames, perform_indexing, perform_detection
    for fname in glob.glob('tests/ci/*.mp4'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname,
                               file(fname).read(),
                               content_type="video/mp4")
        handle_uploaded_file(f, name, False)
    for fname in glob.glob('tests/*.zip'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname,
                               file(fname).read(),
                               content_type="application/zip")
        handle_uploaded_file(f, name)
    handle_youtube_video('tomorrow never dies',
                         'https://www.youtube.com/watch?v=gYtz5sw98Bc')
    for v in Video.objects.all():
        extract_frames(v.pk)
        perform_indexing(v.pk)
        # perform_detection(v.pk) detection is not performed in CI since it take long time on CPU
    test_backup()
Ejemplo n.º 2
0
def ci():
    """
    Used in conjunction with travis for Continuous Integration testing
    :return:
    """
    import django
    sys.path.append(os.path.dirname(__file__))
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
    django.setup()
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.views import handle_uploaded_file, handle_youtube_video
    from dvaapp.models import Video
    from dvaapp.tasks import extract_frames, perform_face_indexing, inpcetion_index_by_id, perform_yolo_ssd_detection_by_id
    for fname in glob.glob('tests/ci/*.mp4'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname, file(fname).read(), content_type="video/mp4")
        handle_uploaded_file(f, name, False)
    for fname in glob.glob('tests/*.zip'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname, file(fname).read(), content_type="application/zip")
        handle_uploaded_file(f, name)
    handle_youtube_video('tomorrow never dies', 'https://www.youtube.com/watch?v=gYtz5sw98Bc')
    for i,v in enumerate(Video.objects.all()):
        extract_frames(v.pk)
        inpcetion_index_by_id(v.pk)
        if i ==0: # save travis time by just running detection on first video
            perform_yolo_ssd_detection_by_id(v.pk)
            perform_face_indexing(v.pk)
    test_backup()
Ejemplo n.º 3
0
def test():
    """
    Run tests by launching tasks
    :return:
    """
    import django
    sys.path.append(os.path.dirname(__file__))
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
    django.setup()
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.views import handle_uploaded_file, handle_youtube_video
    for fname in glob.glob('tests/*.mp4'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname,
                               file(fname).read(),
                               content_type="video/mp4")
        handle_uploaded_file(f, name)
    for fname in glob.glob('tests/*.zip'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname,
                               file(fname).read(),
                               content_type="application/zip")
        handle_uploaded_file(f, name)
    handle_youtube_video('tomorrow never dies',
                         'https://www.youtube.com/watch?v=gYtz5sw98Bc')
Ejemplo n.º 4
0
def ci():
    """
    Used in conjunction with travis for Continuous Integration testing
    :return:
    """
    import django
    sys.path.append(os.path.dirname(__file__))
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
    django.setup()
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.views import handle_uploaded_file, handle_youtube_video
    from dvaapp.models import Video, Clusters, IndexEntries
    from django.conf import settings
    from dvaapp.tasks import extract_frames, perform_face_indexing, inception_index_by_id, perform_ssd_detection_by_id,\
        perform_yolo_detection_by_id, inception_index_ssd_detection_by_id, export_video_by_id, import_video_by_id,\
        perform_clustering
    for fname in glob.glob('tests/ci/*.mp4'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname,
                               file(fname).read(),
                               content_type="video/mp4")
        handle_uploaded_file(f, name, False)
    for fname in glob.glob('tests/*.zip'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname,
                               file(fname).read(),
                               content_type="application/zip")
        handle_uploaded_file(f, name)
    handle_youtube_video('tomorrow never dies',
                         'https://www.youtube.com/watch?v=gYtz5sw98Bc')
    for i, v in enumerate(Video.objects.all()):
        extract_frames(v.pk)
        inception_index_by_id(v.pk)
        if i == 0:  # save travis time by just running detection on first video
            perform_ssd_detection_by_id(v.pk)
            perform_yolo_detection_by_id(v.pk)
            perform_face_indexing(v.pk)
            inception_index_ssd_detection_by_id(v.pk)
        fname = export_video_by_id(v.pk)
        f = SimpleUploadedFile(fname,
                               file("{}/exports/{}".format(
                                   settings.MEDIA_ROOT, fname)).read(),
                               content_type="application/zip")
        vimported = handle_uploaded_file(f, fname)
        import_video_by_id(vimported.pk)
    dc = Clusters()
    dc.indexer_algorithm = 'inception'
    dc.included_index_entries_pk = [
        k.pk for k in IndexEntries.objects.all().filter(
            algorithm=dc.indexer_algorithm)
    ]
    dc.components = 32
    dc.save()
    perform_clustering(dc.pk)
    test_backup()
Ejemplo n.º 5
0
def ci():
    """
    Used in conjunction with travis for Continuous Integration testing
    :return:
    """
    import django
    sys.path.append(os.path.dirname(__file__))
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
    django.setup()
    import base64
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.views import handle_uploaded_file, handle_youtube_video, create_query
    from dvaapp.models import Video, Clusters,IndexEntries,TEvent
    from django.conf import settings
    from dvaapp.tasks import extract_frames, perform_face_indexing, inception_index_by_id, perform_ssd_detection_by_id,\
        perform_yolo_detection_by_id, inception_index_ssd_detection_by_id, export_video_by_id, import_video_by_id,\
        inception_query_by_image, perform_clustering, assign_open_images_text_tags_by_id
    for fname in glob.glob('tests/ci/*.mp4'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname, file(fname).read(), content_type="video/mp4")
        handle_uploaded_file(f, name, False)
    for fname in glob.glob('tests/*.zip'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname, file(fname).read(), content_type="application/zip")
        handle_uploaded_file(f, name)
    handle_youtube_video('tomorrow never dies', 'https://www.youtube.com/watch?v=gYtz5sw98Bc')
    for i,v in enumerate(Video.objects.all()):
        extract_frames(TEvent.objects.create(video=v).pk)
        inception_index_by_id(TEvent.objects.create(video=v).pk)
        if i ==0: # save travis time by just running detection on first video
            perform_ssd_detection_by_id(TEvent.objects.create(video=v).pk)
            perform_yolo_detection_by_id(TEvent.objects.create(video=v).pk)
            perform_face_indexing(v.pk)
            inception_index_ssd_detection_by_id(TEvent.objects.create(video=v).pk)
            assign_open_images_text_tags_by_id(TEvent.objects.create(video=v).pk)
        fname = export_video_by_id(TEvent.objects.create(video=v,event_type=TEvent.EXPORT).pk)
        f = SimpleUploadedFile(fname, file("{}/exports/{}".format(settings.MEDIA_ROOT,fname)).read(), content_type="application/zip")
        vimported = handle_uploaded_file(f, fname)
        import_video_by_id(TEvent.objects.create(video=vimported).pk)
    dc = Clusters()
    dc.indexer_algorithm = 'inception'
    dc.included_index_entries_pk = [k.pk for k in IndexEntries.objects.all().filter(algorithm=dc.indexer_algorithm)]
    dc.components = 32
    dc.save()
    clustering_task = TEvent()
    clustering_task.clustering = dc
    clustering_task.event_type = TEvent.CLUSTERING
    clustering_task.operation = 'perform_clustering'
    clustering_task.save()
    perform_clustering(clustering_task.pk)
    query,dv = create_query(10,False,['inception',],[],'data:image/png;base64,'+base64.encodestring(file('tests/query.png').read()))
    inception_query_by_image(query.pk)
    query,dv = create_query(10,True,['inception',],[],'data:image/png;base64,'+base64.encodestring(file('tests/query.png').read()))
    inception_query_by_image(query.pk)
    test_backup()
Ejemplo n.º 6
0
def qt():
    import django
    sys.path.append(os.path.dirname(__file__))
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
    django.setup()
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.views import handle_uploaded_file
    for fname in glob.glob('tests/ci/*.mp4'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname, file(fname).read(), content_type="application/mp4")
        v = handle_uploaded_file(f, name)
    for fname in glob.glob('tests/example*.zip'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname, file(fname).read(), content_type="application/zip")
        v = handle_uploaded_file(f, name)
Ejemplo n.º 7
0
def qt():
    import django
    sys.path.append(os.path.dirname(__file__))
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
    django.setup()
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.views import handle_uploaded_file
    from dvaapp.models import Video, TEvent
    from dvaapp.tasks import extract_frames, perform_face_detection, perform_indexing, segment_video
    for fname in glob.glob('tests/ci/*.mp4'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname,
                               file(fname).read(),
                               content_type="application/mp4")
        v = handle_uploaded_file(f, name)
        arguments_json = json.dumps({'sync': True})
        segment_video(
            TEvent.objects.create(video=v, arguments_json=arguments_json).pk)
        perform_face_detection(TEvent.objects.create(video=v).pk)
        args = json.dumps({
            'index': 'facenet',
            'target': 'regions',
            'filter': {
                'object_name__startswith': 'MTCNN_face'
            }
        })
        perform_indexing(
            TEvent.objects.create(video=v, arguments_json=args).pk)
Ejemplo n.º 8
0
def test():
    """
    Run tests by launching tasks
    :return:
    """
    import django
    sys.path.append(os.path.dirname(__file__))
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
    django.setup()
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.views import handle_uploaded_file, handle_youtube_video
    for fname in glob.glob('tests/*.mp4'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname, file(fname).read(), content_type="video/mp4")
        handle_uploaded_file(f, name)
    for fname in glob.glob('tests/*.zip'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname, file(fname).read(), content_type="application/zip")
        handle_uploaded_file(f, name)
    handle_youtube_video('tomorrow never dies', 'https://www.youtube.com/watch?v=gYtz5sw98Bc')
Ejemplo n.º 9
0
def test(ci=False):
    """
    Run tests
    :param ci: if True (fab test:1) tests are run on Travis this option skips creating tasks and directly calls
    :return:
    """
    import django
    sys.path.append(os.path.dirname(__file__))
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
    django.setup()
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.views import handle_uploaded_file, handle_youtube_video
    from dvaapp.models import Video
    from dvaapp.tasks import extract_frames, perform_indexing, perform_detection
    if ci:
        for fname in glob.glob('tests/ci/*.mp4'):
            name = fname.split('/')[-1].split('.')[0]
            f = SimpleUploadedFile(fname,
                                   file(fname).read(),
                                   content_type="video/mp4")
            handle_uploaded_file(f, name, False)
        for fname in glob.glob('tests/*.zip'):
            name = fname.split('/')[-1].split('.')[0]
            f = SimpleUploadedFile(fname,
                                   file(fname).read(),
                                   content_type="application/zip")
            handle_uploaded_file(f, name)
        handle_youtube_video('jungle book',
                             'https://www.youtube.com/watch?v=C4qgAaxB_pc')
        for v in Video.objects.all():
            extract_frames(v.pk)
            perform_indexing(v.pk)
            perform_detection(v.pk)
        test_backup()
    else:
        for fname in glob.glob('tests/*.mp4'):
            name = fname.split('/')[-1].split('.')[0]
            f = SimpleUploadedFile(fname,
                                   file(fname).read(),
                                   content_type="video/mp4")
            handle_uploaded_file(f, name)
        for fname in glob.glob('tests/*.zip'):
            name = fname.split('/')[-1].split('.')[0]
            f = SimpleUploadedFile(fname,
                                   file(fname).read(),
                                   content_type="application/zip")
            handle_uploaded_file(f, name)
        handle_youtube_video('jungle book',
                             'https://www.youtube.com/watch?v=C4qgAaxB_pc')
Ejemplo n.º 10
0
def qt():
    import django
    sys.path.append(os.path.dirname(__file__))
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
    django.setup()
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.views import handle_uploaded_file
    from dvaapp.models import Video, TEvent
    from dvaapp.tasks import extract_frames,perform_detection,perform_indexing,segment_video
    for fname in glob.glob('tests/ci/*.mp4'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname, file(fname).read(), content_type="application/mp4")
        v = handle_uploaded_file(f, name)
Ejemplo n.º 11
0
def qt():
    import django
    sys.path.append(os.path.dirname(__file__))
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
    django.setup()
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.views import handle_uploaded_file
    from dvaapp.models import Video, TEvent
    from dvaapp.tasks import extract_frames
    for fname in glob.glob('tests/ci/*.mp4'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname, file(fname).read(), content_type="video/mp4")
        v = handle_uploaded_file(f, name, False)
        extract_frames(TEvent.objects.create(video=v).pk)
Ejemplo n.º 12
0
def qt():
    import django
    sys.path.append(os.path.dirname(__file__))
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
    django.setup()
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.views import handle_uploaded_file
    from dvaapp.models import Video, TEvent
    from dvaapp.tasks import extract_frames,perform_face_detection,perform_face_indexing
    for fname in glob.glob('tests/example*.zip'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname, file(fname).read(), content_type="application/zip")
        v = handle_uploaded_file(f, name)
        extract_frames(TEvent.objects.create(video=v).pk)
        perform_face_detection(TEvent.objects.create(video=v).pk)
        perform_face_indexing(TEvent.objects.create(video=v).pk)
Ejemplo n.º 13
0
def process_visual_genome():
    setup_django()
    import os, shutil, gzip, json
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.shared import handle_uploaded_file
    from dvaapp import models
    from dvaapp.models import TEvent
    from dvaapp.tasks import extract_frames, export_video
    from collections import defaultdict
    os.system(
        'aws s3api get-object --request-payer "requester" --bucket visualdatanetwork --key visual_genome_objects.txt.gz  /root/DVA/visual_genome_objects.txt.gz'
    )
    data = defaultdict(list)
    with gzip.open('/root/DVA/visual_genome_objects.txt.gz') as metadata:
        for line in metadata:
            entries = line.strip().split('\t')
            data[entries[1]].append({
                'x': int(entries[2]),
                'y': int(entries[3]),
                'w': int(entries[4]),
                'h': int(entries[5]),
                'object_id': entries[0],
                'object_name': entries[6],
                'text': ' '.join(entries[6:]),
            })
    name = "visual_genome"
    fname = "visual_genome.zip"
    f = SimpleUploadedFile(fname, "", content_type="application/zip")
    v = handle_uploaded_file(f, name)
    outpath = "/root/DVA/dva/media/{}/video/{}.zip".format(v.pk, v.pk)
    os.system('rm  {}'.format(outpath))
    os.system(
        'aws s3api get-object --request-payer "requester" --bucket visualdatanetwork --key visual_genome.zip  {}'
        .format(outpath))
    extract_frames(TEvent.objects.create(video=v).pk)
    video = v
    models.Region.objects.all().filter(video=video).delete()
    buffer = []
    batch_count = 0
    for frame in models.Frame.objects.all().filter(video=video):
        frame_id = str(int(frame.name.split('/')[-1].split('.')[0]))
        for o in data[frame_id]:
            annotation = models.Region()
            annotation.region_type = models.Region.ANNOTATION
            annotation.video = v
            annotation.frame = frame
            annotation.x = o['x']
            annotation.y = o['y']
            annotation.h = o['h']
            annotation.w = o['w']
            annotation.object_name = o['object_name']
            annotation.metadata = o
            annotation.text = o['text']
            buffer.append(annotation)
            if len(buffer) == 1000:
                try:
                    models.Region.objects.bulk_create(buffer)
                    batch_count += 1
                    print "saved {}".format(batch_count)
                except:
                    print "encountered an error doing one by one"
                    for k in buffer:
                        try:
                            k.save()
                        except:
                            print "skipping"
                            print k.object_name
                buffer = []
    try:
        models.Region.objects.bulk_create(buffer)
        print "saved {}".format(batch_count)
    except:
        print "encountered an error doing one by one"
        for k in buffer:
            try:
                k.save()
            except:
                print "skipping"
                print k.object_name
    print "exporting"
    export_video(TEvent.objects.create(video=v).pk)
Ejemplo n.º 14
0
def create_yolo_test_data():
    import json
    import shutil
    import numpy as np
    import os
    from PIL import Image
    setup_django()
    from dvaapp.shared import handle_uploaded_file
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.models import Region, TEvent, Frame, AppliedLabel
    from dvaapp.tasks import extract_frames, export_video_by_id
    try:
        shutil.rmtree('tests/yolo_test')
    except:
        pass
    try:
        os.mkdir('tests/yolo_test')
    except:
        pass
    data = np.load('shared/underwater_data.npz')
    json_test = {}
    json_test['anchors'] = [(0.57273, 0.677385), (1.87446, 2.06253),
                            (3.33843, 5.47434), (7.88282, 3.52778),
                            (9.77052, 9.16828)]
    id_2_boxes = {}
    class_names = {
        0: "red_buoy",
        1: "green_buoy",
        2: "yellow_buoy",
        3: "path_marker",
        4: "start_gate",
        5: "channel"
    }
    for i, image in enumerate(data['images'][:500]):
        path = "tests/yolo_test/{}.jpg".format(i)
        Image.fromarray(image).save(path)
        id_2_boxes[path.split('/')[-1]] = data['boxes'][i].tolist()
    local('zip tests/yolo_test.zip -r tests/yolo_test/* ')
    fname = "tests/yolo_test.zip"
    name = "yolo_test"
    f = SimpleUploadedFile(fname,
                           file(fname).read(),
                           content_type="application/zip")
    dv = handle_uploaded_file(f, name)
    extract_frames(TEvent.objects.create(video=dv).pk)
    for df in Frame.objects.filter(video=dv):
        for box in id_2_boxes[df.name]:
            r = Region()
            r.video = dv
            r.frame = df
            c, top_x, top_y, bottom_x, bottom_y = box
            r.object_name = class_names[c]
            r.region_type = Region.ANNOTATION
            r.x = top_x
            r.y = top_y
            r.w = bottom_x - top_x
            r.h = bottom_y - top_y
            r.save()
            l = AppliedLabel()
            l.frame = df
            l.video = dv
            l.label_name = class_names[c]
            l.region = r
            l.save()
    export_video_by_id(TEvent.objects.create(video=dv).pk)
    try:
        shutil.rmtree('tests/yolo_test')
    except:
        pass
Ejemplo n.º 15
0
def ci():
    """
    Used in conjunction with travis for Continuous Integration testing
    :return:
    """
    import django
    sys.path.append(os.path.dirname(__file__))
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
    django.setup()
    import base64
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.views import handle_uploaded_file, handle_youtube_video, pull_vdn_list\
        ,import_vdn_dataset_url
    from dvaapp.models import Video, Clusters,IndexEntries,TEvent,VDNServer
    from django.conf import settings
    from dvaapp.operations.query_processing import QueryProcessing
    from dvaapp.tasks import extract_frames, inception_index_by_id, perform_ssd_detection_by_id,\
        perform_yolo_detection_by_id, inception_index_regions_by_id, export_video_by_id, import_video_by_id,\
        execute_index_subquery, perform_clustering, assign_open_images_text_tags_by_id, perform_face_detection,\
        perform_face_indexing
    for fname in glob.glob('tests/ci/*.mp4'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname, file(fname).read(), content_type="video/mp4")
        handle_uploaded_file(f, name, False)
    for fname in glob.glob('tests/*.mp4'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname, file(fname).read(), content_type="video/mp4")
        handle_uploaded_file(f, name, False)
    for fname in glob.glob('tests/*.zip'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname, file(fname).read(), content_type="application/zip")
        handle_uploaded_file(f, name)
    # handle_youtube_video('world is not enough', 'https://www.youtube.com/watch?v=P-oNz3Nf50Q') # Temporarily disabled due error in travis
    for i,v in enumerate(Video.objects.all()):
        extract_frames(TEvent.objects.create(video=v).pk)
        inception_index_by_id(TEvent.objects.create(video=v).pk)
        if i ==0: # save travis time by just running detection on first video
            perform_ssd_detection_by_id(TEvent.objects.create(video=v).pk)
            perform_face_detection(TEvent.objects.create(video=v).pk)
            inception_index_regions_by_id(TEvent.objects.create(video=v).pk)
            assign_open_images_text_tags_by_id(TEvent.objects.create(video=v).pk)
        fname = export_video_by_id(TEvent.objects.create(video=v,event_type=TEvent.EXPORT).pk)
        f = SimpleUploadedFile(fname, file("{}/exports/{}".format(settings.MEDIA_ROOT,fname)).read(), content_type="application/zip")
        vimported = handle_uploaded_file(f, fname)
        import_video_by_id(TEvent.objects.create(video=vimported).pk)
    dc = Clusters()
    dc.indexer_algorithm = 'inception'
    dc.included_index_entries_pk = [k.pk for k in IndexEntries.objects.all().filter(algorithm=dc.indexer_algorithm)]
    dc.components = 32
    dc.save()
    clustering_task = TEvent()
    clustering_task.clustering = dc
    clustering_task.event_type = TEvent.CLUSTERING
    clustering_task.operation = 'perform_clustering'
    clustering_task.save()
    perform_clustering(clustering_task.pk)
    query_dict = {
        'image_data_b64':base64.encodestring(file('tests/query.png').read()),
        'indexers':[
            {
                'algorithm':'inception',
                'count':10,
                'approximate':False
            }
        ]
    }
    qp = QueryProcessing()
    qp.create_from_json(query_dict)
    execute_index_subquery(qp.indexer_queries[0].pk)
    query_dict = {
        'image_data_b64':base64.encodestring(file('tests/query.png').read()),
        'indexers':[
            {
                'algorithm':'inception',
                'count':10,
                'approximate':True
            }
        ]
    }
    qp = QueryProcessing()
    qp.create_from_json(query_dict)
    execute_index_subquery(qp.indexer_queries[0].pk)
    server, datasets, detectors = pull_vdn_list(1)
    for k in datasets:
        if k['name'] == 'MSCOCO_Sample_500':
            print 'FOUND MSCOCO SAMPLE'
            import_vdn_dataset_url(VDNServer.objects.get(pk=1),k['url'],None)
    test_backup()
Ejemplo n.º 16
0
def ci():
    """
    Used in conjunction with travis for Continuous Integration testing
    :return:
    """
    import django
    sys.path.append(os.path.dirname(__file__))
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
    django.setup()
    import base64
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.views import handle_uploaded_file, handle_youtube_video, pull_vdn_list\
        ,import_vdn_dataset_url
    from dvaapp.models import Video, Clusters,IndexEntries,TEvent,VDNServer, DVAPQL
    from django.conf import settings
    from dvaapp.operations.processing import DVAPQLProcess
    from dvaapp.tasks import extract_frames, perform_indexing, export_video, import_video_by_id,\
        perform_clustering, perform_analysis, perform_detection,\
        segment_video, crop_regions_by_id
    for fname in glob.glob('tests/ci/*.mp4'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname, file(fname).read(), content_type="video/mp4")
        handle_uploaded_file(f, name, False)
    if sys.platform != 'darwin':
        for fname in glob.glob('tests/*.mp4'):
            name = fname.split('/')[-1].split('.')[0]
            f = SimpleUploadedFile(fname, file(fname).read(), content_type="video/mp4")
            handle_uploaded_file(f, name, False)
        for fname in glob.glob('tests/*.zip'):
            name = fname.split('/')[-1].split('.')[0]
            f = SimpleUploadedFile(fname, file(fname).read(), content_type="application/zip")
            handle_uploaded_file(f, name)
    # handle_youtube_video('world is not enough', 'https://www.youtube.com/watch?v=P-oNz3Nf50Q') # Temporarily disabled due error in travis
    for i,v in enumerate(Video.objects.all()):
        if v.dataset:
            arguments = {'sync':True}
            extract_frames(TEvent.objects.create(video=v,arguments=arguments).pk)
        else:
            arguments = {'sync':True}
            segment_video(TEvent.objects.create(video=v,arguments=arguments).pk)
            arguments = {'index': 'inception'}
            perform_indexing(TEvent.objects.create(video=v,arguments=arguments).pk)
        if i ==0: # save travis time by just running detection on first video
            # face_mtcnn
            arguments = {'detector': 'face'}
            dt = TEvent.objects.create(video=v,arguments=arguments)
            perform_detection(dt.pk)
            arguments = {'filters':{'event_id':dt.pk},}
            crop_regions_by_id(TEvent.objects.create(video=v,arguments=arguments).pk)
            # coco_mobilenet
            arguments = {'detector': 'coco'}
            dt = TEvent.objects.create(video=v, arguments=arguments)
            perform_detection(dt.pk)
            arguments = {'filters':{'event_id':dt.pk},}
            crop_regions_by_id(TEvent.objects.create(video=v,arguments=arguments).pk)
            # inception on crops from detector
            arguments = {'index':'inception','target': 'regions','filters': {'event_id': dt.pk, 'w__gte': 50, 'h__gte': 50}}
            perform_indexing(TEvent.objects.create(video=v,arguments=arguments).pk)
            # assign_open_images_text_tags_by_id(TEvent.objects.create(video=v).pk)
        fname = export_video(TEvent.objects.create(video=v).pk)
        f = SimpleUploadedFile(fname, file("{}/exports/{}".format(settings.MEDIA_ROOT,fname)).read(), content_type="application/zip")
        vimported = handle_uploaded_file(f, fname)
        import_video_by_id(TEvent.objects.create(video=vimported).pk)
    dc = Clusters()
    dc.indexer_algorithm = 'inception'
    dc.included_index_entries_pk = [k.pk for k in IndexEntries.objects.all().filter(algorithm=dc.indexer_algorithm)]
    dc.components = 32
    dc.save()
    clustering_task = TEvent()
    clustering_task.arguments = {'clusters_id':dc.pk}
    clustering_task.operation = 'perform_clustering'
    clustering_task.save()
    perform_clustering(clustering_task.pk)
    query_dict = {
        'process_type': DVAPQL.QUERY,
        'image_data_b64':base64.encodestring(file('tests/query.png').read()),
        'indexer_queries':[
            {
                'algorithm':'inception',
                'count':10,
                'approximate':False
            }
        ]
    }
    qp = DVAPQLProcess()
    qp.create_from_json(query_dict)
    # execute_index_subquery(qp.indexer_queries[0].pk)
    query_dict = {
        'process_type': DVAPQL.QUERY,
        'image_data_b64':base64.encodestring(file('tests/query.png').read()),
        'indexer_queries':[
            {
                'algorithm':'inception',
                'count':10,
                'approximate':True
            }
        ]
    }
    qp = DVAPQLProcess()
    qp.create_from_json(query_dict)
    # execute_index_subquery(qp.indexer_queries[0].pk)
    server, datasets, detectors = pull_vdn_list(1)
    for k in datasets:
        if k['name'] == 'MSCOCO_Sample_500':
            print 'FOUND MSCOCO SAMPLE'
            import_vdn_dataset_url(VDNServer.objects.get(pk=1),k['url'],None)
    test_backup()
Ejemplo n.º 17
0
         command = 'celery -A dva worker -l info -c {} -Q {} -n {}.%h -f logs/{}.log'.format(
             1, Q_DETECTOR, Q_DETECTOR, Q_DETECTOR)
     elif sys.argv[2] == 'retriever':
         command = 'celery -A dva worker -l info -c {} -Q {} -n {}.%h -f logs/{}.log'.format(
             1, Q_RETRIEVER, Q_RETRIEVER, Q_RETRIEVER)
     else:
         raise NotImplementedError
     print command
     os.system(command)
 elif sys.argv[1] == 'test':
     for fname in glob.glob('tests/*.mp4'):
         name = fname.split('/')[-1].split('.')[0]
         f = SimpleUploadedFile(fname,
                                file(fname).read(),
                                content_type="video/mp4")
         handle_uploaded_file(f, name)
     for fname in glob.glob('tests/*.zip'):
         name = fname.split('/')[-1].split('.')[0]
         f = SimpleUploadedFile(fname,
                                file(fname).read(),
                                content_type="application/zip")
         handle_uploaded_file(f, name)
     handle_youtube_video('jungle book',
                          'https://www.youtube.com/watch?v=C4qgAaxB_pc')
 elif sys.argv[1] == 'ci_test':
     for fname in glob.glob('tests/ci/*.mp4'):
         name = fname.split('/')[-1].split('.')[0]
         f = SimpleUploadedFile(fname,
                                file(fname).read(),
                                content_type="video/mp4")
         handle_uploaded_file(f, name, False)
Ejemplo n.º 18
0
def ci():
    """
    Used in conjunction with travis for Continuous Integration testing
    :return:
    """
    import django
    sys.path.append(os.path.dirname(__file__))
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
    django.setup()
    import base64
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.views import handle_uploaded_file, handle_youtube_video, pull_vdn_list\
        ,import_vdn_dataset_url
    from dvaapp.models import Video, Clusters,IndexEntries,TEvent,VDNServer
    from django.conf import settings
    from dvaapp.operations.query_processing import QueryProcessing
    from dvaapp.tasks import extract_frames, perform_indexing, export_video_by_id, import_video_by_id,\
        perform_clustering, perform_analysis, perform_detection,\
        segment_video, crop_regions_by_id
    for fname in glob.glob('tests/ci/*.mp4'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname, file(fname).read(), content_type="video/mp4")
        handle_uploaded_file(f, name, False)
    if sys.platform != 'darwin':
        for fname in glob.glob('tests/*.mp4'):
            name = fname.split('/')[-1].split('.')[0]
            f = SimpleUploadedFile(fname, file(fname).read(), content_type="video/mp4")
            handle_uploaded_file(f, name, False)
        for fname in glob.glob('tests/*.zip'):
            name = fname.split('/')[-1].split('.')[0]
            f = SimpleUploadedFile(fname, file(fname).read(), content_type="application/zip")
            handle_uploaded_file(f, name)
    # handle_youtube_video('world is not enough', 'https://www.youtube.com/watch?v=P-oNz3Nf50Q') # Temporarily disabled due error in travis
    for i,v in enumerate(Video.objects.all()):
        if v.dataset:
            arguments_json = json.dumps({'sync':True})
            extract_frames(TEvent.objects.create(video=v,arguments_json=arguments_json).pk)
        else:
            arguments_json = json.dumps({'sync':True})
            segment_video(TEvent.objects.create(video=v,arguments_json=arguments_json).pk)
            arguments_json = json.dumps({'index': 'inception'})
            perform_indexing(TEvent.objects.create(video=v,arguments_json=arguments_json).pk)
        if i ==0: # save travis time by just running detection on first video
            # face_mtcnn
            arguments_json = json.dumps({'detector': 'face'})
            dt = TEvent.objects.create(video=v,arguments_json=arguments_json)
            perform_detection(dt.pk)
            arguments_json = json.dumps({'filters':{'event_id':dt.pk},})
            crop_regions_by_id(TEvent.objects.create(video=v,arguments_json=arguments_json).pk)
            # coco_mobilenet
            arguments_json = json.dumps({'detector': 'coco'})
            dt = TEvent.objects.create(video=v, arguments_json=arguments_json)
            perform_detection(dt.pk)
            arguments_json = json.dumps({'filters':{'event_id':dt.pk},})
            crop_regions_by_id(TEvent.objects.create(video=v,arguments_json=arguments_json).pk)
            # inception on crops from detector
            arguments_json = json.dumps({'index':'inception','target': 'regions','filters': {'event_id': dt.pk, 'w__gte': 50, 'h__gte': 50}})
            perform_indexing(TEvent.objects.create(video=v,arguments_json=arguments_json).pk)
            # assign_open_images_text_tags_by_id(TEvent.objects.create(video=v).pk)
        fname = export_video_by_id(TEvent.objects.create(video=v,event_type=TEvent.EXPORT).pk)
        f = SimpleUploadedFile(fname, file("{}/exports/{}".format(settings.MEDIA_ROOT,fname)).read(), content_type="application/zip")
        vimported = handle_uploaded_file(f, fname)
        import_video_by_id(TEvent.objects.create(video=vimported).pk)
    dc = Clusters()
    dc.indexer_algorithm = 'inception'
    dc.included_index_entries_pk = [k.pk for k in IndexEntries.objects.all().filter(algorithm=dc.indexer_algorithm)]
    dc.components = 32
    dc.save()
    clustering_task = TEvent()
    clustering_task.clustering = dc
    clustering_task.event_type = TEvent.CLUSTERING
    clustering_task.operation = 'perform_clustering'
    clustering_task.save()
    perform_clustering(clustering_task.pk)
    query_dict = {
        'image_data_b64':base64.encodestring(file('tests/query.png').read()),
        'indexers':[
            {
                'algorithm':'inception',
                'count':10,
                'approximate':False
            }
        ]
    }
    qp = QueryProcessing()
    qp.create_from_json(query_dict)
    # execute_index_subquery(qp.indexer_queries[0].pk)
    query_dict = {
        'image_data_b64':base64.encodestring(file('tests/query.png').read()),
        'indexers':[
            {
                'algorithm':'inception',
                'count':10,
                'approximate':True
            }
        ]
    }
    qp = QueryProcessing()
    qp.create_from_json(query_dict)
    # execute_index_subquery(qp.indexer_queries[0].pk)
    server, datasets, detectors = pull_vdn_list(1)
    for k in datasets:
        if k['name'] == 'MSCOCO_Sample_500':
            print 'FOUND MSCOCO SAMPLE'
            import_vdn_dataset_url(VDNServer.objects.get(pk=1),k['url'],None)
    test_backup()
Ejemplo n.º 19
0
def ci():
    """
    Perform Continuous Integration testing using Travis

    """
    import django
    sys.path.append(os.path.dirname(__file__))
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
    django.setup()
    import base64
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.views import handle_uploaded_file, pull_vdn_list \
        , import_vdn_dataset_url
    from dvaapp.models import Video, IndexEntries, TEvent, VDNServer, DVAPQL, Retriever
    from django.conf import settings
    from dvaapp.operations.processing import DVAPQLProcess
    from dvaapp.tasks import perform_dataset_extraction, perform_indexing, perform_export, perform_import, \
        perform_retriever_creation, perform_detection, \
        perform_video_segmentation, perform_transformation
    for fname in glob.glob('tests/ci/*.mp4'):
        name = fname.split('/')[-1].split('.')[0]
        f = SimpleUploadedFile(fname,
                               file(fname).read(),
                               content_type="video/mp4")
        handle_uploaded_file(f, name, False)
    if sys.platform != 'darwin':
        for fname in glob.glob('tests/*.mp4'):
            name = fname.split('/')[-1].split('.')[0]
            f = SimpleUploadedFile(fname,
                                   file(fname).read(),
                                   content_type="video/mp4")
            handle_uploaded_file(f, name, False)
        for fname in glob.glob('tests/*.zip'):
            name = fname.split('/')[-1].split('.')[0]
            f = SimpleUploadedFile(fname,
                                   file(fname).read(),
                                   content_type="application/zip")
            handle_uploaded_file(f, name)
    for i, v in enumerate(Video.objects.all()):
        if v.dataset:
            arguments = {'sync': True}
            perform_dataset_extraction(
                TEvent.objects.create(video=v, arguments=arguments).pk)
        else:
            arguments = {'sync': True}
            perform_video_segmentation(
                TEvent.objects.create(video=v, arguments=arguments).pk)
        arguments = {'index': 'inception', 'target': 'frames'}
        perform_indexing(
            TEvent.objects.create(video=v, arguments=arguments).pk)
        if i == 0:  # save travis time by just running detection on first video
            # face_mtcnn
            arguments = {'detector': 'face'}
            dt = TEvent.objects.create(video=v, arguments=arguments)
            perform_detection(dt.pk)
            arguments = {
                'filters': {
                    'event_id': dt.pk
                },
            }
            perform_transformation(
                TEvent.objects.create(video=v, arguments=arguments).pk)
            # coco_mobilenet
            arguments = {'detector': 'coco'}
            dt = TEvent.objects.create(video=v, arguments=arguments)
            perform_detection(dt.pk)
            arguments = {
                'filters': {
                    'event_id': dt.pk
                },
            }
            perform_transformation(
                TEvent.objects.create(video=v, arguments=arguments).pk)
            # inception on crops from detector
            arguments = {
                'index': 'inception',
                'target': 'regions',
                'filters': {
                    'event_id': dt.pk,
                    'w__gte': 50,
                    'h__gte': 50
                }
            }
            perform_indexing(
                TEvent.objects.create(video=v, arguments=arguments).pk)
            # assign_open_images_text_tags_by_id(TEvent.objects.create(video=v).pk)
        temp = TEvent.objects.create(video=v,
                                     arguments={'destination': "FILE"})
        perform_export(temp.pk)
        temp.refresh_from_db()
        fname = temp.arguments['file_name']
        f = SimpleUploadedFile(fname,
                               file("{}/exports/{}".format(
                                   settings.MEDIA_ROOT, fname)).read(),
                               content_type="application/zip")
        vimported = handle_uploaded_file(f, fname)
        perform_import(
            TEvent.objects.create(video=vimported,
                                  arguments={
                                      "source": "LOCAL"
                                  }).pk)
    # dc = Retriever()
    # args = {}
    #
    # dc.included_index_entries_pk = [k.pk for k in IndexEntries.objects.all().filter(algorithm=dc.indexer_algorithm)]
    # dc.components = 32
    # dc.save()
    # clustering_task = TEvent()
    # clustering_task.arguments = {'clusters_id': dc.pk}
    # clustering_task.operation = 'perform_clustering'
    # clustering_task.save()
    # perform_clustering(clustering_task.pk)
    # query_dict = {
    #     'process_type': DVAPQL.QUERY,
    #     'image_data_b64': base64.encodestring(file('tests/query.png').read()),
    #     'indexer_queries': [
    #         {
    #             'algorithm': 'inception',
    #             'count': 10,
    #             'approximate': False
    #         }
    #     ]
    # }
    # qp = DVAPQLProcess()
    # qp.create_from_json(query_dict)
    # # execute_index_subquery(qp.indexer_queries[0].pk)
    # query_dict = {
    #     'process_type': DVAPQL.QUERY,
    #     'image_data_b64': base64.encodestring(file('tests/query.png').read()),
    #     'indexer_queries': [
    #         {
    #             'algorithm': 'inception',
    #             'count': 10,
    #             'approximate': True
    #         }
    #     ]
    # }
    # qp = DVAPQLProcess()
    # qp.create_from_json(query_dict)
    # # execute_index_subquery(qp.indexer_queries[0].pk)
    server, datasets, detectors = pull_vdn_list(1)
    for k in datasets:
        if k['name'] == 'MSCOCO_Sample_500':
            print 'FOUND MSCOCO SAMPLE'
            import_vdn_dataset_url(VDNServer.objects.get(pk=1), k['url'], None,
                                   k)
    test_backup()
Ejemplo n.º 20
0
def create_yolo_test_data():
    import json
    import shutil
    import numpy as np
    import os
    from PIL import Image
    setup_django()
    from dvaapp.shared import handle_uploaded_file
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.models import Region,TEvent,Frame, AppliedLabel
    from dvaapp.tasks import extract_frames,export_video_by_id
    try:
        shutil.rmtree('tests/yolo_test')
    except:
        pass
    try:
        os.mkdir('tests/yolo_test')
    except:
        pass
    data = np.load('shared/underwater_data.npz')
    json_test = {}
    json_test['anchors'] = [(0.57273, 0.677385), (1.87446, 2.06253), (3.33843, 5.47434), (7.88282, 3.52778), (9.77052, 9.16828)]
    id_2_boxes = {}
    class_names = {
        0:"red_buoy",
        1:"green_buoy",
        2:"yellow_buoy",
        3:"path_marker",
        4:"start_gate",
        5:"channel"
    }
    for i,image in enumerate(data['images'][:500]):
        path = "tests/yolo_test/{}.jpg".format(i)
        Image.fromarray(image).save(path)
        id_2_boxes[path.split('/')[-1]] = data['boxes'][i].tolist()
    local('zip tests/yolo_test.zip -r tests/yolo_test/* ')
    fname = "tests/yolo_test.zip"
    name = "yolo_test"
    f = SimpleUploadedFile(fname, file(fname).read(), content_type="application/zip")
    dv = handle_uploaded_file(f, name)
    extract_frames(TEvent.objects.create(video=dv).pk)
    for df in Frame.objects.filter(video=dv):
        for box in id_2_boxes[df.name]:
            r = Region()
            r.video = dv
            r.frame = df
            c , top_x, top_y, bottom_x, bottom_y = box
            r.object_name = class_names[c]
            r.region_type = Region.ANNOTATION
            r.x = top_x
            r.y = top_y
            r.w = bottom_x - top_x
            r.h = bottom_y - top_y
            r.save()
            l = AppliedLabel()
            l.frame = df
            l.video = dv
            l.label_name = class_names[c]
            l.region = r
            l.save()
    export_video_by_id(TEvent.objects.create(video=dv).pk)
    try:
        shutil.rmtree('tests/yolo_test')
    except:
        pass
Ejemplo n.º 21
0
def process_visual_genome():
    setup_django()
    import os, shutil, gzip, json
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.shared import handle_uploaded_file
    from dvaapp import models
    from dvaapp.models import TEvent
    from dvaapp.tasks import extract_frames, export_video_by_id
    from collections import defaultdict
    os.system('aws s3api get-object --request-payer "requester" --bucket visualdatanetwork --key visual_genome_objects.txt.gz  /root/DVA/visual_genome_objects.txt.gz')
    data = defaultdict(list)
    with gzip.open('/root/DVA/visual_genome_objects.txt.gz') as metadata:
        for line in metadata:
            entries = line.strip().split('\t')
            data[entries[1]].append({
                'x': int(entries[2]),
                'y': int(entries[3]),
                'w': int(entries[4]),
                'h': int(entries[5]),
                'object_id': entries[0],
                'object_name': entries[6],
                'metadata_text': ' '.join(entries[6:]), })
    name = "visual_genome"
    fname = "visual_genome.zip"
    f = SimpleUploadedFile(fname, "", content_type="application/zip")
    v = handle_uploaded_file(f, name)
    outpath = "/root/DVA/dva/media/{}/video/{}.zip".format(v.pk, v.pk)
    os.system('rm  {}'.format(outpath))
    os.system(
        'aws s3api get-object --request-payer "requester" --bucket visualdatanetwork --key visual_genome.zip  {}'.format(
            outpath))
    extract_frames(TEvent.objects.create(video=v).pk)
    video = v
    models.Region.objects.all().filter(video=video).delete()
    buffer = []
    batch_count = 0
    for frame in models.Frame.objects.all().filter(video=video):
        frame_id = str(int(frame.name.split('/')[-1].split('.')[0]))
        for o in data[frame_id]:
            annotation = models.Region()
            annotation.region_type = models.Region.ANNOTATION
            annotation.video = v
            annotation.frame = frame
            annotation.x = o['x']
            annotation.y = o['y']
            annotation.h = o['h']
            annotation.w = o['w']
            annotation.object_name = o['object_name']
            annotation.metadata_json = json.dumps(o)
            annotation.metadata_text = o['metadata_text']
            buffer.append(annotation)
            if len(buffer) == 1000:
                try:
                    models.Region.objects.bulk_create(buffer)
                    batch_count += 1
                    print "saved {}".format(batch_count)
                except:
                    print "encountered an error doing one by one"
                    for k in buffer:
                        try:
                            k.save()
                        except:
                            print "skipping"
                            print k.object_name
                buffer = []
    try:
        models.Region.objects.bulk_create(buffer)
        print "saved {}".format(batch_count)
    except:
        print "encountered an error doing one by one"
        for k in buffer:
            try:
                k.save()
            except:
                print "skipping"
                print k.object_name
    print "exporting"
    export_video_by_id(TEvent.objects.create(video=v).pk)
Ejemplo n.º 22
0
def generate_vdn(fast=False):
    kill()
    setup_django()
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.views import handle_uploaded_file, handle_youtube_video
    from dvaapp import models
    from dvaapp.models import TEvent
    from dvaapp.tasks import extract_frames, perform_face_detection_indexing_by_id, inception_index_by_id, \
        perform_ssd_detection_by_id, perform_yolo_detection_by_id, inception_index_regions_by_id, \
        export_video_by_id
    dirname = get_coco_dirname()
    local('wget https://www.dropbox.com/s/2dq085iu34y0hdv/coco_input.zip?dl=1 -O coco.zip')
    local('unzip coco.zip')
    with lcd(dirname):
        local("zip coco_input.zip -r *.jpg")
    fname = '{}/coco_input.zip'.format(dirname)
    with open('{}/coco_sample_metadata.json'.format(dirname)) as datafile:
        data = json.load(datafile)
    f = SimpleUploadedFile("coco_input.zip", file(fname).read(), content_type="application/zip")
    v = handle_uploaded_file(f, 'mscoco_sample_500')
    extract_frames(TEvent.objects.create(video=v).pk)
    video = v
    models.Region.objects.all().filter(video=video).delete()
    for frame in models.Frame.objects.all().filter(video=video):
        frame_id = str(int(frame.name.split('_')[-1].split('.')[0]))
        annotation = models.Region()
        annotation.region_type = models.Region.ANNOTATION
        annotation.video = v
        annotation.frame = frame
        annotation.full_frame = True
        annotation.metadata_json = json.dumps(data[frame_id]['image'])
        annotation.object_name = 'metadata'
        annotation.save()
    for frame in models.Frame.objects.all().filter(video=video):
        frame_id = str(int(frame.name.split('_')[-1].split('.')[0]))
        for a in data[frame_id][u'annotations']:
            annotation = models.Region()
            annotation.region_type = models.Region.ANNOTATION
            annotation.video = v
            annotation.frame = frame
            annotation.metadata_json = json.dumps(a)
            annotation.full_frame = False
            annotation.x = a['bbox'][0]
            annotation.y = a['bbox'][1]
            annotation.w = a['bbox'][2]
            annotation.h = a['bbox'][3]
            annotation.object_name = 'coco_instance/{}/{}'.format(a[u'category'][u'supercategory'], a[u'category'][u'name'])
            annotation.save()
        for a in data[frame_id][u'keypoints']:
            annotation = models.Region()
            annotation.region_type = models.Region.ANNOTATION
            annotation.video = v
            annotation.frame = frame
            annotation.metadata_json = json.dumps(a)
            annotation.x = a['bbox'][0]
            annotation.y = a['bbox'][1]
            annotation.w = a['bbox'][2]
            annotation.h = a['bbox'][3]
            annotation.object_name = 'coco_keypoints/{}/{}'.format(a[u'category'][u'supercategory'], a[u'category'][u'name'])
            annotation.save()
        for caption in data[frame_id][u'captions']:
            annotation = models.Region()
            annotation.region_type = models.Region.ANNOTATION
            annotation.video = v
            annotation.frame = frame
            annotation.metadata_text = caption['caption']
            annotation.full_frame = True
            annotation.object_name = 'caption'
            annotation.save()
    if not fast:
        inception_index_by_id(TEvent.objects.create(video=v).pk)
        perform_ssd_detection_by_id(TEvent.objects.create(video=v).pk)
        perform_face_detection_indexing_by_id(TEvent.objects.create(video=v).pk)
        inception_index_regions_by_id(TEvent.objects.create(video=v).pk)
    export_video_by_id(TEvent.objects.create(video=v).pk)
Ejemplo n.º 23
0
def generate_visual_genome(fast=False):
    kill()
    import django
    sys.path.append(os.path.dirname(__file__))
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
    django.setup()
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.views import handle_uploaded_file, handle_youtube_video
    from dvaapp import models
    from dvaapp.models import TEvent
    import gzip
    from dvaapp.tasks import extract_frames, perform_face_detection_indexing_by_id, inception_index_by_id, \
        perform_ssd_detection_by_id, inception_index_regions_by_id, \
        export_video_by_id
    dirname = get_visual_genome_dirname()
    with lcd(dirname):
        if not os.path.isfile("{}/vg.zip".format(dirname)):
            local(
                'wget https://www.dropbox.com/s/7g2c1j5n318eovr/visual_genome_sample.zip?dl=1 -O vg.zip'
            )
            local(
                'wget https://www.dropbox.com/s/589tyg6vn3uxqcc/visual_genome_objects.txt.gz?dl=1 -O visual_genome_objects.txt.gz'
            )
    data = defaultdict(list)
    with gzip.open(
            '{}/visual_genome_objects.txt.gz'.format(dirname)) as metadata:
        for line in metadata:
            entries = line.strip().split('\t')
            data[entries[1]].append({
                'x': int(entries[2]),
                'y': int(entries[3]),
                'w': int(entries[4]),
                'h': int(entries[5]),
                'object_id': entries[0],
                'object_name': entries[6],
                'metadata_text': ' '.join(entries[6:]),
            })
    f = SimpleUploadedFile("vg.zip",
                           file('{}/vg.zip'.format(dirname)).read(),
                           content_type="application/zip")
    v = handle_uploaded_file(f, 'visual genome sample')
    extract_frames(TEvent.objects.create(video=v).pk)
    video = v
    models.Region.objects.all().filter(video=video).delete()
    buffer = []
    for frame in models.Frame.objects.all().filter(video=video):
        frame_id = str(int(frame.name.split('_')[-1].split('.')[0]))
        for o in data[frame_id]:
            annotation = models.Region()
            annotation.region_type = models.Region.ANNOTATION
            annotation.video = v
            annotation.frame = frame
            annotation.full_frame = False
            annotation.x = o['x']
            annotation.y = o['y']
            annotation.h = o['h']
            annotation.w = o['w']
            annotation.object_name = o['object_name']
            annotation.metadata_json = json.dumps(o)
            annotation.metadata_text = o['metadata_text']
            buffer.append(annotation)
            if len(buffer) == 1000:
                models.Region.objects.bulk_create(buffer)
                print "saving"
                buffer = []
    models.Region.objects.bulk_create(buffer)
    print "saving final"
    if not fast:
        inception_index_by_id(TEvent.objects.create(video=v).pk)
        default_args = {'region_type': 'A', 'w__gte': 50, 'h__gte': 50}
        inception_index_regions_by_id(
            TEvent.objects.create(video=v,
                                  arguments_json=json.dumps(default_args)).pk)
    export_video_by_id(TEvent.objects.create(video=v).pk)
Ejemplo n.º 24
0
def generate_vdn(fast=False):
    kill()
    import django
    sys.path.append(os.path.dirname(__file__))
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
    django.setup()
    from django.core.files.uploadedfile import SimpleUploadedFile
    from dvaapp.views import handle_uploaded_file, handle_youtube_video
    from dvaapp import models
    from dvaapp.models import TEvent
    from dvaapp.tasks import extract_frames, perform_face_detection_indexing_by_id, inception_index_by_id, \
        perform_ssd_detection_by_id, perform_yolo_detection_by_id, inception_index_regions_by_id, \
        export_video_by_id
    dirname = get_coco_dirname()
    local(
        'wget https://www.dropbox.com/s/2dq085iu34y0hdv/coco_input.zip?dl=1 -O coco.zip'
    )
    local('unzip coco.zip')
    with lcd(dirname):
        local("zip coco_input.zip -r *.jpg")
    fname = '{}/coco_input.zip'.format(dirname)
    with open('{}/coco_sample_metadata.json'.format(dirname)) as datafile:
        data = json.load(datafile)
    f = SimpleUploadedFile("coco_input.zip",
                           file(fname).read(),
                           content_type="application/zip")
    v = handle_uploaded_file(f, 'mscoco_sample_500')
    extract_frames(TEvent.objects.create(video=v).pk)
    video = v
    models.Region.objects.all().filter(video=video).delete()
    for frame in models.Frame.objects.all().filter(video=video):
        frame_id = str(int(frame.name.split('_')[-1].split('.')[0]))
        annotation = models.Region()
        annotation.region_type = models.Region.ANNOTATION
        annotation.video = v
        annotation.frame = frame
        annotation.full_frame = True
        annotation.metadata_json = json.dumps(data[frame_id]['image'])
        annotation.object_name = 'metadata'
        annotation.save()
    for frame in models.Frame.objects.all().filter(video=video):
        frame_id = str(int(frame.name.split('_')[-1].split('.')[0]))
        for a in data[frame_id][u'annotations']:
            annotation = models.Region()
            annotation.region_type = models.Region.ANNOTATION
            annotation.video = v
            annotation.frame = frame
            annotation.metadata_json = json.dumps(a)
            annotation.full_frame = False
            annotation.x = a['bbox'][0]
            annotation.y = a['bbox'][1]
            annotation.w = a['bbox'][2]
            annotation.h = a['bbox'][3]
            annotation.object_name = 'coco_instance/{}/{}'.format(
                a[u'category'][u'supercategory'], a[u'category'][u'name'])
            annotation.save()
        for a in data[frame_id][u'keypoints']:
            annotation = models.Region()
            annotation.region_type = models.Region.ANNOTATION
            annotation.video = v
            annotation.frame = frame
            annotation.metadata_json = json.dumps(a)
            annotation.x = a['bbox'][0]
            annotation.y = a['bbox'][1]
            annotation.w = a['bbox'][2]
            annotation.h = a['bbox'][3]
            annotation.object_name = 'coco_keypoints/{}/{}'.format(
                a[u'category'][u'supercategory'], a[u'category'][u'name'])
            annotation.save()
        for caption in data[frame_id][u'captions']:
            annotation = models.Region()
            annotation.region_type = models.Region.ANNOTATION
            annotation.video = v
            annotation.frame = frame
            annotation.metadata_text = caption['caption']
            annotation.full_frame = True
            annotation.object_name = 'caption'
            annotation.save()
    if not fast:
        inception_index_by_id(TEvent.objects.create(video=v).pk)
        perform_ssd_detection_by_id(TEvent.objects.create(video=v).pk)
        perform_face_detection_indexing_by_id(
            TEvent.objects.create(video=v).pk)
        inception_index_regions_by_id(TEvent.objects.create(video=v).pk)
    export_video_by_id(TEvent.objects.create(video=v).pk)
Ejemplo n.º 25
0
        annotation['category'] = kp_id_to_category[annotation['category_id']]
        data[annotation['image_id']]['keypoints'].append(annotation)
with open('coco_sample_metadata.json', 'w') as output:
    json.dump(data, output)
os.system("zip coco_input.zip -r {}".format(dirname))
from django.core.files.uploadedfile import SimpleUploadedFile
from dvaapp.views import handle_uploaded_file, handle_youtube_video
from dvaapp.models import Video
from dvaapp import models
from dvaapp.tasks import extract_frames, perform_face_indexing, inception_index_by_id, perform_ssd_detection_by_id, perform_yolo_detection_by_id, inception_index_ssd_detection_by_id

fname = 'coco_input.zip'
f = SimpleUploadedFile(fname,
                       file('coco_input.zip').read(),
                       content_type="application/zip")
v = handle_uploaded_file(f, 'mscoco_sample_500')
extract_frames(v.pk)
data = json.load(file('coco_sample_metadata.json'))
video = v
models.Annotation.objects.all().filter(video=video).delete()
for frame in models.Frame.objects.all().filter(video=video):
    frame_id = str(int(frame.name.split('_')[-1].split('.')[0]))
    annotation = models.Annotation()
    annotation.video = v
    annotation.frame = frame
    annotation.full_frame = True
    annotation.metadata_text = json.dumps(data[frame_id]['image'])
    annotation.label = 'metadata'
    annotation.save()
for frame in models.Frame.objects.all().filter(video=video):
    frame_id = str(int(frame.name.split('_')[-1].split('.')[0]))