def test_files_source(sc): # Write test files path_template = '/tmp/files_source_test_{:d}' num_elements = 4 paths = [] for i in range(num_elements): path = path_template.format(i) with open(path, 'wb') as f: # Write data f.write(struct.pack('=Q', i)) paths.append(path) data = sc.io.Input([FilesStream(paths=paths)]) pass_data = sc.ops.Pass(input=data) output = NamedStream(sc, 'test_files_source') output_op = sc.io.Output(pass_data, [output]) sc.run(output_op, PerfParams.estimate(), cache_mode=CacheMode.Overwrite, show_progress=False) num_rows = 0 for buf in output.load(): (val, ) = struct.unpack('=Q', buf) assert val == num_rows num_rows += 1 assert num_elements == num_rows
def run_op(sc, op): input = NamedVideoStream(sc, 'test1') frame = sc.io.Input([input]) gather_frame = sc.streams.Gather(frame, [[0]]) faces = op(frame=gather_frame) output = NamedStream(sc, 'output') output_op = sc.io.Output(faces, [output]) sc.run(output_op, PerfParams.estimate(pipeline_instances_per_node=1), cache_mode=CacheMode.Overwrite, show_progress=False) return list(output.load())
def run(self, sc, device): input = NamedVideoStream(sc, 'test1') frame = sc.io.Input([input]) hist = sc.ops.Histogram(frame=frame, device=device) output = NamedStream(sc, 'test_hist') output_op = sc.io.Output(hist, [output]) sc.run(output_op, PerfParams.estimate(), cache_mode=CacheMode.Overwrite, show_progress=False) next(output.load())
def test_shot_detection(sc): input = NamedVideoStream(sc, 'test1') frame = sc.io.Input([input]) range_frame = sc.streams.Range(frame, [{'start': 0, 'end': 1000}]) hist = sc.ops.Histogram(frame=range_frame) boundaries = sc.ops.ShotBoundaries(histograms=hist) output = NamedStream(sc, 'output') output_op = sc.io.Output(boundaries, [output]) sc.run(output_op, PerfParams.manual(work_packet_size=1000, io_packet_size=1000, pipeline_instances_per_node=1), cache_mode=CacheMode.Overwrite, show_progress=False) assert len(next(output.load(rows=[0]))) == 7
def test_captions(sc): caption_path = download_transcript() captions = sc.io.Input( [CaptionStream(caption_path, window_size=10.0, max_time=3600)]) ignored = sc.ops.DecodeCap(cap=captions) output = sc.io.Output(ignored, [NamedStream(sc, 'caption_test')]) sc.run(output, PerfParams.estimate(pipeline_instances_per_node=1), cache_mode=CacheMode.Overwrite)
def run(self, sc, device): input = NamedVideoStream(sc, 'test1') frame = sc.io.Input([input]) flow = sc.ops.OpticalFlow(frame=frame, stencil=[-1, 0], device=device) flow_range = sc.streams.Range(flow, ranges=[{'start': 0, 'end': 50}]) output = NamedStream(sc, 'test_flow') output_op = sc.io.Output(flow_range, [output]) sc.run(output_op, PerfParams.estimate(), cache_mode=CacheMode.Overwrite, show_progress=False) assert output.len() == 50 flow_array = next(output.load()) assert flow_array.dtype == np.float32 assert flow_array.shape[0] == 480 assert flow_array.shape[1] == 640 assert flow_array.shape[2] == 2
def test_python_source(sc): # Write test files py_data = [{'{:d}'.format(i): i} for i in range(4)] data = sc.io.Input([PythonStream(py_data)]) pass_data = sc.ops.Pass(input=data) output = NamedStream(sc, 'test_python_source') output_op = sc.io.Output(pass_data, [output]) sc.run(output_op, PerfParams.estimate(), cache_mode=CacheMode.Overwrite, show_progress=False) num_rows = 0 for i, buf in enumerate(output.load()): d = pickle.loads(buf) assert d['{:d}'.format(i)] == i num_rows += 1 assert num_rows == 4
def run(sc, op, name): vid = NamedVideoStream(sc, 'test1') inp = sc.io.Input([vid]) #f = sc.streams.Gather(inp, [list(range(1000))]) tf = op(frame=inp, batch=100, device=DeviceType.CPU) out = NamedStream(sc, 'qq') outp = sc.io.Output(tf, [out]) s = now() sc.run(outp, PerfParams.estimate(), cache_mode=CacheMode.Overwrite, pipeline_instances_per_node=1) sc.table('qq').profiler().write_trace('{}.trace'.format(name)) print('{:.1f}s'.format(now() - s))
def run(sc, op, name, device): vid = NamedVideoStream(sc, 'test3') inp = sc.io.Input([vid]) f = sc.streams.Gather(inp, [list(range(10000))]) res = sc.ops.Resize(frame=inp, width=[224], height=[224], device=device, batch=100) tf = op(frame=res, batch=100, device=device) out = NamedStream(sc, 'qq') outp = sc.io.Output(tf, [out]) s = now() sc.run(outp, PerfParams.manual(500, 10000, pipeline_instances_per_node=1), cache_mode=CacheMode.Overwrite, gpu_pool='8G') sc.table('qq').profiler().write_trace('{}.tar.gz'.format(name)) print('{:.1f}s'.format(now() - s))
def test_audio(sc): (vid_path, _) = download_videos() audio = sc.io.Input([AudioStream(vid_path, 1.0)]) ignored = sc.ops.DiscardFrame(ignore=audio) output = sc.io.Output(ignored, [NamedStream(sc, 'audio_test')]) sc.run(output, PerfParams.estimate(), cache_mode=CacheMode.Overwrite)