将tensor转为图像保存

时间:2025-04-04 18:34:47
from torchvision import utils as vutils
print('begin')
for j in range(t):                               
    print('begin')
    from torchvision import utils as vutils
    residue=residues[:,i,:,:,:]
    pic = ().detach()
    pic = (('cpu'))
    
    dir='/data/dataset1/wj/RealBasicVSR/results/clean/'             
    filename=dir+str(j)+'.png'                    
    vutils.save_image(pic, filename)
print('over')

第二种方法

print('begin')
import cv2  

for j in range(t):                                           
    residue=residues[:,j,:,:,:]
    data = (1,3)
    
    data = ().numpy()
    data = data[0,:,:,:]*255		#没有*255之前是黑色的
    print()
    name = str(j)+".jpg"
    (name,data)