반응형
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)
반응형
'언어 | Framework > Pytorch' 카테고리의 다른 글
Multi GPU 학습 모델 불러오기 (0) | 2024.07.09 |
---|---|
[Pytorch] model.eval() (0) | 2021.07.14 |
[Pytorch] numpy, tensor, list 변환 (0) | 2021.03.24 |
[Pytorch] Multi GPU (0) | 2021.03.24 |