Exemplo n.º 1
0
def check_sequence_rearrange(batch_size,
                             shape,
                             reorders,
                             persample_reorder=True,
                             op_type="cpu",
                             layout=""):
    pipe = Pipeline(batch_size=batch_size, num_threads=4, device_id=0)
    with pipe:
        input = fn.external_source(lambda: get_sequences(batch_size, shape),
                                   layout=layout)
        frames = input.gpu() if op_type == "gpu" else input
        order = fn.external_source(
            lambda: reorders) if persample_reorder else reorders
        rearranged = fn.sequence_rearrange(frames,
                                           new_order=order,
                                           device=op_type)
        pipe.set_outputs(rearranged, input)
    pipe.build()
    result, input = pipe.run()
    if op_type == "gpu":
        result = result.as_cpu()
    input = to_batch(input, batch_size)
    baseline = reorder(input, shape[0], reorders, persample_reorder)
    for i in range(batch_size):
        np.testing.assert_array_equal(result[i], baseline[i])
Exemplo n.º 2
0
 def pipe(max_batch_size, input_data, device):
     pipe = Pipeline(batch_size=max_batch_size, num_threads=4, device_id=0)
     data = fn.external_source(source=input_data, cycle=False, device=device,
                               layout="FHWC")
     processed = fn.sequence_rearrange(data, new_order=[0, 4, 1, 3, 2])
     pipe.set_outputs(processed)
     return pipe
Exemplo n.º 3
0
def test_sequence_rearrange_cpu():
    pipe = Pipeline(batch_size=batch_size, num_threads=4, device_id=None)
    test_data_shape = [5, 10, 20, 3]

    def get_data():
        out = [
            np.random.randint(0, 255, size=test_data_shape, dtype=np.uint8)
            for _ in range(batch_size)
        ]
        return out

    data = fn.external_source(source=get_data, layout="FHWC")
    processed = fn.sequence_rearrange(data, new_order=[0, 4, 1, 3, 2])
    pipe.set_outputs(processed)
    pipe.build()
    for _ in range(3):
        pipe.run()