def runFullPutMany(src_list, cleanUp=False): if cleanUp: if os.path.exists('./videos_full'): shutil.rmtree('./videos_full') manager = FullStorageManager(None, CropSplitter(), 'videos_full') now = timer() targets = [os.path.basename(src) for src in src_list] logs = manager.put_many(src_list, targets, log=True, args={ 'encoding': XVID, 'size': -1, 'sample': 1.0, 'offset': 0, 'limit': -1, 'batch_size': 50, 'num_processes': os.cpu_count() }) put_time = timer() - now logrecord('full', ({ 'file': src_list }), 'put', str({'elapsed': put_time}), 's') for i, log in enumerate(logs): logrecord('fullMany', i, 'put', str({'elapsed': log}), 's')
def runFullSequential(src, cleanUp=False): if cleanUp: if os.path.exists('./videos_full'): shutil.rmtree('./videos_full') manager = FullStorageManager(None, CropSplitter(), 'videos_full') now = timer() manager.put(src, os.path.basename(src), parallel=False, args={ 'encoding': XVID, 'size': -1, 'sample': 1.0, 'offset': 0, 'limit': -1, 'batch_size': 50, 'num_processes': os.cpu_count() }) put_time = timer() - now logrecord('full', ({'file': src}), 'put', str({'elapsed': put_time}), 's') clips = manager.get(os.path.basename(src), Condition()) pipelines = [] for c in clips: pipelines.append(c[KeyPoints()]) result = counts(pipelines, ['one'], stats=True) logrecord('full', ({'file': src}), 'get', str(result), 's')
def runFullPutMany(src_list, batch_size=30, cleanUp=False): if cleanUp: if os.path.exists('./videos_full'): shutil.rmtree('./videos_full') manager = FullStorageManager(None, CropSplitter(), 'videos_full') now = timer() targets = [os.path.basename(src) for src in src_list] logs = manager.put_many(src_list, targets, log=True, args={ 'encoding': XVID, 'size': -1, 'sample': 1.0, 'offset': 0, 'limit': -1, 'batch_size': batch_size, 'num_processes': os.cpu_count() }) put_time = timer() - now logrecord('full', ({ 'file': src_list }), 'put', str({'elapsed': put_time}), 's') for i, log in enumerate(logs): logrecord('fullMany', i, 'put', str({'elapsed': log}), 's') # Don't call get() for now for src in src_list: clips = manager.get(os.path.basename(src), Condition()) pipelines = [] for c in clips: pipelines.append(c[KeyPoints()]) result = counts(pipelines, ['one'], stats=True) logrecord('full', ({'file': src}), 'get', str(result), 's')
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')
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)
def runFull(src, cleanUp = False): if cleanUp: if os.path.exists('./videos_full'): shutil.rmtree('./videos_full') manager = FullStorageManager(None, CropSplitter(), 'videos_full') now = timer() manager.put(src, os.path.basename(src), parallel = True, args={'encoding': XVID, 'size': -1, 'sample': 1.0, 'offset': 0, 'limit': -1, 'batch_size': 30, 'num_processes': os.cpu_count()}) put_time = timer() - now logrecord('full', ({'file': src}), 'put', str({'elapsed': put_time}), 's')
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')
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 = SplitterOptimizer() 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')
def test_put(src, cleanUp = False): if cleanUp: if os.path.exists('./videos'): shutil.rmtree('./videos') manager = FullStorageManager(None, CropSplitter(), 'videos') start = time.time() manager.put(src, os.path.basename(src), parallel = True, args={'encoding': XVID, 'size': -1, 'sample': 1.0, 'offset': 0, 'limit': -1, 'batch_size': 50, 'num_processes': 6}) print("Put time:", time.time() - start) clips = manager.get(os.path.basename(src), Condition(label='person')) pipelines = [] for c in clips: pipelines.append(c[KeyPoints()]) result = counts(pipelines, ['one'], stats=True) logrecord('full', ({'file': src}), 'get', str(result), 's')
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
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 simple:", 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 = [] d = SplitterOptimizer() 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) logrecord('fullopt', ({ 'size': tot, 'sel': sel, 'file': src }), 'get', str(result), 's')
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 = SplitterOptimizer() 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'])
def runFull(src, cleanUp=True, limit=-1, background_scale=1, optimizer=False): if cleanUp: if os.path.exists('/tmp/videos'): shutil.rmtree('/tmp/videos') manager = FullStorageManager( CustomTagger(FixedCameraBGFGSegmenter().segment, batch_size=30), CropSplitter(), '/tmp/videos') start = time.time() output = manager.put(src, 'test', parallel=False, args={ 'encoding': XVID, 'size': -1, 'sample': 1.0, 'offset': 0, 'limit': limit, 'batch_size': 30, 'background_scale': background_scale }) end = time.time() clips = manager.get('test', Condition(label='foreground')) region = Box(200, 550, 350, 750) pipelines = [] d = SplitterOptimizer() 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, 'optimizer': optimizer, 'file': src, 'background_scale': background_scale, 'folder_size': get_size('/tmp/videos') }), 'get', str(result), 's', 'put', str(end - start), 's')
def runFullOpt(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 = [] d = SplitterOptimizer() for c in clips: pipeline = c[KeyPoints(blur=3)][ActivityMetric('one', region)][Filter( 'one', [-0.5, 1, -0.5], 0.25, delay=40)] pipeline = d.optimize(pipeline) pipelines.append(pipeline) result = counts(pipelines, ['one'], stats=True) logrecord('fullopt', ({ 'size': tot, 'sel': sel, 'file': src }), 'get', str(result), 's')
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')
from splitter.tracking.contour import * from splitter.dataflow.map import * from splitter.full_manager.full_manager import * from splitter.full_manager.video_processing_keypoint import * from splitter.object_detection.detect import * from splitter.dataflow.agg import * from splitter.tracking.contour import * from splitter.tracking.event import * #from splitter.extern.ffmpeg import * #from splitter manager = FullStorageManager( CustomTagger(FixedCameraBGFGSegmenter().segment, batch_size=30), CropSplitter(), 'videos') #manager = FullStorageManager(SizeMovementTagger(), CropSplitter(), 'videos') #manager = FullStorageManager(TensorFlowObjectDetect(model_file='ssd_mobilenet_v1_coco_2017_11_17', label_file='mscoco_label_map.pbtxt', # num_classes=90, confidence=0.25), CropSplitter(), 'videos') manager.put('./cut3.mp4', 'test2') #res = manager.get('test', Condition(label='small')) #print([video for video in res[0]][0]['data'].shape) #print(len(res)) #play(res[0]) #manager = FullStorageManager(CustomTagger(FixedCameraBGFGSegmenter().segment, batch_size=300), CropSplitter(), 'videos') #manager.put('tcam.mp4', 'test', args={'encoding': XVID, 'size': -1, 'sample': 1.0, 'offset': 0, 'limit': 1000, 'batch_size': 100, 'num_processes': 4, 'background_scale': 1}) #clips = manager.get('test', Condition(label='foreground')) """ for i in range(25,60,3): new_file = set_bitrate('tcam.mp4',str(i)+'tcam.avi', i)