当前位置: 首页>>代码示例>>Python>>正文


Python transforms.resize方法代码示例

本文整理汇总了Python中chainercv.transforms.resize方法的典型用法代码示例。如果您正苦于以下问题:Python transforms.resize方法的具体用法?Python transforms.resize怎么用?Python transforms.resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在chainercv.transforms的用法示例。


在下文中一共展示了transforms.resize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __call__

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import resize [as 别名]
def __call__(self, imgs):
        resized_imgs = []
        for img in imgs:
            _, H, W = img.shape
            scale = self._min_size / min(H, W)
            if scale * max(H, W) > self._max_size:
                scale = self._max_size / max(H, W)
            H, W = int(H * scale), int(W * scale)
            img = transforms.resize(img, (H, W))
            img -= self._mean
            resized_imgs.append(img)

        size = np.array([img.shape[1:] for img in resized_imgs]).max(axis=0)
        size = (np.ceil(size / self._stride) * self._stride).astype(int)
        x = np.zeros((len(imgs), 3, size[0], size[1]), dtype=np.float32)
        for i, img in enumerate(resized_imgs):
            _, H, W = img.shape
            x[i, :, :H, :W] = img

        return x 
开发者ID:chainer,项目名称:models,代码行数:22,代码来源:transform.py

示例2: test

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import resize [as 别名]
def test(self):
        H = 80
        W = 90
        n_inst = 10

        mask = np.zeros((n_inst, H, W), dtype=np.bool)
        bbox = generate_random_bbox(n_inst, (H, W), 10, 30).astype(np.int32)
        for i, bb in enumerate(bbox):
            y_min, x_min, y_max, x_max = bb
            m = np.random.randint(0, 2, size=(y_max - y_min, x_max - x_min))
            m[5, 5] = 1  # At least one element is one
            mask[i, y_min:y_max, x_min:x_max] = m
        bbox = mask_to_bbox(mask)
        size = H * 2
        out_H = size
        out_W = W * 2
        out_mask = scale_mask(mask, bbox, size)

        expected = resize(
            mask.astype(np.float32), (out_H, out_W),
            interpolation=PIL.Image.NEAREST).astype(np.bool)
        np.testing.assert_equal(out_mask, expected) 
开发者ID:chainer,项目名称:chainercv,代码行数:24,代码来源:test_scale_mask.py

