计算LPIPS

import lpips
import os
import utils_image as util
loss_fn_alex = lpips.LPIPS(net='vgg')#也可以选择alex
inputpath = r'E:\testresult'#(alex:0.1009) (vgg:0.1879)
gtpath=r'F:\eval_normal'
imgs=os.listdir(path)
losssum=0.0
count=0
for img in imgs:
    ig=util.imread_uint(inputpath +'/'+img,3)
    input=util.uint2tensor3(ig)
    #print(path+'/'+img,pathgt + '/normal' + img[3:])
    gt = util.imread_uint(gtpath+ '/' + img, 3)
    #gt = util.imread_uint(pathgt + '/normal' + img[3:], 3)
    input = util.uint2tensor3(ig)
    gt = util.uint2tensor3(gt)
    loss=loss_fn_alex(input,gt)
    losssum=losssum+loss
    count+=1
    print(img,loss.item())
print(losssum/count)

你可能感兴趣的:(代码问题,python,深度学习)