コード例 #1
0
ファイル: test_tagger.py プロジェクト: sjyk/deeplens-cv
def test_tagger():
    # logging.basicConfig(level=logging.DEBUG)
    urllib.request.urlretrieve(
        "https://www.dropbox.com/s/6adl0d91l5lokbu/cut4.mp4?dl=1",
        "/tmp/test.mp4")

    if os.path.exists('/tmp/videos'):
        shutil.rmtree('/tmp/videos')
    manager = FullStorageManager(
        CustomTagger(FixedCameraBGFGSegmenter().segment, batch_size=20),
        CropSplitter(),
        '/tmp/videos',
        '/tmp/videos',
        dsn='dbname=postgres user=postgres password=postgres host=127.0.0.1')
    start = time.time()
    output = manager.put('/tmp/test.mp4',
                         'test',
                         parallel=False,
                         args={
                             'encoding': XVID,
                             'size': -1,
                             'sample': 1.0,
                             'offset': 0,
                             'limit': 1000,
                             'batch_size': 20,
                             'num_processes': 8,
                             'background_scale': 1
                         })
    end = time.time()
    print("Without background resizing:", end - start)
    res = manager.get('test', Condition(label='foreground'))
    shape1 = next(next(res))['data'].shape
    assert shape1[2] == 3

    manager = FullStorageManager(
        CustomTagger(FixedCameraBGFGSegmenter().segment, batch_size=20),
        CropSplitter(),
        '/tmp/videos',
        '/tmp/videos',
        dsn='dbname=postgres user=postgres password=postgres host=127.0.0.1')
    start = time.time()
    output = manager.put('/tmp/test.mp4',
                         'test',
                         parallel=False,
                         args={
                             'encoding': XVID,
                             'size': -1,
                             'sample': 1.0,
                             'offset': 0,
                             'limit': 1000,
                             'batch_size': 20,
                             'num_processes': 8,
                             'background_scale': 0.2
                         })
    end = time.time()
    print("With background resizing:", end - start)
    res = manager.get('test', Condition(label='foreground'))
    shape2 = next(next(res))['data'].shape
    assert shape2[2] == 3
コード例 #2
0
def runFull(src, cache=False, cleanUp=True, limit=6000, optimizer=True):
    if cleanUp:
        if os.path.exists('/tmp/videos'):
            shutil.rmtree('/tmp/videos')

    manager = FullStorageManager(CustomTagger(FixedCameraBGFGSegmenter().segment, batch_size=30), CropSplitter(),
                                 '/tmp/videos')
    manager.put(src, 'test',
                args={'encoding': XVID, 'size': -1, 'sample': 1.0, 'offset': 0, 'limit': limit, 'batch_size': 30,
                      'num_processes': 4, 'background_scale': 1}, hwang=False)
    if cache:
        manager.cache('test', Condition(label='foreground'), hwang=False)

    clips = manager.get('test', Condition(label='foreground'))

    region = Box(200, 550, 350, 750)

    pipelines = []
    d = DeepLensOptimizer()
    for c in clips:
        pipeline = c[KeyPoints()][ActivityMetric('one', region)][
            Filter('one', [-0.25, -0.25, 1, -0.25, -0.25], 1.5, delay=10)]
        if optimizer:
            pipeline = d.optimize(pipeline)
        pipelines.append(pipeline)

    result = counts(pipelines, ['one'], stats=True)
    logrecord('full', ({'size': limit, 'cache': cache, 'optimizer': optimizer, 'file': src,
                         'folder_size': get_size('/tmp/videos')}), 'get', str(result), 's')
    if cache:
        manager.uncache('test', Condition(label='foreground'))
コード例 #3
0
ファイル: test_tcam.py プロジェクト: sjyk/deeplens-cv
def runFull(src, tot=-1, sel=0.1):
    cleanUp()

    manager = FullStorageManager(
        CustomTagger(FixedCameraBGFGSegmenter().segment, batch_size=100),
        CropSplitter(), 'videos')
    now = timer()
    manager.put(src,
                'test',
                args={
                    'encoding': XVID,
                    'size': -1,
                    'sample': 1.0,
                    'offset': 0,
                    'limit': tot,
                    'batch_size': 100,
                    'num_processes': 12
                })
    put_time = timer() - now
    print("Put time for simple:", put_time)

    region = Box(515, 200, 700, 600)
    sel = sel / 2

    clips = manager.get('test', Condition(label='foreground'))
    pipelines = []

    for c in clips:
        pipelines.append(c[KeyPoints()][ActivityMetric('one', region)][Filter(
            'one', [-0.25, -0.25, 1, -0.25, -0.25], 1.5, delay=10)])

    result = counts(pipelines, ['one'], stats=True)

    logrecord('full', ({'file': src}), 'get', str(result), 's')
