传统使用opencv自带的swapaxes进行转换,然后使用pytorch的from_numpy转为tensor
例如:
img = img.swapaxes(1,2).swapaxes(0,1)
但是有一个常用的图像增广模块albumentations模块中的img_to_tensor进行直接转换
注意:我这里使用unsqueeze是为了验证模型的输出,如果使用pytorch的dataset则不需要使用这个操作
传统使用opencv自带的swapaxes进行转换,然后使用pytorch的from_numpy转为tensor
例如:
img = img.swapaxes(1,2).swapaxes(0,1)
但是有一个常用的图像增广模块albumentations模块中的img_to_tensor进行直接转换
注意:我这里使用unsqueeze是为了验证模型的输出,如果使用pytorch的dataset则不需要使用这个操作