[Pytorch] tensor to PIL Image
·
언어 | Framework/Pytorch
tensor to numpy output_tensor = model(data) output_tensor = output_tensor.cpu() # tensor to numpy output_tensor = torch.squeeze(output_tensor[0]) output_numpy = output_tensor.numpy() ## if output_tensor.requires_grad==True # output_numpy = output_tensor.detach().numpy() numpy to PIL Image from torchvision import transforms # numpy to PIL Image output_image = transforms.ToPILImage()(output_numpy)
[Pytorch] numpy, tensor, list 변환
·
언어 | Framework/Pytorch
pytorch에서 자주 쓰이는 형태인 numpy, tensor, list 간에 변환. import torch import numpy as np # numpy to tensor np_arr = np.zeros((3, 3), dtype=np.float32) tensor_arr = torch.from_numpy(np_arr) # tensor to numpy np_arr = tensor_arr.numpy() # tensor to list list = tensor_arr.tolist() # list to tensor tensor_arr = torch.tensor(list) 간단하다.
woongs_93
'tensor' 태그의 글 목록