Esempio n. 1
0
    def __call__(self, results):
        """Call function.

        Args:
            results (dict): A dict containing the necessary information and
                data for augmentation.

        Returns:
            dict: A dict containing the processed data and information.
        """
        if self.file_client is None:
            self.file_client = FileClient(self.io_backend, **self.kwargs)
        filepath = str(results[f'{self.key}_path'])
        img_bytes = self.file_client.get(filepath)
        img = imfrombytes(img_bytes,
                          flag=self.flag,
                          channel_order=self.channel_order)  # HWC
        if len(img.shape) == 2:
            img = np.expand_dims(img, axis=2)

        results[self.key] = img
        results[f'{self.key}_path'] = filepath
        results[f'{self.key}_ori_shape'] = img.shape
        if self.save_original_img:
            results[f'ori_{self.key}'] = img.copy()
        return results
Esempio n. 2
0
    def __call__(self, results):
        """Call function.

        Args:
            results (dict): A dict containing the necessary information and
                data for augmentation.

        Returns:
            dict: A dict containing the processed data and information.
        """

        if self.file_client is None:
            self.file_client = FileClient(self.io_backend, **self.kwargs)
        filepaths = results[f'{self.key}_path']
        if not isinstance(filepaths, list):
            raise TypeError(
                f'filepath should be list, but got {type(filepaths)}')

        filepaths = [str(v) for v in filepaths]

        imgs = []
        shapes = []
        if self.save_original_img:
            ori_imgs = []

        def get_cache_key(path):
            l = path.split("/")
            return os.path.join(l[-2], l[-1])

        global cache_dict
        for filepath in filepaths:
            if self.use_mem:
                key = get_cache_key(filepath)
                if cache_dict.__contains__(key):
                    img_bytes = cache_dict.get(key)
                else:
                    img_bytes = self.file_client.get(filepath)
                    cache_dict[key] = img_bytes
            else:
                img_bytes = self.file_client.get(filepath)
            img = imfrombytes(img_bytes, flag=self.flag)  # HWC, BGR
            if img.ndim == 2:
                img = np.expand_dims(img, axis=2)
            imgs.append(img)
            shapes.append(img.shape)
            if self.save_original_img:
                ori_imgs.append(img.copy())

        results[self.key] = imgs
        results[f'{self.key}_path'] = filepaths
        results[f'{self.key}_ori_shape'] = shapes
        if self.save_original_img:
            results[f'ori_{self.key}'] = ori_imgs
        
        return results
Esempio n. 3
0
    def __call__(self, results):
        """Call function.

        Args:
            results (dict): A dict containing the necessary information and
                data for augmentation.

        Returns:
            dict: A dict containing the processed data and information.
        """

        if self.file_client is None:
            self.file_client = FileClient(self.io_backend, **self.kwargs)
        filepaths = results[f'{self.key}_path']
        if not isinstance(filepaths, list):
            raise TypeError(
                f'filepath should be list, but got {type(filepaths)}')

        filepaths = [str(v) for v in filepaths]

        imgs = []
        shapes = []
        if self.save_original_img:
            ori_imgs = []

        for filepath in filepaths:
            if self.make_bin:
                bin_path = get_bin_path(filepath)
                if os.path.isfile(bin_path):
                    img = read_bin(bin_path)
                else:
                    raise NotImplementedError(
                        "please make sure all pkl file exist first")
                    # img_bytes = self.file_client.get(filepath)
                    # img = imfrombytes(img_bytes, flag=self.flag, channel_order=self.channel_order)  # HWC, BGR
                    # make_ndarray_bin(img, bin_path)
            else:
                img_bytes = self.file_client.get(filepath)
                img = imfrombytes(img_bytes,
                                  flag=self.flag,
                                  channel_order=self.channel_order)  # HWC, BGR
            if img.ndim == 2:
                img = np.expand_dims(img, axis=2)
            imgs.append(img)
            shapes.append(img.shape)
            if self.save_original_img:
                ori_imgs.append(img.copy())

        results[self.key] = imgs
        results[f'{self.key}_path'] = filepaths
        results[f'{self.key}_ori_shape'] = shapes
        if self.save_original_img:
            results[f'ori_{self.key}'] = ori_imgs

        return results