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


Python mmcv.imdenormalize方法代码示例

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


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

示例1: tensor2imgs

# 需要导入模块: import mmcv [as 别名]
# 或者: from mmcv import imdenormalize [as 别名]
def tensor2imgs(tensor, mean=(0, 0, 0), std=(1, 1, 1), to_rgb=True):
    """Convert tensor to images.

    Args:
        tensor (torch.Tensor): Tensor that contains multiple images
        mean (tuple[float], optional): Mean of images. Defaults to (0, 0, 0).
        std (tuple[float], optional): Standard deviation of images.
            Defaults to (1, 1, 1).
        to_rgb (bool, optional): Whether convert the images to RGB format.
            Defaults to True.

    Returns:
        list[np.ndarray]: A list that contains multiple images.
    """
    num_imgs = tensor.size(0)
    mean = np.array(mean, dtype=np.float32)
    std = np.array(std, dtype=np.float32)
    imgs = []
    for img_id in range(num_imgs):
        img = tensor[img_id, ...].cpu().numpy().transpose(1, 2, 0)
        img = mmcv.imdenormalize(
            img, mean, std, to_bgr=to_rgb).astype(np.uint8)
        imgs.append(np.ascontiguousarray(img))
    return imgs 
开发者ID:open-mmlab,项目名称:mmdetection,代码行数:26,代码来源:misc.py

示例2: tensor2imgs

# 需要导入模块: import mmcv [as 别名]
# 或者: from mmcv import imdenormalize [as 别名]
def tensor2imgs(tensor, mean=(0, 0, 0), std=(1, 1, 1), to_rgb=True):
    num_imgs = tensor.size(0)
    mean = np.array(mean, dtype=np.float32)
    std = np.array(std, dtype=np.float32)
    imgs = []
    for img_id in range(num_imgs):
        img = tensor[img_id, ...].cpu().numpy().transpose(1, 2, 0)
        img = mmcv.imdenormalize(
            img, mean, std, to_bgr=to_rgb).astype(np.uint8)
        imgs.append(np.ascontiguousarray(img))
    return imgs 
开发者ID:dingjiansw101,项目名称:AerialDetection,代码行数:13,代码来源:misc.py

示例3: tensor2imgs

# 需要导入模块: import mmcv [as 别名]
# 或者: from mmcv import imdenormalize [as 别名]
def tensor2imgs(tensor, mean=(0, 0, 0), std=(1, 1, 1), to_rgb=True):
    """Convert tensor to 3-channel images.

    Args:
        tensor (torch.Tensor): Tensor that contains multiple images, shape (
            N, C, H, W).
        mean (tuple[float], optional): Mean of images. Defaults to (0, 0, 0).
        std (tuple[float], optional): Standard deviation of images.
            Defaults to (1, 1, 1).
        to_rgb (bool, optional): Whether the tensor was converted to RGB
            format in the first place. If so, convert it back to BGR.
            Defaults to True.

    Returns:
        list[np.ndarray]: A list that contains multiple images.
    """

    if torch is None:
        raise RuntimeError('pytorch is not installed')
    assert torch.is_tensor(tensor) and tensor.ndim == 4
    assert len(mean) == 3
    assert len(std) == 3

    num_imgs = tensor.size(0)
    mean = np.array(mean, dtype=np.float32)
    std = np.array(std, dtype=np.float32)
    imgs = []
    for img_id in range(num_imgs):
        img = tensor[img_id, ...].cpu().numpy().transpose(1, 2, 0)
        img = mmcv.imdenormalize(
            img, mean, std, to_bgr=to_rgb).astype(np.uint8)
        imgs.append(np.ascontiguousarray(img))
    return imgs 
开发者ID:open-mmlab,项目名称:mmcv,代码行数:35,代码来源:misc.py

示例4: test_imdenormalize

# 需要导入模块: import mmcv [as 别名]
# 或者: from mmcv import imdenormalize [as 别名]
def test_imdenormalize(self):
        norm_img = (self.img[:, :, ::-1] - self.mean) / self.std
        rgb_baseline = (norm_img * self.std + self.mean)
        bgr_baseline = rgb_baseline[:, :, ::-1]
        img = mmcv.imdenormalize(norm_img, self.mean, self.std)
        assert np.allclose(img, bgr_baseline)
        img = mmcv.imdenormalize(norm_img, self.mean, self.std, to_bgr=False)
        assert np.allclose(img, rgb_baseline) 
开发者ID:open-mmlab,项目名称:mmcv,代码行数:10,代码来源:test_photometric.py

示例5: main

# 需要导入模块: import mmcv [as 别名]
# 或者: from mmcv import imdenormalize [as 别名]
def main():
    args = parse_args()
    os.makedirs(args.output, exist_ok=True)
    cfg = Config.fromfile(args.config)
    dataset = get_dataset(cfg.data.train)
    for i in tqdm(np.random.randint(0, len(dataset), 500)):
        data = dataset[i]
        img = data['img'].data.numpy().transpose(1, 2, 0)
        masks = data['gt_masks'].data.transpose(1, 2, 0).astype(bool)
        bboxes = data['gt_bboxes'].data.numpy()
        img = mmcv.imdenormalize(img, mean=cfg.img_norm_cfg.mean, std=cfg.img_norm_cfg.std, to_bgr=False)
        img = draw_masks(img, masks).astype(np.uint8)
        draw_bounding_boxes_on_image_array(img, bboxes, use_normalized_coordinates=False, thickness=5)
        cv2.imwrite(osp.join(args.output, f'{i}_{np.random.randint(0, 10000)}.jpg'), img[..., ::-1]) 
开发者ID:amirassov,项目名称:kaggle-imaterialist,代码行数:16,代码来源:eda.py

示例6: tensor2video_snaps

# 需要导入模块: import mmcv [as 别名]
# 或者: from mmcv import imdenormalize [as 别名]
def tensor2video_snaps(tensor, mean=(0, 0, 0), std=(1, 1, 1), to_rgb=True):
    num_videos = tensor.size(0)
    num_frames = tensor.size(2)
    mean = np.array(mean, dtype=np.float32)
    std = np.array(std, dtype=np.float32)
    video_snaps = []
    for vid_id in range(num_videos):
        img = tensor[vid_id, :, num_frames //
                     2, ...].cpu().numpy().transpose(1, 2, 0)
        img = mmcv.imdenormalize(
            img, mean, std, to_bgr=to_rgb).astype(np.uint8)
        video_snaps.append(np.ascontiguousarray(img))
    return video_snaps 
开发者ID:open-mmlab,项目名称:mmaction,代码行数:15,代码来源:misc.py


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