Example #1
0
    def _populate_patches_and_labels(self, xkeys, xys, mode='train'):

        np.random.seed(self.seed)

        # estimate the size and create h5py dataset
        total_frames = self._get_total_frames(xys)

        patches_cache, labels_cache = self._create_patch_and_label_dataset(
            total_frames)

        assert 'dis_y' in xkeys
        assert 'dis_u' in xkeys
        assert 'dis_v' in xkeys

        yss = xys['dis_y']  # yss: Y * frames * videos
        uss = xys['dis_u']
        vss = xys['dis_v']
        if mode == 'train':
            assert 'label' in xys
            labels = xys['label']
        elif mode == 'test':
            labels = [None for _ in range(len(yss))]
        else:
            assert False

        assert len(yss) == len(uss) == len(vss) == len(labels)

        patch_idx = 0
        for ys, us, vs, label in zip(yss, uss, vss, labels):  # iterate videos
            assert len(ys) == len(us) == len(vs)
            for y, u, v in zip(ys, us, vs):  # iterate frames

                yuvimg = dstack_y_u_v(y, u, v)

                img = create_hp_yuv_4channel(yuvimg)

                h, w, c = img.shape

                adj_h = h - self.patch_height
                adj_w = w - self.patch_width

                iv, jv = np.meshgrid(np.arange(adj_h),
                                     np.arange(adj_w),
                                     sparse=False,
                                     indexing='ij')
                iv = iv.reshape(-1)
                jv = jv.reshape(-1)

                idx = np.random.permutation(adj_h * adj_w)

                iv = iv[idx]
                jv = jv[idx]

                patches_found = 0
                for (y, x) in zip(iv, jv):
                    patches_cache[patch_idx] = img[y:y + self.patch_height,
                                                   x:x + self.patch_width]
                    if mode == 'train':
                        labels_cache[patch_idx] = label

                    patches_found += 1
                    patch_idx += 1
                    if patches_found >= self.patches_per_frame:
                        break

        return patches_cache, labels_cache
Example #2
0
    def _populate_patches_and_labels(self, xkeys, xys, mode='train'):

        np.random.seed(self.seed)

        # estimate the size and create h5py dataset
        total_frames = self._get_total_frames(xys)

        patches_cache, labels_cache = self._create_patch_and_label_dataset(
            total_frames)

        assert 'dis_y' in xkeys
        assert 'dis_u' in xkeys
        assert 'dis_v' in xkeys

        yss = xys['dis_y'] # yss: Y * frames * videos
        uss = xys['dis_u']
        vss = xys['dis_v']
        if mode == 'train':
            assert 'label' in xys
            labels = xys['label']
        elif mode == 'test':
            labels = [None for _ in range(len(yss))]
        else:
            assert False

        assert len(yss) == len(uss) == len(vss) == len(labels)

        patch_idx = 0
        for ys, us, vs, label in zip(yss, uss, vss, labels): # iterate videos
            assert len(ys) == len(us) == len(vs)
            for y, u, v in zip(ys, us, vs): # iterate frames

                yuvimg = dstack_y_u_v(y, u, v)

                img = create_hp_yuv_4channel(yuvimg)

                h, w, c = img.shape

                adj_h = h - self.patch_height
                adj_w = w - self.patch_width

                iv, jv = np.meshgrid(np.arange(adj_h), np.arange(adj_w),
                                     sparse=False, indexing='ij')
                iv = iv.reshape(-1)
                jv = jv.reshape(-1)

                idx = np.random.permutation(adj_h * adj_w)

                iv = iv[idx]
                jv = jv[idx]

                patches_found = 0
                for (y, x) in zip(iv, jv):
                    patches_cache[patch_idx] = img[y: y + self.patch_height,
                                                   x: x + self.patch_width]
                    if mode == 'train':
                        labels_cache[patch_idx] = label

                    patches_found += 1
                    patch_idx += 1
                    if patches_found >= self.patches_per_frame:
                        break

        return patches_cache, labels_cache