示例3: get_example

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import resize [as 别名]
def get_example(self, i):
        with Image.open(str(self.filepaths[i])) as f:
            target = img_to_chw_array(f)

        target = random_crop(target, (self.fine_size, self.fine_size))
        target = random_flip(target, x_random=True)
        if self.random_nn:
            source = resize(
                downscale_random_nearest_neighbor(target.copy()),
                (self.fine_size, self.fine_size), Image.NEAREST,
            )
        else:
            source = resize(
                resize(
                    target,
                    (self.fine_size // 2, self.fine_size // 2), Image.NEAREST,
                ),
                (self.fine_size, self.fine_size), Image.NEAREST,
            )
        return source, target 
开发者ID:mitaki28,项目名称:pixcaler,代码行数:22,代码来源:dataset.py

示例4: __call__

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import resize [as 别名]
def __call__(self, in_data):
        img, label = in_data
        img = random_sized_crop(img)
        img = resize(img, (224, 224))
        img = random_flip(img, x_random=True)
        img -= self.mean
        return img, label 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:9,代码来源:train_imagenet_multi.py

示例5: __call__

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import resize [as 别名]
def __call__(self, in_data):
        img, mask, label = in_data
        bbox = mask_to_bbox(mask)
        _, orig_H, orig_W = img.shape
        img = self.fcis.prepare(img)
        _, H, W = img.shape
        scale = H / orig_H
        mask = transforms.resize(mask.astype(np.float32), (H, W))
        bbox = transforms.resize_bbox(bbox, (orig_H, orig_W), (H, W))

        img, params = transforms.random_flip(
            img, x_random=True, return_param=True)
        mask = transforms.flip(mask, x_flip=params['x_flip'])
        bbox = transforms.flip_bbox(bbox, (H, W), x_flip=params['x_flip'])
        return img, mask, label, bbox, scale 
开发者ID:chainer,项目名称:chainercv,代码行数:17,代码来源:train_sbd.py

示例6: __call__

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import resize [as 别名]
def __call__(self, in_data):
        if len(in_data) == 4:
            img, mask, label, bbox = in_data
        else:
            img, bbox, label = in_data
        # Flipping
        img, params = transforms.random_flip(
            img, x_random=True, return_param=True)
        x_flip = params['x_flip']
        bbox = transforms.flip_bbox(
            bbox, img.shape[1:], x_flip=x_flip)

        # Scaling and mean subtraction
        img, scale = scale_img(
            img, self.min_size, self.max_size)
        img -= self.mean
        bbox = bbox * scale

        if len(in_data) == 4:
            mask = transforms.flip(mask, x_flip=x_flip)
            mask = transforms.resize(
                mask.astype(np.float32),
                img.shape[1:],
                interpolation=PIL.Image.NEAREST).astype(np.bool)
            return img, bbox, label, mask
        else:
            return img, bbox, label 
开发者ID:chainer,项目名称:chainercv,代码行数:29,代码来源:train_multi.py

示例7: _prepare

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import resize [as 别名]
def _prepare(self, img):
        img = img.astype(np.float32)
        img = transforms.resize(img, (self.insize, self.insize))
        img -= self.mean
        return img 
开发者ID:chainer,项目名称:chainercv,代码行数:7,代码来源:ssd.py

示例8: predict

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import resize [as 别名]
def predict(self, imgs):
        """Conduct semantic segmentations from images.

        Args:
            imgs (iterable of numpy.ndarray): Arrays holding images.
                All images are in CHW and RGB format
                and the range of their values are :math:`[0, 255]`.

        Returns:
            list of numpy.ndarray:

            List of integer labels predicted from each image in the input \
            list.

        """
        labels = []
        for img in imgs:
            C, H, W = img.shape
            with chainer.using_config('train', False), \
                    chainer.function.no_backprop_mode():
                x = chainer.Variable(self.xp.asarray(img[np.newaxis]))
                score = self.forward(x)[0].array
            score = chainer.backends.cuda.to_cpu(score)
            if score.shape != (C, H, W):
                dtype = score.dtype
                score = resize(score, (H, W)).astype(dtype)

            label = np.argmax(score, axis=0).astype(np.int32)
            labels.append(label)
        return labels 
开发者ID:chainer,项目名称:chainercv,代码行数:32,代码来源:segnet_basic.py

示例9: _get_proba

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import resize [as 别名]
def _get_proba(self, img, scale, flip):
        if flip:
            img = img[:, :, ::-1]

        _, H, W = img.shape
        if scale == 1.0:
            h, w = H, W
        else:
            h, w = int(H * scale), int(W * scale)
            img = resize(img, (h, w))

        img = self.prepare(img)

        x = chainer.Variable(self.xp.asarray(img[np.newaxis]))
        x = self.forward(x)
        x = F.softmax(x, axis=1)
        score = F.resize_images(x, img.shape[1:])[0, :, :h, :w].array
        score = chainer.backends.cuda.to_cpu(score)

        if scale != 1.0:
            score = resize(score, (H, W))

        if flip:
            score = score[:, :, ::-1]

        return score 
开发者ID:chainer,项目名称:chainercv,代码行数:28,代码来源:deeplab_v3_plus.py

示例10: _prepare

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import resize [as 别名]
def _prepare(self, img):
        """Prepare an image for feeding it to a model.

        This is a standard preprocessing scheme used by feature extraction
        models.
        First, the image is scaled or resized according to :math:`scale_size`.
        Note that this step is optional.
        Next, the image is cropped to :math:`crop_size`.
        Last, the image is mean subtracted by an array :obj:`mean`.

        Args:
            img (~numpy.ndarray): An image. This is in CHW format.
                The range of its value is :math:`[0, 255]`.

        Returns:
            ~numpy.ndarray:
            A preprocessed image. This is 4D array whose batch size is
            the number of crops.

        """
        if self.scale_size is not None:
            if isinstance(self.scale_size, int):
                img = scale(img, size=self.scale_size)
            else:
                img = resize(img, size=self.scale_size)
        else:
            img = img.copy()

        if self.crop == '10':
            imgs = ten_crop(img, self.crop_size)
        elif self.crop == 'center':
            imgs = center_crop(img, self.crop_size)[np.newaxis]

        imgs -= self.mean[np.newaxis]

        return imgs 
开发者ID:chainer,项目名称:chainercv,代码行数:38,代码来源:feature_predictor.py

示例11: scale_img

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import resize [as 别名]
def scale_img(img, min_size, max_size):
    """Process image."""
    _, H, W = img.shape
    scale = min_size / min(H, W)
    if scale * max(H, W) > max_size:
        scale = max_size / max(H, W)
    H, W = int(H * scale), int(W * scale)
    img = transforms.resize(img, (H, W))
    return img, scale 
开发者ID:chainer,项目名称:chainercv,代码行数:11,代码来源:misc.py

示例12: test_resize_color

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import resize [as 别名]
def test_resize_color(self):
        if self.backend == 'cv2' and not _cv2_available:
            return
        img = np.random.uniform(size=(3, 24, 32))
        with chainer.using_config('cv_resize_backend', self.backend):
            out = resize(img, size=(32, 64), interpolation=self.interpolation)
        self.assertEqual(out.shape, (3, 32, 64)) 
开发者ID:chainer,项目名称:chainercv,代码行数:9,代码来源:test_resize.py

示例13: test_resize_grayscale

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import resize [as 别名]
def test_resize_grayscale(self):
        if self.backend == 'cv2' and not _cv2_available:
            return
        img = np.random.uniform(size=(1, 24, 32))
        with chainer.using_config('cv_resize_backend', self.backend):
            out = resize(img, size=(32, 64), interpolation=self.interpolation)
        self.assertEqual(out.shape, (1, 32, 64)) 
开发者ID:chainer,项目名称:chainercv,代码行数:9,代码来源:test_resize.py

示例14: test_zero_length_img

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import resize [as 别名]
def test_zero_length_img(self):
        if self.backend == 'cv2' and not _cv2_available:
            return
        img = np.random.uniform(size=(0, 24, 32))
        with chainer.using_config('cv_resize_backend', self.backend):
            out = resize(img, size=(32, 64), interpolation=self.interpolation)
        self.assertEqual(out.shape, (0, 32, 64)) 
开发者ID:chainer,项目名称:chainercv,代码行数:9,代码来源:test_resize.py

示例15: test_invalid_backend

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import resize [as 别名]
def test_invalid_backend(self):
        img = np.random.uniform(size=(3, 24, 32))
        with chainer.using_config('cv_resize_backend', 'PII'):
            with self.assertRaises(ValueError):
                resize(img, size=(32, 64)) 
开发者ID:chainer,项目名称:chainercv,代码行数:7,代码来源:test_resize.py


注:本文中的chainercv.transforms.resize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。