示例#1
0
def test_kinetics():
    kinetics = Kinetics('/data/public/rw/datasets/videos/kinetics')
    assert kinetics.size() == 391782
    assert kinetics.names[:5] == [
        '---0dWlqevI', '---QUuC4vJs', '---aQ-tA5_A', '---j12rm3WI',
        '--0NTAs-fA0'
    ]
    assert kinetics.names[-5:] == [
        'zzyHRXPQP2I', 'zzyxMjfYpL0', 'zzz0-zDYts8', 'zzzZycxdZHk',
        'zzz_3yWpTXo'
    ]
def dataflow(name='davis', scale=1, split='val'):
    if name == 'davis':
        ds = Davis('/data/zubin/videos/davis', name=split, num_frames=1, shuffle=False)
    elif name == 'kinetics':
        ds = Kinetics('/data/public/rw/datasets/videos/kinetics', num_frames=1, skips=[0], shuffle=False)
    else:
        raise Exception('not support dataset %s' % name)

    if name != 'davis':
        ds = df.MapData(ds, lambda dp: [dp[0], dp[1], dp[1]])

    ds = df.MapData(ds, lambda dp: [
        dp[0], # index
        dp[1], # original
        dp[2], # mask
        dp[3], # name
    ])
    feature_size = int(256 * scale)
    size = (feature_size, feature_size)

    ds = df.MapDataComponent(ds, ImageProcess.resize(small_axis=feature_size), index=1)
    ds = df.MapDataComponent(ds, lambda images: cv2.resize(images[0], size), index=2)

    ds = df.MapData(ds, lambda dp: [
        dp[0], # index
        dp[1][0], # original small axis 256 x scale
        cv2.cvtColor(cv2.resize(dp[1][0], size), cv2.COLOR_BGR2GRAY).reshape((size[0], size[1], 1)), # gray (256xscale)x(256xscale)x1
        dp[2], # annotated mask 256xscale x 256xscale
        dp[3], # name
    ])
    ds = df.MultiProcessPrefetchData(ds, nr_prefetch=32, nr_proc=1)
    return ds
示例#3
0
def test_kinetics_tensorpack_dataflow():
    ds = Kinetics('/data/public/rw/datasets/videos/kinetics',
                  num_frames=4,
                  skips=[0, 4, 4, 8])

    ds = df.MapDataComponent(
        ds,
        lambda images: [cv2.resize(image, (256, 256)) for image in images],
        index=1)
    ds = df.MapDataComponent(ds,
                             lambda images: np.stack(images, axis=0),
                             index=1)
    ds = df.BatchData(ds, 6)

    ds.reset_state()
    generator = ds.get_data()
    for _ in range(10):
        _, images = next(generator)
        assert images.shape == (6, 4, 256, 256, 3)