コード例 #4
0
ファイル: submit.py プロジェクト: sjyk/deeplens-cv
def put(video, name, segmentation_args):
    manager = FullStorageManager(\
       CustomTagger(\
        FixedCameraBGFGSegmenter(**segmentation_args).segment, \
        batch_size=STORAGE_ARGS['batch_size']), \
           CropSplitter(), FOLDER)

    manager.put(video, name, args=STORAGE_ARGS, hwang=False)
コード例 #5
0
def fullQuality(index=0):

    if os.path.exists('videos'):
        shutil.rmtree('videos')

    manager = FullStorageManager(
        CustomTagger(FixedCameraBGFGSegmenter(blur=11,
                                              movement_threshold=11).segment,
                     batch_size=200), CropSplitter(), 'videos')

    now = datetime.datetime.now()

    filename = FOLDER + 'crash{0}.mp4'.format(index)

    manager.put(filename,
                'test',
                args={
                    'encoding': XVID,
                    'size': -1,
                    'sample': 1.0,
                    'offset': 0,
                    'limit': -1,
                    'batch_size': 200,
                    'num_processes': 4,
                    'background_scale': 1
                },
                hwang=False)

    #no queries to the background, lowest quality for speed to be within 5%
    manager.set_quality('test',
                        Condition(label='background'),
                        qscale=52,
                        rscale=0.1)
    manager.set_quality('test',
                        Condition(label='foreground'),
                        qscale=44,
                        rscale=1)

    put_result = (datetime.datetime.now() - now).total_seconds()

    logrecord('fullq', ({
        'folder_size': get_size('videos')
    }), 'put', str(put_result), 's')

    now = datetime.datetime.now()

    clips = manager.get('test', Condition(label='foreground'))
    for c in clips:
        pipeline_get(c[MotionVectors()][Speed()])

    result = (datetime.datetime.now() - now).total_seconds()

    logrecord('fullq', ({
        'folder_size': get_size('videos')
    }), 'get', str(result), 's')
コード例 #6
0
def runFullOpt(src, tot=1000, sel=0.1):
    cleanUp()

    manager = FullStorageManager(
        CustomTagger(FixedCameraBGFGSegmenter().segment, batch_size=20),
        CropSplitter(), 'videos')
    now = timer()
    manager.put(src,
                'test',
                args={
                    'encoding': XVID,
                    'size': -1,
                    'sample': 1.0,
                    'offset': 0,
                    'limit': tot,
                    'batch_size': 20,
                    'num_processes': 4,
                    'background_scale': 1
                })
    put_time = timer() - now
    print("Put time for full opt:", put_time)

    left = Box(1600, 1600, 1700, 1800)
    middle = Box(1825, 1600, 1975, 1800)
    right = Box(2050, 1600, 2175, 1800)
    sel = sel / 2

    clips = manager.get('test',
                        Condition(label='foreground', custom_filter=None))

    pipelines = []
    d = DeepLensOptimizer()
    for c in clips:
        pipeline = c[GoodKeyPoints()][ActivityMetric(
            'left', left)][ActivityMetric('middle', middle)][ActivityMetric(
                'right',
                right)][Filter('left', [1, 1, 1], 3,
                               delay=25)][Filter('middle', [1, 1, 1],
                                                 3,
                                                 delay=25)][Filter('right',
                                                                   [1, 1, 1],
                                                                   3,
                                                                   delay=25)]
        pipeline = d.optimize(pipeline)
        pipelines.append(pipeline)

    result = counts(pipelines, ['left', 'middle', 'right'], stats=True)

    logrecord('fullopt', ({
        'size': tot,
        'sel': sel,
        'file': src
    }), 'get', str(result), 's')
コード例 #7
0
def get(name, condition):
	manager = FullStorageManager(\
				CustomTagger(\
					FixedCameraBGFGSegmenter().segment, \
					batch_size=STORAGE_ARGS['batch_size']), \
				    CropSplitter(), FOLDER)

	clips = manager.get(name, condition)
	srcs = []
	for c in clips:
		if isinstance(c, IteratorVideoStream):
			srcs.extend(c.sources)
		else:
			srcs.append(c.src)

	return srcs
