Exemple #1
0
def test_perf_params(cl):
    frame = cl.io.Input([NamedVideoStream(cl, 'test1')])
    hist = cl.ops.Histogram(frame=frame)
    ghist = cl.streams.Gather(hist, [[0]])
    output_op = cl.io.Output(ghist, [NamedStream(cl, '_ignore')])

    cl.run(output_op,
           PerfParams.manual(10, 10),
           show_progress=False,
           cache_mode=CacheMode.Overwrite)

    cl.run(output_op,
           PerfParams.estimate(),
           show_progress=False,
           cache_mode=CacheMode.Overwrite)
def test_files_sink(sc):
    # Write initial test files
    path_template = '/tmp/files_source_test_{:d}'
    num_elements = 4
    input_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))
        input_paths.append(path)

    # Write output test files
    path_template = '/tmp/files_sink_test_{:d}'
    num_elements = 4
    output_paths = []
    for i in range(num_elements):
        path = path_template.format(i)
        output_paths.append(path)
    data = sc.io.Input([FilesStream(paths=input_paths)])
    pass_data = sc.ops.Pass(input=data)
    output = FilesStream(paths=output_paths)
    output_op = sc.io.Output(pass_data, [output])
    sc.run(output_op,
           PerfParams.estimate(),
           cache_mode=CacheMode.Overwrite,
           show_progress=False)

    # Read output test files
    for i, s in enumerate(output.load()):
        d, = struct.unpack('=Q', s)
        assert d == i
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 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)
Exemple #5
0
 def run_spacer_job(spacer, spacing):
     frame = cl.io.Input([NamedVideoStream(cl, 'test1')])
     hist = cl.ops.Histogram(frame=frame)
     space_hist = spacer(input=hist, spacings=[spacing])
     output = NamedStream(cl, 'test_space')
     output_op = cl.io.Output(space_hist, [output])
     cl.run(output_op,
            PerfParams.estimate(),
            cache_mode=CacheMode.Overwrite,
            show_progress=False)
     return output
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())
Exemple #7
0
def test_stream_args(cl):
    frame = cl.io.Input([NamedVideoStream(cl, 'test1')])
    resized_frame = cl.ops.Resize(frame=frame, width=[640], height=[480])
    range_frame = cl.streams.Range(resized_frame, [(0, 10)])
    output_stream = NamedVideoStream(cl, 'test_stream_args')
    output_op = cl.io.Output(range_frame, [output_stream])
    cl.run(output_op,
           PerfParams.estimate(),
           cache_mode=CacheMode.Overwrite,
           show_progress=False)

    list(output_stream.load())
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))
Exemple #9
0
    def run_sampler_job(sampler, sampler_args, expected_rows):
        frame = cl.io.Input([NamedVideoStream(cl, 'test1')])
        sample_frame = sampler(input=frame, **sampler_args)
        output = NamedVideoStream(cl, 'test_sample')
        output_op = cl.io.Output(sample_frame, [output])
        cl.run(output_op,
               PerfParams.estimate(),
               cache_mode=CacheMode.Overwrite,
               show_progress=False)

        num_rows = len(list(output.load()))
        assert num_rows == expected_rows
Exemple #10
0
def test_py_variadic(cl):
    input = NamedVideoStream(cl, 'test1')
    frame = cl.io.Input([input])
    range_frame = cl.streams.Range(frame, ranges=[{'start': 0, 'end': 30}])
    out_frame = cl.ops.TestPyVariadic(range_frame, range_frame, range_frame)
    output = NamedVideoStream(cl, 'test_variadic')
    output_op = cl.io.Output(out_frame.lossless(), [output])
    cl.run(output_op,
           PerfParams.estimate(),
           cache_mode=CacheMode.Overwrite,
           show_progress=False)
    next(output.load())
Exemple #11
0
    def run_job(args_1, args_2):
        frame = cl.io.Input([NamedVideoStream(cl, 'test1')])
        sample_frame_1 = cl.streams.Range(input=frame, ranges=[args_1])
        sample_frame_2 = cl.streams.Range(input=frame, ranges=[args_2])
        output_op_1 = cl.io.Output(sample_frame_1,
                                   [NamedVideoStream(cl, 'test_mp_1')])
        output_op_2 = cl.io.Output(sample_frame_2,
                                   [NamedVideoStream(cl, 'test_mp_2')])

        cl.run([output_op_1, output_op_2],
               PerfParams.estimate(),
               cache_mode=CacheMode.Overwrite,
               show_progress=False)
Exemple #12
0
def test_auto_ingest(cl):
    (vid1_path, vid2_path) = download_videos()
    input = NamedVideoStream(cl, 'test3', path=vid1_path)
    frame = cl.io.Input([input])
    hist = cl.ops.Histogram(frame=frame)
    output = NamedStream(cl, 'test_hist')
    output_op = cl.io.Output(hist, [output])
    cl.run(output_op,
           PerfParams.estimate(),
           cache_mode=CacheMode.Overwrite,
           show_progress=False)

    run(['rm', '-rf', vid1_path, vid2_path])
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_blur(sc):
    input = NamedVideoStream(sc, 'test1')
    frame = sc.io.Input([input])
    range_frame = sc.streams.Range(frame, ranges=[{'start': 0, 'end': 30}])
    blurred_frame = sc.ops.Blur(frame=range_frame, kernel_size=3, sigma=0.1)
    output = NamedVideoStream(sc, 'test_blur')
    output_op = sc.io.Output(blurred_frame, [output])
    sc.run(output_op,
           PerfParams.estimate(),
           cache_mode=CacheMode.Overwrite,
           show_progress=False)

    frame_array = next(output.load())
    assert frame_array.dtype == np.uint8
    assert frame_array.shape[0] == 480
    assert frame_array.shape[1] == 640
    assert frame_array.shape[2] == 3
Exemple #15
0
def test_profiler(cl):
    frame = cl.io.Input([NamedVideoStream(cl, 'test1')])
    hist = cl.ops.Histogram(frame=frame)
    ghist = cl.streams.Gather(hist, [[0]])
    output_op = cl.io.Output(ghist, [NamedStream(cl, '_ignore')])

    time_start = time.time()
    job_id = cl.run(output_op,
                    PerfParams.estimate(),
                    show_progress=False,
                    cache_mode=CacheMode.Overwrite)
    print('Time', time.time() - time_start)
    profile = cl.get_profile(job_id)
    f = tempfile.NamedTemporaryFile(delete=False, suffix='.trace')
    f.close()
    profile.write_trace(f.name)
    profile.statistics()
    run(['rm', '-f', f.name])
    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