示例#1
0
    def to_aggregated_dataset(self, aggregate_scores, **kwargs):

        newone = empty_object()

        # systematically copy fields, e.g. dataset_name, yuv_fmt, width, height, ...
        for key in self.dataset.__dict__.keys():
            if not key.startswith(
                    '__'):  # filter out those e.g. __builtin__ ...
                setattr(newone, key, getattr(self.dataset, key))

        if 'quality_width' in kwargs and kwargs['quality_width'] is not None:
            newone.quality_width = kwargs['quality_width']
        elif hasattr(self.dataset, 'quality_width'):
            newone.quality_width = self.dataset.quality_width

        if 'quality_height' in kwargs and kwargs['quality_height'] is not None:
            newone.quality_height = kwargs['quality_height']
        elif hasattr(self.dataset, 'quality_height'):
            newone.quality_height = self.dataset.quality_height

        if 'resampling_type' in kwargs and kwargs[
                'resampling_type'] is not None:
            newone.resampling_type = kwargs['resampling_type']
        elif hasattr(self.dataset, 'resampling_type'):
            newone.resampling_type = self.dataset.resampling_type

        # ref_videos: deepcopy
        newone.ref_videos = copy.deepcopy(self.dataset.ref_videos)

        # dis_videos: use input aggregate scores
        dis_videos = []
        assert len(self.dataset.dis_videos) == len(aggregate_scores)
        for dis_video, score in zip(self.dataset.dis_videos, aggregate_scores):
            dis_video2 = copy.deepcopy(dis_video)
            if 'os' in dis_video2:  # remove 'os' - opinion score
                del dis_video2['os']
            dis_video2['groundtruth'] = score
            dis_videos.append(dis_video2)

        # add scores std if available
        if 'scores_std' in kwargs and kwargs['scores_std'] is not None:
            assert len(dis_videos) == len(kwargs['scores_std'])
            for dis_video, score_std in zip(dis_videos, kwargs['scores_std']):
                dis_video['groundtruth_std'] = score_std

        if 'aggregate_content_ids' in kwargs and kwargs[
                'aggregate_content_ids'] is not None:
            dis_videos = filter(
                lambda dis_video: dis_video['content_id'] in kwargs[
                    'aggregate_content_ids'], dis_videos)

        if 'aggregate_asset_ids' in kwargs and kwargs[
                'aggregate_asset_ids'] is not None:
            dis_videos = filter(
                lambda dis_video: dis_video['asset_id'] in kwargs[
                    'aggregate_asset_ids'], dis_videos)

        newone.dis_videos = dis_videos

        return newone
示例#2
0
    def to_persubject_dataset(self, quality_scores, **kwargs):

        import math

        newone = empty_object()

        # systematically copy fields, e.g. dataset_name, yuv_fmt, width, height, ...
        for key in self.dataset.__dict__.keys():
            if not key.startswith(
                    '__'):  # filter out those e.g. __builtin__ ...
                setattr(newone, key, getattr(self.dataset, key))

        if 'quality_width' in kwargs and kwargs['quality_width'] is not None:
            newone.quality_width = kwargs['quality_width']
        elif hasattr(self.dataset, 'quality_width'):
            newone.quality_width = self.dataset.quality_width

        if 'quality_height' in kwargs and kwargs['quality_height'] is not None:
            newone.quality_height = kwargs['quality_height']
        elif hasattr(self.dataset, 'quality_height'):
            newone.quality_height = self.dataset.quality_height

        if 'resampling_type' in kwargs and kwargs[
                'resampling_type'] is not None:
            newone.resampling_type = kwargs['resampling_type']
        elif hasattr(self.dataset, 'resampling_type'):
            newone.resampling_type = self.dataset.resampling_type

        # ref_videos: deepcopy
        newone.ref_videos = copy.deepcopy(self.dataset.ref_videos)

        # dis_videos: use input aggregate scores
        dis_videos = []
        for dis_video, quality_score in zip(self.dataset.dis_videos,
                                            quality_scores):
            assert 'os' in dis_video

            # quality_score should be a 1-D array with (processed) per-subject scores
            assert hasattr(quality_score, '__len__')

            # new style: opinion is specified as a dict: user -> score. In this
            # case, quality_score may contain nan. In this case: filter them out
            if isinstance(dis_video['os'], dict):
                quality_score = filter(lambda x: not math.isnan(x),
                                       quality_score)

            assert len(dis_video['os']) == len(quality_score)

            for persubject_score in quality_score:
                dis_video2 = copy.deepcopy(dis_video)
                if 'os' in dis_video2:  # remove 'os' - opinion score
                    del dis_video2['os']
                dis_video2['groundtruth'] = persubject_score
                dis_videos.append(dis_video2)
        newone.dis_videos = dis_videos

        return newone
示例#3
0
 def _prepare_new_dataset(self, kwargs):
     newone = empty_object()
     # systematically copy fields, e.g. dataset_name, yuv_fmt, width, height, ...
     for key in self.dataset.__dict__.keys():
         if not key.startswith('__'):  # filter out those e.g. __builtin__ ...
             setattr(newone, key, getattr(self.dataset, key))
     if 'quality_width' in kwargs and kwargs['quality_width'] is not None:
         newone.quality_width = kwargs['quality_width']
     elif hasattr(self.dataset, 'quality_width'):
         newone.quality_width = self.dataset.quality_width
     if 'quality_height' in kwargs and kwargs['quality_height'] is not None:
         newone.quality_height = kwargs['quality_height']
     elif hasattr(self.dataset, 'quality_height'):
         newone.quality_height = self.dataset.quality_height
     if 'resampling_type' in kwargs and kwargs['resampling_type'] is not None:
         newone.resampling_type = kwargs['resampling_type']
     elif hasattr(self.dataset, 'resampling_type'):
         newone.resampling_type = self.dataset.resampling_type
     return newone
示例#4
0
    def to_dataset(self):
        """
        Override DatasetReader.to_dataset(). Need to overwrite dis_video['os']
        """

        newone = empty_object()
        newone.__dict__.update(self.dataset.__dict__)

        # deep copy ref_videos and dis_videos
        newone.ref_videos = copy.deepcopy(self.dataset.ref_videos)
        newone.dis_videos = copy.deepcopy(self.dataset.dis_videos)

        # overwrite dis_video['os']
        score_mtx = self.opinion_score_2darray
        num_videos, num_subjects = score_mtx.shape
        assert num_videos == len(newone.dis_videos)
        for scores, dis_video in zip(score_mtx, newone.dis_videos):
            dis_video['os'] = list(scores)

        return newone