예제 #1
0
    def __init__(self,
                 frame_size=(0, 0),
                 crop_size=(0, 0),
                 normalized=True,
                 random_crop=False,
                 random_flip=False,
                 color_space='YCbCr'):

        # frame size
        self.frame_size = _pair(frame_size)
        self.frame_height, self.frame_width = frame_size

        # crop size
        self.crop_size = _pair(crop_size)
        self.crop_height, self.crop_width = crop_size

        # colour space
        if color_space not in ['RGB', 'YCbCr']:
            raise ValueError('Specified Color Space is not supported by NVVL')
        self.color_space = color_space

        # processing dictionary
        self.dict = {
            'input':
            nvvl.ProcessDesc(width=self.crop_width,
                             height=self.crop_height,
                             scale_width=self.frame_width,
                             scale_height=self.frame_height,
                             normalized=normalized,
                             random_crop=random_crop,
                             random_flip=random_flip,
                             color_space=color_space)
        }
예제 #2
0
    def __init__(self,
                 frames,
                 is_cropped,
                 crop_size,
                 root,
                 batchsize=1,
                 device_id=0,
                 shuffle=False,
                 distributed=False,
                 fp16=False):
        self.root = root
        self.batchsize = batchsize
        self.shuffle = shuffle
        self.distributed = distributed
        self.frames = frames
        self.device_id = device_id

        self.is_cropped = is_cropped
        self.crop_size = crop_size

        self.files = glob(os.path.join(self.root, '*.mp4'))[64:66]

        if len(self.files) < 1:
            print(("[Error] No video files in %s" % (self.root)))
            raise LookupError

        if fp16:
            tensor_type = 'half'
        else:
            tensor_type = 'float'

        self.image_shape = nvvl.video_size_from_file(self.files[0])

        height = min(self.image_shape.height, self.crop_size[0])
        width = min(self.image_shape.width, self.crop_size[1])

        processing = {
            "input":
            nvvl.ProcessDesc(type=tensor_type,
                             height=height,
                             width=width,
                             random_crop=self.is_cropped,
                             random_flip=False,
                             normalized=True,
                             color_space="RGB",
                             dimension_order="cfhw")
        }

        dataset = nvvl.VideoDataset(self.files,
                                    sequence_length=self.frames,
                                    device_id=self.device_id,
                                    processing=processing)

        self.loader = nvvl.VideoLoader(dataset,
                                       batch_size=self.batchsize,
                                       shuffle=self.shuffle,
                                       distributed=self.distributed)
예제 #3
0
def get_loaders(traindir, batch_size, time_steps):
    training_videos = [
        '/home/users/daniel/data/shanghaitech/training/nvvl_videos/01_001.mp4'
    ]
    logger.info(f'Found {len(training_videos)} video files in training set.')
    testing_videos = [
        '/home/users/daniel/data/shanghaitech/testing/videos/01_0014.mp4'
    ]
    logger.info(f'Found {len(testing_videos)} video files in test set.')

    index_map = np.arange(16)
    processing = {
        'input':
        nvvl.ProcessDesc(
            #  scale_width=width, scale_height=height,
            normalized=True,
            dimension_order='cfhw',
            index_map=list(index_map))
    }
    frame_mask_dataset = FrameMaskDataset(
        '/home/users/daniel/data/shanghaitech/testing/test_frame_mask',
        index_map=index_map,
        video_paths=testing_videos)

    datasets = novelly.datasets.Split(
        nvvl.VideoDataset(training_videos, time_steps, processing=processing),
        nvvl.VideoDataset(testing_videos,
                          time_steps,
                          processing=processing,
                          get_label=frame_mask_dataset.get_label))
    loaders = novelly.datasets.Split(
        nvvl.VideoLoader(datasets.train,
                         batch_size=batch_size,
                         shuffle=True,
                         buffer_length=3),
        nvvl.VideoLoader(datasets.test, batch_size=batch_size,
                         buffer_length=3))
    return loaders, frame_mask_dataset
