Despoticc's picture
download
raw
820 Bytes
import torch
import numpy as np
import cv2
def plot_image(save_path, image, convert_RGB2BGR=True):
if isinstance(image, torch.Tensor):
image = image.detach().cpu().numpy()
image = image.astype(float)
if image.max() < 1.1 and image.min() > -0.1: # [0, 1]
image = image * 255
elif image.max() < 1.1 and image.min() > -1.1: # [-1, 1]
image = (image + 1.0) * 0.5 * 255
image = image.clip(0, 255)
image = image.astype(np.uint8)
if len(image.shape) == 4 and image.shape[0] == 1:
image = image[0]
if len(image.shape) == 3 and image.shape[0] <= 4: # C, H, W
image = torch.from_numpy(image).permute(1, 2, 0).numpy()
if len(image.shape) == 3 and convert_RGB2BGR:
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
cv2.imwrite(save_path, image)

Xet Storage Details

Size:
820 Bytes
·
Xet hash:
34cbef012463066f74ff76bea8734b6d0f603954a47c3e42227d77ed8004aec2

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.