本文整理匯總了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
示例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
示例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
示例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)
示例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])
示例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