cv2.imread()
数值范围:0-255
数据类型:numpy.ndarray dtype('uint8')
数据形状(img.shape):h,w,c
Image.open()
数值范围:0-255
数据类型:numpy.ndarray
数据形状(img.size):w,h
模式:默认RGB
transforms.ToTensor()
数值范围:0-1
数据类型:torch.float32
数据形状(img.shape):c,h,w
数据格式转换:
numpy->PIL
Image.fromarray(img)
tensor->PIL
transforms.ToPILImage()
PIL->tensor
transforms.ToTensor()
numpy->tensor
tensor = torch.tensor(arr2) # 默认深拷贝,新建内存
Tensor = torch.Tensor(arr2) # 默认深拷贝,新建内存
as_tensor = torch.as_tensor(arr2) # 默认浅拷贝,共享内存
from_numpy = torch.from_numpy(arr2) # 默认浅拷贝,共享内存
tensor->numpy
a = torch.ones(5)
b = a.numpy() # 内存共享