コード例 #8
0
def runFull(src, tot=1000, sel=0.1):
    cleanUp()

    manager = FullStorageManager(
        CustomTagger(FixedCameraBGFGSegmenter().segment, batch_size=100),
        CropSplitter(),
        'videos',
        './videos',
        dsn='dbname=header user=postgres password=secret host=127.0.0.1')
    now = timer()
    manager.put(src,
                'test',
                args={
                    'encoding': XVID,
                    'size': -1,
                    'sample': 1.0,
                    'offset': 0,
                    'limit': tot,
                    'batch_size': 100,
                    'num_processes': 4,
                    'background_scale': 1
                })
    put_time = timer() - now
    print("Put time for full:", put_time)

    region = Box(200, 550, 350, 750)
    sel = sel / 2

    clips = manager.get(
        'test',
        Condition(label='foreground',
                  custom_filter=time_filter(tot // 2 - int(tot * sel),
                                            tot // 2 + int(tot * sel))))
    pipelines = []

    for c in clips:
        pipelines.append(c[KeyPoints()][ActivityMetric('one', region)][Filter(
            'one', [-0.25, -0.25, 1, -0.25, -0.25], 1.5, delay=10)])

    result = counts(pipelines, ['one'], stats=True)

    logrecord('full', ({
        'size': tot,
        'sel': sel,
        'file': src
    }), 'get', str(result), 's')
コード例 #9
0
ファイル: test_cache_policy.py プロジェクト: sjyk/deeplens-cv
def doexperiments_ks(budget=1000000000):

    for i in range(0, 300, 50):
        cleanUp()

        manager = FullStorageManager(
            CustomTagger(FixedCameraBGFGSegmenter().segment, batch_size=100),
            CropSplitter(), 'videos')
        manager.put('tcam.mp4',
                    'test',
                    args={
                        'encoding': XVID,
                        'size': -1,
                        'sample': 1.0,
                        'offset': 0,
                        'limit': 2000,
                        'batch_size': 100,
                        'num_processes': 4,
                        'background_scale': 1
                    })
        clips = manager.get('test', Condition(label='foreground'))

        region = spatial_selectivity(buffer=i)

        d = DeepLensOptimizer()
        pipelines = []
        for c in clips:
            pipeline = c[KeyPoints()][ActivityMetric('one', region)][Filter(
                'one', [-0.25, -0.25, 1, -0.25, -0.25], 1.5, delay=10)]
            pipeline = d.optimize(pipeline)
            pipelines.append(pipeline)

        result, time1 = counts(pipelines, ['one'], stats=True)
        d.cacheKnapsack(manager, budget)

        clips = manager.get('test', Condition(label='foreground'))
        pipelines = []
        for c in clips:
            pipeline = c[KeyPoints()][ActivityMetric('one', region)][Filter(
                'one', [-0.25, -0.25, 1, -0.25, -0.25], 1.5, delay=10)]
            pipeline = d.optimize(pipeline)
            pipelines.append(pipeline)

        result, time2 = counts(pipelines, ['one'], stats=True)

        print(i, budget, time1['elapsed'], time2['elapsed'])
コード例 #10
0
ファイル: exp3_sim.py プロジェクト: sjyk/deeplens-cv
def runFull(src, tot=1000, sel=0.1):
	cleanUp()

	manager = FullStorageManager(CustomTagger(FixedCameraBGFGSegmenter(movement_threshold=21,blur=7,movement_prob=0.10).segment, batch_size=100), CropSplitter(), 'videos')
	manager.put(src, 'test', args={'encoding': XVID, 'size': -1, 'sample': 1.0, 'offset': 0, 'limit': tot, 'batch_size': 100})

	region = Box(500, 350, 750, 450)
	sel = sel/2

	clips = manager.get('test', Condition(label='foreground', custom_filter=time_filter(tot//2-int(tot*sel),tot//2+int(tot*sel))))
	pipelines = []

	for c in clips:
		pipelines.append(c[KeyPoints(blur=3)][ActivityMetric('one', region)][Filter('one', [-0.5,1,-0.5], 0.25, delay=40)])

	result = counts(pipelines, ['one'], stats=True)

	logrecord('full',({'size': tot, 'sel': sel, 'file': src}), 'get', str(result), 's')
コード例 #11
0
def runFullOpt(src, tot=1000, sel=0.1):
	cleanUp()

	manager = FullStorageManager(CustomTagger(FixedCameraBGFGSegmenter().segment, batch_size=100), CropSplitter(), 'videos')
	manager.put(src, 'test', args={'encoding': XVID, 'size': -1, 'sample': 1.0, 'offset': 0, 'limit': tot, 'batch_size': 100})

	region = Box(200, 550, 350, 750)
	sel = sel/2
	
	clips = manager.get('test', Condition(label='foreground',custom_filter=time_filter(tot//2-int(tot*sel),tot//2+int(tot*sel))))

	pipelines = []
	d = DeepLensOptimizer()
	for c in clips:
		pipeline = c[KeyPoints()][ActivityMetric('one', region)][Filter('one', [-0.25,-0.25,1,-0.25,-0.25],1.5, delay=10)]
		pipeline = d.optimize(pipeline)
		pipelines.append(pipeline)

	result = counts(pipelines, ['one'], stats=True)[1]['elapsed']

	logrecord('fullopt',({'size': tot, 'sel': sel, 'file': src}), 'get', str(result), 's')
コード例 #12
0
from deeplens.full_manager.full_video_processing import CropSplitter
from deeplens.struct import *
from deeplens.tracking.background import FixedCameraBGFGSegmenter
from deeplens.utils import *
from deeplens.dataflow.map import *
from deeplens.full_manager.full_manager import *
from deeplens.utils.testing_utils import *
import os
import shutil

if os.path.exists('./videos'):
    shutil.rmtree('./videos')
manager = FullStorageManager(
    CustomTagger(FixedCameraBGFGSegmenter().segment, batch_size=5),
    CropSplitter(), 'videos')
manager.put(0,
            'test',
            args={
                'encoding': XVID,
                'size': -1,
                'sample': 1.0,
                'offset': 0,
                'limit': 100,
                'batch_size': 5
            })
コード例 #13
0
def runFull(src, tot=1000, batch_size=20):
    # cleanUp()

    folder = '/bulk/videos'
    manager = FullStorageManager(
        CustomTagger(FixedCameraBGFGSegmenter().segment,
                     batch_size=batch_size), CropSplitter(), folder)
    # now = timer()
    # manager.put(src, 'test',
    #             args={'encoding': 'X264', 'size': -1, 'sample': 1.0, 'offset': 0, 'limit': tot, 'batch_size': batch_size,
    #                   'num_processes': 4, 'background_scale': 1})
    # put_time = timer() - now
    # print("Put time for full:", put_time)
    print("Batch size:", batch_size, "Folder size:", get_size(folder))

    left = Box(1600, 1600, 1700, 1800)
    middle = Box(1825, 1600, 1975, 1800)
    right = Box(2050, 1600, 2175, 1800)

    # left = Box(1600 / 3, 1600 / 3, 1700 / 3, 1800 / 3)
    # middle = Box(1825 / 3, 1600 / 3, 1975 / 3, 1800 / 3)
    # right = Box(2050 / 3, 1600 / 3, 2175 / 3, 1800 / 3)

    # left = Box(1600 / 2, 1600 / 2, 1700 / 2, 1800 / 2)
    # middle = Box(1825 / 2, 1600 / 2, 1975 / 2, 1800 / 2)
    # right = Box(2050 / 2, 1600 / 2, 2175 / 2, 1800 / 2)

    clips = manager.get('test',
                        Condition(label='foreground', custom_filter=None),
                        large=True)
    pipelines = []

    total_counts = {}
    total_frames = 0
    total_time = 0

    for c in tqdm(clips):
        this_result = count(c[GoodKeyPoints()][ActivityMetric(
            'left', left)][ActivityMetric('middle', middle)][ActivityMetric(
                'right',
                right)][Filter('left', [1], 1,
                               delay=25)][Filter('middle', [1], 1,
                                                 delay=25)][Filter('right',
                                                                   [1],
                                                                   1,
                                                                   delay=25)],
                            ['left', 'middle', 'right'],
                            stats=True)
        print(this_result)
        total_counts = {
            k: total_counts.get(k, 0) + this_result[0].get(k, 0)
            for k in set(total_counts) | set(this_result[0])
        }
        total_frames += this_result[1]['frames']
        total_time += this_result[1]['elapsed']

    result = total_counts, {'frames': total_frames, 'elapsed': total_time}

    logrecord('full', ({
        'size': tot,
        'batch_size': batch_size,
        'file': src,
        'folder_size': get_size(folder)
    }), 'get', str(result), 's')