예제 #4
0
파일: dataloaders.py 프로젝트: klecki/nvvl
    def __init__(self,
                 frames,
                 is_cropped,
                 crop_size,
                 root,
                 batchsize=1,
                 device_id=0,
                 shuffle=False,
                 distributed=False,
                 fp16=False):

        self.root = root
        self.batchsize = batchsize
        self.shuffle = shuffle
        self.distributed = distributed
        self.frames = frames
        self.device_id = device_id

        self.is_cropped = is_cropped
        self.crop_size = crop_size

        self.files = glob(os.path.join(self.root, '*.mp4'))

        if len(self.files) < 1:
            print(("[Error] No video files in %s" % (self.root)))
            raise LookupError

        if fp16:
            tensor_type = 'half'
        else:
            tensor_type = 'float'

        self.image_shape = nvvl.video_size_from_file(self.files[0])

        height = max(self.image_shape.height, self.crop_size[0])
        width = max(self.image_shape.width, self.crop_size[1])
        # Frames are enforced to be mod64 in each dimension
        # as required by FlowNetSD convolutions
        height = int(math.floor(height / 64.) * 64)
        width = int(math.floor(width / 64.) * 64)

        processing = {
            "input":
            nvvl.ProcessDesc(type=tensor_type,
                             height=height,
                             width=width,
                             random_crop=self.is_cropped,
                             random_flip=False,
                             normalized=False,
                             color_space="RGB",
                             dimension_order="cfhw",
                             index_map=[0, 1, 2])
        }

        dataset = nvvl.VideoDataset(self.files,
                                    sequence_length=self.frames,
                                    device_id=self.device_id,
                                    processing=processing)

        self.loader = nvvl.VideoLoader(dataset,
                                       batch_size=self.batchsize,
                                       shuffle=self.shuffle,
                                       distributed=self.distributed)
예제 #5
0
    def __init__(self,
                 frames,
                 is_cropped,
                 crop_size,
                 root,
                 batchsize=1,
                 device_id=0,
                 shuffle=False,
                 distributed=False,
                 fp16=False,
                 index_map=None,
                 random_flip=False,
                 normalized=False,
                 color_space="RGB",
                 dimension_order="cfhw",
                 get_label=None,
                 sampler=None,
                 stride=None):

        self.root = root
        self.batchsize = batchsize
        self.shuffle = shuffle
        self.distributed = distributed
        self.frames = frames
        self.device_id = device_id

        self.is_cropped = is_cropped
        self.crop_size = crop_size

        self.fp16 = fp16
        self.index_map = index_map

        self.random_flip = random_flip
        self.normalized = normalized
        self.color_space = color_space
        self.dimension_order = dimension_order

        self.get_label = get_label

        self.files = glob(os.path.join(self.root, '*.mp4'))

        if len(self.files) < 1:
            print(("[Error] No video files in %s" % (self.root)))
            raise LookupError

        if self.fp16:
            tensor_type = 'half'
        else:
            tensor_type = 'float'

        self.image_shape = nvvl.video_size_from_file(self.files[0])

        if self.is_cropped:
            self.height = self.crop_size[0]
            self.width = self.crop_size[1]
        else:
            self.height = self.image_shape.height
            self.width = self.image_shape.width

        print("Input size: {} x {}\nOutput size: {} x {}\n".format(
            self.image_shape.height, self.image_shape.width, self.height,
            self.width))

        processing = {
            "input":
            nvvl.ProcessDesc(type=tensor_type,
                             height=self.height,
                             width=self.width,
                             random_crop=self.is_cropped,
                             random_flip=self.random_flip,
                             normalized=self.normalized,
                             color_space=self.color_space,
                             dimension_order=self.dimension_order,
                             index_map=self.index_map),
        }

        dataset = nvvl.VideoDataset(self.files,
                                    sequence_length=self.frames,
                                    device_id=self.device_id,
                                    processing=processing,
                                    get_label=self.get_label)

        if sampler is not None and stride is not None:
            self.sampler = sampler(dataset, stride=stride)
        else:
            self.sampler = None

        self.loader = nvvl.VideoLoader(dataset,
                                       batch_size=self.batchsize,
                                       shuffle=self.shuffle,
                                       distributed=self.distributed,
                                       sampler=self.sampler)