示例#4
0
def test_kinetics_generator_with_num_frames_skips():
    kinetics = Kinetics('/data/public/rw/datasets/videos/kinetics')
    generator = kinetics.get_data(num_frames=4, skips=[0, 4, 4, 8])
    idx, images = next(generator)
    assert idx == 0
    assert len(images) == 4
    assert [image.shape for image in images] == [(720, 406, 3)] * 4

    for _ in range(299 // (1 + 5 + 5 + 9) - 1):
        next(generator)

    idx, images = next(generator)
    assert idx == 14
    assert len(images) == 4
    assert [image.shape for image in images] == [(720, 406, 3)] * 4

    idx, images = next(generator)
    assert idx == 0
    assert len(images) == 4
    assert [image.shape for image in images] == [(240, 320, 3)] * 4
示例#5
0
def test_kinetics_generator():
    kinetics = Kinetics('/data/public/rw/datasets/videos/kinetics')
    generator = kinetics.get_data()
    idx, images = next(generator)
    assert idx == 0
    assert len(images) == 1
    assert images[0].shape == (720, 406, 3)

    for _ in range(299 - 1):
        next(generator)

    idx, images = next(generator)
    assert idx == 299
    assert len(images) == 1
    assert images[0].shape == (720, 406, 3)

    idx, images = next(generator)
    assert idx == 0
    assert len(images) == 1
    assert images[0].shape == (240, 320, 3)
示例#6
0
def test_kinetics_get():
    kinetics = Kinetics('/data/public/rw/datasets/videos/kinetics')
    assert kinetics.get_filename(kinetics.names[0]) == (
        True,
        '/data/public/rw/datasets/videos/kinetics/processed/---0dWlqevI.mp4')
    assert kinetics.get_filename(kinetics.names[-1]) == (
        False,
        '/data/public/rw/datasets/videos/kinetics/processed/zzz_3yWpTXo.mp4')
    with pytest.raises(KeyError) as exception_info:
        kinetics.get_filename('NOT_EXISTS_NAME')
    assert exception_info.value.args[0] == 'not exists name at NOT_EXISTS_NAME'
def dataflow(name='davis', scale=1):
    if name == 'davis':
        ds = Davis('/data/public/rw/datasets/videos/davis/trainval',
                   num_frames=1,
                   shuffle=False)
    elif name == 'kinetics':
        ds = Kinetics('/data/public/rw/datasets/videos/kinetics',
                      num_frames=1,
                      skips=[0],
                      shuffle=False)
    else:
        raise Exception('not support dataset %s' % name)

    if name != 'davis':
        ds = df.MapData(ds, lambda dp: [dp[0], dp[1], dp[1]])

    ds = df.MapData(
        ds,
        lambda dp: [
            dp[0],  # index
            dp[1],  # original
            dp[2],  # mask
        ])
    size = (256 * scale, 256 * scale)

    ds = df.MapDataComponent(ds,
                             ImageProcess.resize(small_axis=256 * scale),
                             index=1)
    ds = df.MapDataComponent(ds,
                             lambda images: cv2.resize(images[0], size),
                             index=2)

    ds = df.MapData(
        ds,
        lambda dp: [
            dp[0],  # index
            dp[1][0],  # original
            cv2.cvtColor(cv2.resize(dp[1][0], size), cv2.COLOR_BGR2GRAY).
            reshape((size[0], size[1], 1)),  # gray
            dp[2],  # mask
        ])
    ds = df.MultiProcessPrefetchData(ds, nr_prefetch=32, nr_proc=1)
    return ds
示例#8
0
    parser.add_argument('--name', type=str, default='kinetics')

    parser.add_argument('--log-filename', type=str, default='')
    parser.add_argument('--debug', action='store_true')
    args = parser.parse_args()

    log_format = '[%(asctime)s %(levelname)s] %(message)s'
    level = logging.DEBUG if args.debug else logging.INFO
    if not args.log_filename:
        logging.basicConfig(level=level, format=log_format, stream=sys.stderr)
    else:
        logging.basicConfig(level=level, format=log_format, filename=args.log_filename)
    logging.info('args: %s', args)

    if args.name == 'kinetics':
        ds = Kinetics('/data/public/rw/datasets/videos/kinetics', num_frames=1, skips=[0], shuffle=True)
        ds = df.MapData(ds, lambda dp: [dp[1][0], dp[0]])
    else:
        ds = df.dataset.Cifar10('train', shuffle=True)

    ds = df.MapDataComponent(ds, lambda image: cv2.resize(image, (32, 32)))
    ds = df.MapDataComponent(ds, lambda image: cv2.cvtColor(np.float32(image / 255.0), cv2.COLOR_RGB2Lab))
    ds = df.MapDataComponent(ds, lambda image: image[:, :, 1:])
    ds = df.MapDataComponent(ds, lambda image: image.reshape((-1, 2)))
    ds = df.RepeatedData(ds, -1)
    ds.reset_state()

    generator = ds.get_data()
    logging.info('initalized preprocessor')

    samples = []