def nvvl_get(self, record, indices):
        image_shape = nvvl.video_size_from_file(record.path)

        start = time.time()

        destroy = False
        if image_shape.width == 640:
            video_reader = self.video_reader_0
        elif image_shape.width == 480:
            video_reader = self.video_reader_1
        else:
            video_reader = nvvl.VideoReader(0, "warn")
            destroy = True

        tensor_imgs = video_reader.get_samples_old(record.path, indices)
        end = time.time()
        print("read time: {} {}".format(end - start, indices))

        if destroy:
            video_reader.destroy()

        images = list()
        for tensor in tensor_imgs:
            tensor_img = tensor[0].numpy().astype(np.uint8)
            img = Image.fromarray(tensor_img)
            images.append(img)

        process_data = self.transform(images)
        return process_data, record.label
Exemple #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)
Exemple #3
0
    def __init__(self,
                 frames,
                 is_cropped,
                 crop_size,
                 root,
                 batch_size,
                 frame_size=[-1, -1]):
        self.root = root
        self.frames = frames
        self.is_cropped = is_cropped
        self.crop_size = crop_size

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

        assert len(self.files) > 1, "[Error] No video files in %s" % self.root

        image_shape = nvvl.video_size_from_file(self.files[0])
        self.image_shape = [image_shape.height, image_shape.width]
        self.frame_size = frame_size
        print("Video size: ", self.image_shape[0], "x", self.image_shape[1],
              "\n")
        if self.is_cropped:
            self.frame_size = self.crop_size
        else:
            self.frame_size = self.image_shape

        self.dataset = dataset(width=self.image_shape[1],
                               height=self.image_shape[0],
                               frames=self.frames)

        self.gt_step = (self.frames - 1) * 2 + 1

        self.total_frames = 0
        self.frame_counts = []
        self.start_index = []
        self.videos = []
        for i, filename in enumerate(self.files):

            with open(filename, 'rb') as f:
                video = f.read()
                self.videos.append(video)

            cmd = [
                "ffprobe", "-v", "error", "-count_frames", "-select_streams",
                "v:0", "-show_entries", "stream=nb_frames", "-of",
                "default=nokey=1:noprint_wrappers=1", filename
            ]
            count = int(subprocess.check_output(cmd))
            count -= self.gt_step
            if count < 0:
                print("[Warning] Video does not have enough frames\n\t%s" % f)
                count = 0
            self.total_frames += count
            self.frame_counts.append(count)
            self.start_index.append(self.total_frames)

        assert self.total_frames >= 1, "[Error] Not enough frames at \n\t%s" % self.root

        self.frame_buffer = np.zeros(
            (3, self.frames, self.frame_size[0], self.frame_size[1]),
            dtype=np.float32)
Exemple #4
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'))

        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)
Exemple #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)